-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Allow correct retrieval of circuit with initialize instruction from qpy file #11206
Allow correct retrieval of circuit with initialize instruction from qpy file #11206
Conversation
Pull Request Test Coverage Report for Build 6909812262Warning: This coverage report may be inaccurate.We've detected an issue with your CI configuration that might affect the accuracy of this pull request's coverage report.
💛 - Coveralls |
with io.BytesIO() as fptr: | ||
dump(qc, fptr) | ||
fptr.seek(0) | ||
new_circuit = load(fptr)[0] | ||
self.assertEqual(qc, new_circuit) | ||
self.assertDeprecatedBitProperties(qc, new_circuit) |
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.
Maybe a bit out of the scope of this ticket, but I saw that this piece of code of 5 lines (or equivalent code
qiskit/test/python/circuit/test_circuit_load_from_qpy.py
Lines 485 to 490 in daeceef
qpy_file = io.BytesIO() | |
dump(qc, qpy_file) | |
qpy_file.seek(0) | |
new_circ = load(qpy_file)[0] | |
self.assertEqual(qc, new_circ) | |
self.assertDeprecatedBitProperties(qc, new_circ) |
) is repeated throughout this file a lot of times. Wouldn't it be better if we had in this test file a similar function as the one in qpy/test_circuit_load_from_qpy ?
qiskit/test/python/qpy/test_circuit_load_from_qpy.py
Lines 34 to 42 in af643eb
def assert_roundtrip_equal(self, circuit): | |
"""QPY roundtrip equal test.""" | |
qpy_file = io.BytesIO() | |
dump(circuit, qpy_file) | |
qpy_file.seek(0) | |
new_circuit = load(qpy_file)[0] | |
self.assertEqual(circuit, new_circuit) | |
self.assertEqual(circuit.layout, new_circuit.layout) |
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.
Yeah, we could potentially improve this. This particular file is older that test/qpy/test_circuit_load_from_qpy.py
, and to be honest, I don't know why this one still exists - I thought it had been moved into the test/python/qpy
one some time ago. You're right that it would be better in a follow-up PR. If you'd like to make such a PR, it would be welcome.
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.
I would like to make a PR with the refactoring of this file. I will open an issue and associated PR shortly! Thanks
Thank you for opening a new pull request. Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient. While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone. One or more of the the following people are requested to review this:
|
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.
Thank you for this! Please could you add a "bugfix" release note briefly explaining the change?
with io.BytesIO() as fptr: | ||
dump(qc, fptr) | ||
fptr.seek(0) | ||
new_circuit = load(fptr)[0] | ||
self.assertEqual(qc, new_circuit) | ||
self.assertDeprecatedBitProperties(qc, new_circuit) |
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.
Yeah, we could potentially improve this. This particular file is older that test/qpy/test_circuit_load_from_qpy.py
, and to be honest, I don't know why this one still exists - I thought it had been moved into the test/python/qpy
one some time ago. You're right that it would be better in a follow-up PR. If you'd like to make such a PR, it would be welcome.
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!
…py file (#11206) * treated cases for StatePreparation initialization when reading from qpy file * added test for state preparation from qpy * added docstring to test function * added fix release note * Fixup release note --------- Co-authored-by: Jake Lishman <jake.lishman@ibm.com> (cherry picked from commit 9111d0f)
…py file (#11206) (#11274) * treated cases for StatePreparation initialization when reading from qpy file * added test for state preparation from qpy * added docstring to test function * added fix release note * Fixup release note --------- Co-authored-by: Jake Lishman <jake.lishman@ibm.com> (cherry picked from commit 9111d0f) Co-authored-by: SoranaAurelia <52232581+SoranaAurelia@users.noreply.github.com>
Summary
This PR fixes #11158 . It adds the necessary conditions and cases for treating the StatePreparation instruction when reading from a qpy file.
Details and comments
When loading a circuit that had an initialize instruction (with an index or a label as parameter) from a qpy file, a QiskitError was thrown because these cases were not treated when the circuit was rebuilt, more specifically in the read instruction function.