-
Notifications
You must be signed in to change notification settings - Fork 198
[executor-preview] Testing and fixing the NLV3 decoder #2505
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
17 commits
Select commit
Hold shift + click to select a range
94fc4d1
nlv3 decoding - fixes and one test
yaelbh 17c1ea9
done
SamFerracin 4fc024b
model_dump
yaelbh 5f9b20b
Merge branch 'pr-2506' into decoder
yaelbh 6b3af47
fixes
yaelbh 31918ea
fixed converter test
yaelbh 1868d83
do the initial decodin for the schema version without relying on a model
yaelbh e0c6a89
additional tests for the decoder
yaelbh 85bcdaa
black
yaelbh 2a948e2
lint
yaelbh 267d6cc
mypy
yaelbh ef51516
2026
yaelbh 5744b5a
reverting a change
yaelbh ffde640
Merge branch 'executor_preview' of github.com:yaelbh/qiskit-ibm-runti…
yaelbh abba3ad
mypy
yaelbh a72805c
trying to fight a circular import
yaelbh af2c947
lint
yaelbh 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
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
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
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
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
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,86 @@ | ||
| # This code is part of Qiskit. | ||
| # | ||
| # (C) Copyright IBM 2026. | ||
| # | ||
| # 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. | ||
|
|
||
| """Tests the decoder for the noise learner v3 model.""" | ||
|
|
||
| import json | ||
| import numpy as np | ||
| from qiskit.quantum_info import QubitSparsePauliList | ||
|
|
||
| from qiskit_ibm_runtime.noise_learner_v3.converters.version_0_1 import ( | ||
| noise_learner_v3_result_to_0_1, | ||
| ) | ||
| from qiskit_ibm_runtime.noise_learner_v3.noise_learner_v3_decoders import ( | ||
| NoiseLearnerV3ResultDecoder, | ||
| ) | ||
| from qiskit_ibm_runtime.noise_learner_v3.noise_learner_v3_result import ( # type: ignore[attr-defined] | ||
| NoiseLearnerV3Result, | ||
| NoiseLearnerV3Results, | ||
| ) | ||
|
|
||
| from ...ibm_test_case import IBMTestCase | ||
|
|
||
|
|
||
| class TestDecoder(IBMTestCase): | ||
| """Tests the decoder for the noise learner v3 model.""" | ||
|
|
||
| def setUp(self): | ||
| super().setUp() | ||
|
|
||
| generators = [ | ||
| QubitSparsePauliList.from_list(["IX", "XX"]), | ||
| QubitSparsePauliList.from_list(["XI"]), | ||
| ] | ||
| rates = [0.1, 0.2] | ||
| rates_std = [0.01, 0.02] | ||
|
|
||
| metadatum0 = { | ||
| "learning_protocol": "trex", | ||
| "post_selection": {"fraction_kept": 1}, | ||
| } | ||
| result0 = NoiseLearnerV3Result.from_generators(generators, rates, rates_std, metadatum0) | ||
|
|
||
| metadatum1 = { | ||
| "learning_protocol": "lindblad", | ||
| "post_selection": {"fraction_kept": {0: 1, 4: 1}}, | ||
| } | ||
| result1 = NoiseLearnerV3Result.from_generators(generators, rates, metadata=metadatum1) | ||
| self.results = NoiseLearnerV3Results([result0, result1]) | ||
|
|
||
| self.encoded = noise_learner_v3_result_to_0_1(self.results).model_dump_json() | ||
|
|
||
| def test_decoder(self): | ||
| """Tests the decoder.""" | ||
| decoded = NoiseLearnerV3ResultDecoder.decode(self.encoded) | ||
| for datum_in, datum_out in zip(self.results.data, decoded.data): | ||
| assert datum_in._generators == datum_out._generators | ||
| assert np.allclose(datum_in._rates, datum_out._rates) | ||
| assert np.allclose(datum_in._rates_std, datum_out._rates_std) | ||
| assert datum_in.metadata == datum_out.metadata | ||
|
|
||
| def test_no_schema_version(self): | ||
| """Verify that an error is raised if the encoded string | ||
| does not specify any schema version.""" | ||
| encoded_as_json = json.loads(self.encoded) | ||
| del encoded_as_json["schema_version"] | ||
| encoded_as_str = json.dumps(encoded_as_json) | ||
| with self.assertRaisesRegex(ValueError, "Missing schema version."): | ||
| NoiseLearnerV3ResultDecoder.decode(encoded_as_str) | ||
|
|
||
| def test_unknown_schema_version(self): | ||
| """Verify that an error is raised if the schema version specified in the encoded string | ||
| does not exist.""" | ||
| encoded_as_json = json.loads(self.encoded) | ||
| encoded_as_json["schema_version"] = "unknown" | ||
| encoded_as_str = json.dumps(encoded_as_json) | ||
| with self.assertRaisesRegex(ValueError, "No decoder found for schema version unknown."): | ||
| NoiseLearnerV3ResultDecoder.decode(encoded_as_str) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mmmh are you sure of this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is
decoded:Output of
is:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for checking!