Skip to content

Commit

Permalink
PrimitivesV2 schemas (#14)
Browse files Browse the repository at this point in the history
* Partial version of EstimatorV2 input schema

* Full EstimatorV2 schema

* Added SamplerV2 schema and added `seed_estimator` to estimator schema

* Updating the estimator schema after options changes in qiskit runtime

* Updated SamplerV2 schema

* Update schemas/estimator_v2_schema.json

Co-authored-by: Jessie Yu <[email protected]>

* Update schemas/estimator_v2_schema.json

Co-authored-by: Jessie Yu <[email protected]>

* Update schemas/estimator_v2_schema.json

Co-authored-by: Jessie Yu <[email protected]>

* Fixes according to PR review

* Update schemas/estimator_v2_schema.json

Co-authored-by: Jessie Yu <[email protected]>

* Update schemas/estimator_v2_schema.json

Co-authored-by: Jessie Yu <[email protected]>

* Update schemas/estimator_v2_schema.json

Co-authored-by: Jessie Yu <[email protected]>

* Update schemas/estimator_v2_schema.json

Co-authored-by: Jessie Yu <[email protected]>

* Update schemas/sampler_v2_schema.json

Co-authored-by: Jessie Yu <[email protected]>

* Update schemas/sampler_v2_schema.json

Co-authored-by: Jessie Yu <[email protected]>

* Update schemas/estimator_v2_schema.json

Co-authored-by: Jessie Yu <[email protected]>

* Update schemas/estimator_v2_schema.json

Co-authored-by: Jessie Yu <[email protected]>

* Update schemas/estimator_v2_schema.json

Co-authored-by: Jessie Yu <[email protected]>

* Update schemas/estimator_v2_schema.json

Co-authored-by: Jessie Yu <[email protected]>

* Update schemas/estimator_v2_schema.json

Co-authored-by: Jessie Yu <[email protected]>

* Update schemas/estimator_v2_schema.json

Co-authored-by: Jessie Yu <[email protected]>

* Update schemas/estimator_v2_schema.json

Co-authored-by: Jessie Yu <[email protected]>

* Update schemas/estimator_v2_schema.json

Co-authored-by: Jessie Yu <[email protected]>

* Update schemas/estimator_v2_schema.json

Co-authored-by: Jessie Yu <[email protected]>

* Update schemas/estimator_v2_schema.json

Co-authored-by: Jessie Yu <[email protected]>

* Starting to add tests

* Added a framework to test schema vs runtime validator

* Added dynamical decoupling tests and fixed some bugs in the framework

* Test for resilience boolean values and schema fix based on the test

* Tests for zne options; extended the schema to validate correct number of noise factors (currently disagrees with `EstimatorOptions` on behaviour in case of empty noise factor list)

* Improving the test framework

* Updated the schema to verify zne implies zne_mitigation=True, and measure_noise_mitigation implies measure_noise_mitigation=True

* Added pec options tests and updated the schema to require `pec_mitigation=True` if `pec` options are used

* Added noise learning tests

* Added execution and twirling tests

* Added Sampler tests

* linting

* Schema fix: `noise_gain` is inclusive minimum

* Added default shots/precision

* Added `support_qiskit`

* Additional data on PUBS

* Allow longer line length with flake8

* linting

* Switching to test against the `main` branch of `qiskit-ibm-runtime`

* use https instead of ssh

* Fixes

* Fixes

* Fix shots

* Added `meas_type` to Sampler schema

* QuantumCircuit can be either object or string

* Change back to shots

---------

Co-authored-by: Jessie Yu <[email protected]>
  • Loading branch information
gadial and jyu00 authored May 21, 2024
1 parent 0231221 commit db62121
Show file tree
Hide file tree
Showing 6 changed files with 1,116 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
max-line-length = 120
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ fastjsonschema
jsonschema
jsonschema-rs
ddt
qiskit-ibm-runtime@git+https://[email protected]/Qiskit/qiskit-ibm-runtime.git
606 changes: 606 additions & 0 deletions schemas/estimator_v2_schema.json

Large diffs are not rendered by default.

89 changes: 89 additions & 0 deletions schemas/sampler_v2_schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "http://www.qiskit.org/schemas/sampler_v2_schema.json",
"title": "SamplerV2 input",
"description": "The input for an SamplerV2 API call",
"version": "1.0.0",
"type": "object",
"required": ["pubs"],
"properties": {
"pubs": {
"type": "array",
"description": "Primitive Unit Blocs of data. Each PUB is of the form (Circuit, Parameters, Shots) where the circuit is required, parameters should be passed only for parametrized circuits, and shots is optional",
"items": {
"type": "array",
"minItems": 1,
"prefixItems": [
{"description": "The quantum circuit in QASM string or base64-encoded QPY format. See https://docs.quantum.ibm.com/api/qiskit/qpy for more details on QPY.", "type": ["object", "string"]},
{"description": "A dictionary of the parameter values. The keys are the names of the parameters, and the values are the actual parameter values.", "type": "object"},
{"description": "The number of shots to use in this pub", "type": "integer"}
]
}
},
"options": {
"type": "object",
"description": "Options for V2 Sampler",
"properties": {
"default_shots": {
"description": "The default number of shots to use if none are specified in the PUBs",
"type": "integer"
},
"dynamical_decoupling": {
"description": "Suboptions for dynamical decoupling",
"type": "object",
"properties": {
"enable": {
"description": "Whether to enable DD as specified by the other options in this class",
"type": "boolean"
},
"sequence_type": {
"description": "Which dynamical decoupling sequence to use",
"type": "string",
"enum": ["XX", "XpXm", "XY4"]
},
"extra_slack_distribution": {
"description": "Where to put extra timing delays due to rounding issues",
"type": "string",
"enum": ["middle", "edges"]
},
"scheduling_method": {
"description": "Whether to schedule gates as soon as ('asap') or as late as ('alap') possible",
"type": "string",
"enum": ["alap", "asap"]
}
}
},
"execution": {
"description": "Execution options",
"type": "object",
"properties": {
"init_qubits": {
"description": "Whether to reset the qubits to the ground state for each shot",
"type": "boolean"
},
"rep_delay": {
"description": "The delay between a measurement and the subsequent quantum circuit",
"type": "number"
},
"meas_type": {
"description": "How to process and return measurement results",
"enum": ["classified", "kerneled", "avg_kerneled"]
}
}
}
}
},
"shots": {
"description": "Default number of shots which applies to all pubs without shots",
"type": "integer"
},
"support_qiskit": {
"description": "If True, returns a qiskit-style output, meant to be parsed using the runtime result decoder, or resort to returning pure JSON results (resulting in larger objects)",
"type": "boolean"
},
"version": {
"description": "For SamplerV2, version should always be 2",
"enum": [2]
}
}
}
51 changes: 51 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2017.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""With some utils"""

import itertools
from ddt import data, unpack


class Case(dict):
"""<no description>"""


def generate_cases(docstring, dsc=None, name=None, **kwargs):
"""Combines kwargs in Cartesian product and creates Case with them"""
ret = []
keys = kwargs.keys()
vals = kwargs.values()
for values in itertools.product(*vals):
case = Case(zip(keys, values))
if docstring is not None:
setattr(case, "__doc__", docstring.format(**case))
if dsc is not None:
setattr(case, "__doc__", dsc.format(**case))
if name is not None:
setattr(case, "__name__", name.format(**case))
ret.append(case)
return ret


def combine(**kwargs):
"""Decorator to create combinations and tests
@combine(level=[0, 1, 2, 3],
circuit=[a, b, c, d],
dsc='Test circuit {circuit.__name__} with level {level}',
name='{circuit.__name__}_level{level}')
"""

def deco(func):
return data(*generate_cases(docstring=func.__doc__, **kwargs))(unpack(func))

return deco
Loading

0 comments on commit db62121

Please sign in to comment.