-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Fix qpy support for Cliffords #11495
Conversation
One or more of the the following people are requested to review this:
|
Pull Request Test Coverage Report for Build 7553589438Warning: 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 |
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 @mtreinish would like a final look but LGTM 🙂
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.
Overall this LGTM thanks for the fix. I left one question inline about whether there is a potential simplification to the read logic.
The only other thing we maybe want to add is a backwards compatibility test to https://github.com/Qiskit/qiskit/blob/main/test/qpy_compat/test_qpy.py ? I'm not sure it's needed but if you think there's value in validating that we can load a Clifford
with newer qiskit from an historical release it would be good to add there (moving forward we'd obviously have to limit the version strings, see: https://github.com/Qiskit/qiskit/blob/main/test/qpy_compat/test_qpy.py#L750).
qiskit/qpy/binary_io/circuits.py
Outdated
@@ -290,13 +290,17 @@ def _read_instruction( | |||
gate_class = getattr(quantum_initializer, gate_name) | |||
elif hasattr(controlflow, gate_name): | |||
gate_class = getattr(controlflow, gate_name) | |||
elif gate_name == "Clifford": | |||
pass |
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.
Shouldn't this be?
pass | |
gate_class = Clifford |
Mostly just for consistency. But if we did this then we would be able to drop the special handling in L302 as it would just call gate_class(*params)
. Or is len(Clifford.params) > 1 and doing this wouldn't work?
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.
Done in bc1f5e3.
I've tagged this as stable backport potential because this is something we can fix for 0.45.x, especially as there is no version change to the QPY format. |
Since you have mentioned this, I think that adding a backwards compatibility Cliffords test might be a good idea, this is done 5f42977. The only thing I am not 100% sure is whether the line limiting the version strings should read |
Update: I don't understand why the backward compatibility test fails: the claimed error
is exactly what was fixed in this PR. Or is this because the milestone for this PR is set to |
It looks like the compatibility tests fail because you've added a |
Thanks @Cryoris, which version then we should enable? I thought it's |
0.45.2 is correct assuming we're going to backport this (which I think we should). The actual issue causing the failure is because of the |
I pushed up #11572 to address 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.
This LGTM, thanks for the updates.
@@ -640,6 +640,21 @@ def generate_layout_circuits(): | |||
return [qc] | |||
|
|||
|
|||
def generate_clifford_circuits(): | |||
"""Test qpy circuits with Clifford operations.""" | |||
from qiskit.quantum_info import Clifford |
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'm not sure the runtime import is strictly needed as this is only necessary if the import doesn't exist on all the historical versions that runs this file. But in the case of Clifford
that should exist in 0.18.0 (which is the oldest version tested with this, which added qpy). But it doesn't make a difference in practice.
* clifford qpy support + test * release notes * cleanup: checking if instruction is of type Instruction * review comment * review comments: consistency + remove specialized handling * adding test to test_qpy.py * changing version string to 0.45.2 --------- Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com> (cherry picked from commit 786c0e9)
* clifford qpy support + test * release notes * cleanup: checking if instruction is of type Instruction * review comment * review comments: consistency + remove specialized handling * adding test to test_qpy.py * changing version string to 0.45.2 --------- Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com> (cherry picked from commit 786c0e9) Co-authored-by: Alexander Ivrii <alexi@il.ibm.com>
Summary
This PR adds QPY support for Cliffords, partially fixing #11088.