-
Notifications
You must be signed in to change notification settings - Fork 435
Fix handling of circuit metadata #1436
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
mtreinish
merged 14 commits into
Qiskit:main
from
hhorii:parse_metadata_without_to_json
Mar 29, 2022
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
81992f6
use python parser for circuit.header
hhorii b075ec0
support metadata copy with parameterization
hhorii 562e8cb
avoid serialization of circuit metadata
hhorii 04ea641
use circuit_index to specify metadata
hhorii 429ca08
remove metadata from qobj for Aer to simulate circuits
hhorii 4f0c8eb
add release note
hhorii 5e25d4e
Merge branch 'main' into parse_metadata_without_to_json
hhorii 720025c
clear circuite metadata correctly.
hhorii e5afe1d
take unnecessary tests for circuit metadata backup/recovery
hhorii 201a141
Merge branch 'main' into parse_metadata_without_to_json
hhorii ea82810
Merge branch 'main' into parse_metadata_without_to_json
hhorii fd65ac7
work around metadata serialization issue within _run method
hhorii 9392f75
Update releasenotes/notes/remove_circuit_metadata_from_qobj-324e7ea9b…
hhorii f9f80db
Merge branch 'main' into parse_metadata_without_to_json
hhorii 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
13 changes: 13 additions & 0 deletions
13
releasenotes/notes/remove_circuit_metadata_from_qobj-324e7ea9b369ee67.yaml
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,13 @@ | ||
| --- | ||
| fixes: | ||
| - | | ||
| Fixed a potential issue with running simulations on circuits that have the | ||
| :attr:`.QuantumCircuit.metadata` attribute set. The :attr:`~.QuantumCircuit.metadata` | ||
| attribute can be any python dictionary and previously qiskit-aer would attempt to | ||
| JSON serialize the contents of the attribute to process it with the rest of the rest | ||
| of the circuit input, even if the contents were not JSON serializable. This no longer | ||
| occurs as the :attr:`.QuantumCircuit.metadata` attribute is not used to run the | ||
| simulation so now the contents are no serialized and instead are directly attached | ||
| to the :class:`qiskit.result.Result` object without attempting to JSON serialize | ||
| the contents. | ||
| Fixed `#1435 <https://github.com/Qiskit/qiskit-aer/issues/1435>`__ |
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,104 @@ | ||
| # This code is part of Qiskit. | ||
| # | ||
| # (C) Copyright IBM 2018, 2019, 2020, 2021, 2022. | ||
| # | ||
| # 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. | ||
| """ | ||
| AerSimulator Integration Tests | ||
| """ | ||
| from math import sqrt | ||
| from ddt import ddt | ||
| from qiskit import transpile, QuantumCircuit | ||
| from test.terra.reference import ref_algorithms | ||
|
|
||
| from test.terra.backends.simulator_test_case import ( | ||
| SimulatorTestCase, supported_methods) | ||
|
|
||
|
|
||
| @ddt | ||
| class TestMetadata(SimulatorTestCase): | ||
| """AerSimulator algorithm tests in the default basis""" | ||
|
|
||
| @supported_methods( | ||
| ['automatic', 'statevector', 'density_matrix', | ||
| 'matrix_product_state', 'extended_stabilizer']) | ||
| def test_single_circuit_metadata(self, method, device): | ||
| """Test circuits with object metadata.""" | ||
| backend = self.backend(method=method, device=device) | ||
| metadata = {1: object} | ||
| circuit = QuantumCircuit(1, name='circ0', metadata=metadata.copy()) | ||
| result = backend.run(circuit).result() | ||
| self.assertSuccess(result) | ||
| self.assertEqual(result.results[0].header.metadata, metadata) | ||
| self.assertEqual(circuit.metadata, metadata) | ||
|
|
||
| @supported_methods( | ||
| ['automatic', 'statevector', 'density_matrix', | ||
| 'matrix_product_state', 'extended_stabilizer']) | ||
| def test_three_circuit_metadata(self, method, device): | ||
| """Test circuits with object metadata.""" | ||
| backend = self.backend(method=method, device=device) | ||
|
|
||
| metadata0 = {0: object} | ||
| circuit0 = QuantumCircuit(1, name='circ0', metadata=metadata0.copy()) | ||
|
|
||
| metadata1 = {1: object} | ||
| circuit1 = QuantumCircuit(1, name='circ1', metadata=metadata1.copy()) | ||
|
|
||
| metadata2 = {2: object} | ||
| circuit2 = QuantumCircuit(1, name='circ2', metadata=metadata2.copy()) | ||
|
|
||
| result = backend.run([circuit0, circuit1, circuit2]).result() | ||
| self.assertSuccess(result) | ||
| self.assertEqual(len(result.results), 3) | ||
| self.assertEqual(result.results[0].header.metadata, metadata0) | ||
| self.assertEqual(result.results[1].header.metadata, metadata1) | ||
| self.assertEqual(result.results[2].header.metadata, metadata2) | ||
| self.assertEqual(circuit0.metadata, metadata0) | ||
| self.assertEqual(circuit1.metadata, metadata1) | ||
| self.assertEqual(circuit2.metadata, metadata2) | ||
|
|
||
| @supported_methods( | ||
| ['automatic', 'statevector', 'density_matrix', 'matrix_product_state']) | ||
| def test_three_parameterized_circuit_metadata(self, method, device): | ||
| """Test circuits with object metadata.""" | ||
| backend = self.backend(method=method, device=device) | ||
|
|
||
| metadata0 = {0: object} | ||
| circuit0 = QuantumCircuit(1, name='circ0', metadata=metadata0.copy()) | ||
| circuit0.ry(0.1, 0) | ||
| circuit0.measure_all() | ||
|
|
||
| metadata1 = {1: object} | ||
| circuit1 = QuantumCircuit(1, name='circ1', metadata=metadata1.copy()) | ||
| circuit1.ry(0.1, 0) | ||
| circuit1.measure_all() | ||
|
|
||
| metadata2 = {2: object} | ||
| circuit2 = QuantumCircuit(1, name='circ2', metadata=metadata2.copy()) | ||
| circuit2.ry(0.1, 0) | ||
| circuit2.measure_all() | ||
|
|
||
| parameterizations=[[[[0, 0], [0, 1]]], | ||
| [[[0, 0], [0, 1, 2]]], | ||
| []] | ||
|
|
||
| result = backend.run([circuit0, circuit1, circuit2], | ||
| parameterizations=parameterizations).result() | ||
| self.assertSuccess(result) | ||
| self.assertEqual(len(result.results), 6) | ||
| self.assertEqual(result.results[0].header.metadata, metadata0) | ||
| self.assertEqual(result.results[1].header.metadata, metadata0) | ||
| self.assertEqual(result.results[2].header.metadata, metadata1) | ||
| self.assertEqual(result.results[3].header.metadata, metadata1) | ||
| self.assertEqual(result.results[4].header.metadata, metadata1) | ||
| self.assertEqual(result.results[5].header.metadata, metadata2) | ||
| self.assertEqual(circuit0.metadata, metadata0) | ||
| self.assertEqual(circuit1.metadata, metadata1) | ||
| self.assertEqual(circuit2.metadata, metadata2) | ||
|
hhorii marked this conversation as resolved.
|
||
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.