-
Notifications
You must be signed in to change notification settings - Fork 28
Primitives output schema #15
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e0db89a
Test file with basic actual outputs but still no tests
gadial 557e85f
Change "output" to "result"
gadial 81637d6
Basic estimator result schema + test
gadial 59c33f9
Added the basic sampler result schema
gadial 7598650
Merge branch 'main' into primitive_output_schema
gadial 5e8205a
linting
gadial d883392
small fix
gadial File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"id": "http://www.qiskit.org/schemas/estimator_result_v2_schema.json", | ||
"title": "EstimatorV2 result", | ||
"description": "The result for an EstimatorV2 API call", | ||
"version": "1.0.0", | ||
"type": "object", | ||
"required": ["results", "metadata"], | ||
"properties": { | ||
"results": { | ||
"type": "array", | ||
"description": "Array of results, one for each PUB in the original job", | ||
"items": { | ||
"type": "object", | ||
"description": "A single PUB result, containing result data and metadata", | ||
"required": ["data", "metadata"], | ||
"properties": { | ||
"data": { | ||
"type": "object", | ||
"description": "PUB results for estimator include expectation values and standard errors, which can be either numbers or multidimensional arrays of numbers, depending on the shape of the observables and parameters in the original PUB", | ||
"required": ["evs", "stds"], | ||
"properties": { | ||
"evs": { | ||
"anyOf": [{"type": "number"},{"type": "array"}] | ||
}, | ||
"stds": { | ||
"anyOf": [{"type": "number"},{"type": "array"}] | ||
}, | ||
"ensamble_standard_error": { | ||
"anyOf": [{"type": "number"},{"type": "array"}] | ||
} | ||
} | ||
}, | ||
"metadata": { | ||
"type": "object", | ||
"description": "PUB-specific metadata" | ||
} | ||
} | ||
} | ||
}, | ||
"metadata": { | ||
"type": "object", | ||
"description": "Metadata for the job" | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"id": "http://www.qiskit.org/schemas/sampler_result_v2_schema.json", | ||
"title": "EstimatorV2 result", | ||
"description": "The result for an SamplerV2 API call", | ||
"version": "1.0.0", | ||
"type": "object", | ||
"required": ["results", "metadata"], | ||
"properties": { | ||
"results": { | ||
"type": "array", | ||
"description": "Array of results, one for each PUB in the original job", | ||
"items": { | ||
"type": "object", | ||
"description": "A single PUB result, containing result data and metadata", | ||
"required": ["data", "metadata"], | ||
"properties": { | ||
"data": { | ||
"type": "object", | ||
"description": "PUB results for sampler are split according to the classical bits register names. For each register, an array of samples (in hexadecimal string format) is returned", | ||
"additionalProperties": { | ||
"type": "object", | ||
"description": "The data corresponding to a specific measurement", | ||
"properties": { | ||
"samples": { | ||
"type": "array", | ||
"description": "An array of samples (given as hexadecimal strings)", | ||
"items": {"type": "string"} | ||
}, | ||
"num_bits": { | ||
"type": "integer", | ||
"description": "The number of measured bits" | ||
} | ||
} | ||
} | ||
}, | ||
"metadata": { | ||
"type": "object", | ||
"description": "PUB-specific metadata" | ||
} | ||
} | ||
} | ||
}, | ||
"metadata": { | ||
"type": "object", | ||
"description": "Metadata for the job" | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# This code is part of Qiskit. | ||
# | ||
# (C) Copyright IBM 2024 | ||
# | ||
# 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. | ||
|
||
import json | ||
import os | ||
import unittest | ||
import ddt | ||
import jsonschema | ||
|
||
SCHEMAS_PATH = os.path.join( | ||
os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "schemas" | ||
) | ||
|
||
|
||
@ddt.ddt | ||
class TestEstimatorV2ResultSchema(unittest.TestCase): | ||
"""Tests the estimator result schema""" | ||
|
||
def setUp(self) -> None: | ||
with open( | ||
os.path.join(SCHEMAS_PATH, "estimator_result_v2_schema.json"), "r" | ||
) as fd: | ||
self.estimator_schema = json.load(fd) | ||
self.validator = jsonschema.Draft202012Validator(schema=self.estimator_schema) | ||
|
||
def test_basic_result(self): | ||
result_str = '{"results": [{"data": {"evs": 1.1142546245919478, "stds": 0.012101383035893986, ' \ | ||
'"ensemble_standard_error": 0.012101383035893986}, "metadata": ' \ | ||
'{"shots": 4096, "target_precision": 0.015625, "circuit_metadata": {}, "resilience": {}, ' \ | ||
'"num_randomizations": 32}}], "metadata": {"dynamical_decoupling": ' \ | ||
'{"enable": false, "sequence_type": "XX", "extra_slack_distribution": "middle", ' \ | ||
'"scheduling_method": "alap"}, "twirling": {"enable_gates": false, "enable_measure": true, ' \ | ||
'"num_randomizations": "auto", "shots_per_randomization": "auto", "interleave_randomizations": ' \ | ||
'true, "strategy": "active-accum"}, "resilience": {"measure_mitigation": true, ' \ | ||
'"zne_mitigation": false, "pec_mitigation": false}, "version": 2}}' | ||
result = json.loads(result_str) | ||
self.validator.validate(result) | ||
|
||
|
||
class TestSamplerV2ResultSchema(unittest.TestCase): | ||
"""Tests the sampler result schema""" | ||
|
||
def setUp(self) -> None: | ||
with open( | ||
os.path.join(SCHEMAS_PATH, "sampler_result_v2_schema.json"), "r" | ||
) as fd: | ||
self.sampler_schema = json.load(fd) | ||
self.validator = jsonschema.Draft202012Validator(schema=self.sampler_schema) | ||
|
||
def test_basic_result(self): | ||
result_str = '{"results": [{"data": {"meas": {"samples": ["0x3", "0x3", "0x3", "0x3", "0x3"],' \ | ||
' "num_bits": 2}}, "metadata": {"circuit_metadata": {}}}], "metadata": {"version": 2}}' | ||
result = json.loads(result_str) | ||
self.validator.validate(result) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.