diff --git a/mitiq/schema/technique_schema/ddd_schema.json b/mitiq/schema/technique_schema/ddd_schema.json new file mode 100644 index 000000000..947e8edd2 --- /dev/null +++ b/mitiq/schema/technique_schema/ddd_schema.json @@ -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 +} diff --git a/mitiq/schema/technique_schema/pec_schema.json b/mitiq/schema/technique_schema/pec_schema.json new file mode 100644 index 000000000..3de23a7b0 --- /dev/null +++ b/mitiq/schema/technique_schema/pec_schema.json @@ -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 +} diff --git a/mitiq/schema/technique_schema/rem_schema.json b/mitiq/schema/technique_schema/rem_schema.json new file mode 100644 index 000000000..0754ae5ca --- /dev/null +++ b/mitiq/schema/technique_schema/rem_schema.json @@ -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 + } +} diff --git a/mitiq/schema/technique_schema/zne_schema.json b/mitiq/schema/technique_schema/zne_schema.json new file mode 100644 index 000000000..0e30e2dc8 --- /dev/null +++ b/mitiq/schema/technique_schema/zne_schema.json @@ -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 +} diff --git a/mitiq/schema/validation_utils.py b/mitiq/schema/validation_utils.py new file mode 100644 index 000000000..b151d9948 --- /dev/null +++ b/mitiq/schema/validation_utils.py @@ -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 +