Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding QEM schema directory #2597

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions mitiq/schema/technique_schema/ddd_schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "DDD Schema",
"description": "Schema for defining a DDD implementation, to potentially be used as a sub-schema in larger QEM-schema",
"type": "object",
"required": ["rule"],
"properties": {
"technique": {
"description": "Technique name, this is reuqired when composing techniques",
"type": "string",
"enum": ["ddd"]
},

"observable": {
"description": "Observable to compute the expectation value of. If None, the executor must return an expectation value",
"type": "object"
},


"rule": {
"description": "Method used to make the cirucit more sensitive to noise, takes circuit and scale factors as inputm, returns new circuit that is theoretically equivalent but practically noisier",
"type": "string",
"enum": ["xx", "yy", "xyxy", "general", "repeated", "custom"]
},

"rule_args": {
"description": " An optional dictionary of keyword arguments for rule (if using rule not in ['xx', 'yy', 'xyxy'])",
"type": "object"
},

"num_trials": {
"description": "Number of independent experiments to average over. A number larger than 1 can be useful to average over multiple applications of a rule returning non-deterministic DDD sequences",
"type": "integer"

},

"full_output":{
"description": "Whether to return the full output of the DDD rule, or just the mitigated expectation value",
"type": "boolean"
}
},
"additionalProperties": false
}
52 changes: 52 additions & 0 deletions mitiq/schema/technique_schema/pec_schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "PEC Schema",
"description": "Schema for defining a PEC implementation, to potentially be used as a sub-schema in larger QEM-schema",
"type": "object",
"properties": {
"technique": {
"description": "Technique name, this is reuqired when composing techniques",
"type": "string",
"enum": ["pec"]
},

"operation_representations": {
"description": "Representations of the ideal gates in the circuit, expressed as a linear combination of noisy gates",
"type": "array",
"items": {}
},

"observable": {
"description": "Observable to compute the expectation value of. If None, the executor must return an expectation value"
},

"precision": {
"description": "The desired estimation precision (assuming the observable is bounded by 1), ignored if num_samples is given",
"type": "number",
"minimum": 0
},

"num_samples": {
"description": "The number of noisy circuits to be sampled for PEC. If not given, deduced from the precision",
"type": "integer",
"minimum": 1
},

"force_run_all": {
"description": "If True, all sampled circuits are executed regardless of uniqueness, else a minimal unique set is executed",
"type": "boolean"
},

"random_state": {
"description": "Seed for sampling circuits",
"type": "integer"
},

"full_output": {
"description": "If False only the average PEC value is returned. If True a dictionary containing all PEC data is returned too",
"type": "boolean"
}

},
"additionalProperties": false
}
27 changes: 27 additions & 0 deletions mitiq/schema/technique_schema/rem_schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "REM Schema",
"description": "Schema for defining an REM implementation",
"type": "object",
"properties": {
"technique": {
"description": "Technique name, this is reuqired when composing techniques",
"type": "string",
"enum": ["rem"]
},

"observable": {
"description": "Observable to compute the expectation value of",
"type": "object"
},

"inverse_confusion_matrix": {
"description": "The inverse confusion matrix to apply to the probability vector estimated with noisy measurement results.",
"type": "array",
"items": {
"type": "number"
}
},
"additionalProperties": false
}
}
39 changes: 39 additions & 0 deletions mitiq/schema/technique_schema/zne_schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "ZNE Schema",
"description": "Schema for defining a ZNE implementation, to potentially be used as a sub-schema in larger QEM-schema",
"type": "object",
"properties": {
"technique": {
"description": "Technique name, this is reuqired when composing techniques",
"type": "string",
"enum": ["zne"]
},

"noise_scaling_factors": {
"description": "Real scale factors used in the Factory for extrapolating to zero noise case, one for each point that is to be extrapolated",
"type": "array",
"items": {
"type": "number"
}
},

"noise_scaling_method": {
"description": "Method used to make the cirucit more sensitive to noise, takes circuit and scale factors as inputm, returns new circuit that is theoretically equivalent but practically noisier",
"type": "string",
"enum": ["global", "local_random", "local_all", "layer", "identity_scaling"]
},

"scale_factor": {
"description": "Indicates how many times to fold the input circuit according to the noise_scaling_method, folded circuit will have number of gates approximately equal to scale_factor * len(circuit)",
"type": "number"
},

"extrapolation": {
"description": "Method used to extrapolate the noise scaling factors to points not in the original set",
"type": "string",
"enum": ["linear", "richardson", "polynomial", "exponential", "poly-exp", "adaptive-exp"]
}
},
"additionalProperties": false
}
18 changes: 18 additions & 0 deletions mitiq/schema/validation_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import json
import jsonschema
from jsonschema import validate


def load(schema_path):
with open(schema_path, 'r') as file:
return json.load(file)


def validate_experiment(experiment, schema):
try:
validate(instance=experiment, schema=schema)
print("expertiment validation passed")
except jsonschema.exceptions.ValidationError as e:
print("experiment validation failed")
return None

Loading