-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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 Annotated Operations #11505
Changes from 15 commits
e6135fb
1ff5c27
27ca7a6
f70d7c1
4915b10
5b47096
47a46bc
4702925
6559e88
4290033
5541897
fb6a249
2d9bde6
853181e
3beff04
72096a7
77d044d
8fc1674
edf81aa
afae401
e8042ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,6 +139,11 @@ | |
PAULI_EVOLUTION_DEF_PACK = "!Q?1cQQ" | ||
PAULI_EVOLUTION_DEF_SIZE = struct.calcsize(PAULI_EVOLUTION_DEF_PACK) | ||
|
||
# Modifier | ||
MODIFIER_DEF = namedtuple("MODIFIER_DEF", ["type", "num_ctrl_qubits", "ctrl_state", "power"]) | ||
MODIFIER_DEF_PACK = "!1cIId" | ||
MODIFIER_DEF_SIZE = struct.calcsize(MODIFIER_DEF_PACK) | ||
Comment on lines
+143
to
+145
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this requires bumping the QPY version to 11 as this is a new struct to represent the modifiers. If someone tried to load a file using this with 0.45 which uses the same qpy version this would result in an error when the loader encounters the annotated operation (actually the new type key would trigger this too). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, thanks. Does this mean that I need to change this line
to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You'll need to change that condition, also bump https://github.com/Qiskit/qiskit/blob/main/qiskit/qpy/common.py#L23 to 11, and also update the format documentation to describe what's new in version 11. I have another PR #11646 that actually is adding version 11 already, you can use this as a model. The two will merge conflict but we can handle that as there will only be version 11 in this release (there is only one format version for each qiskit release). #11644 will have implications for this, as we'll need to error if someone uses an annotated operation and the |
||
|
||
# CUSTOM_CIRCUIT_DEF_HEADER | ||
CUSTOM_CIRCUIT_DEF_HEADER = namedtuple("CUSTOM_CIRCUIT_DEF_HEADER", ["size"]) | ||
CUSTOM_CIRCUIT_DEF_HEADER_PACK = "!Q" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
fixes: | ||
- | | ||
QPY (using :func:`.qpy.dump` and :func:`.qpy.load`) will now correctly serialize | ||
and deserialize quantum circuits with annotated operations | ||
(:class:`~.AnnotatedOperation`). |
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.
Do we not export
AnnotatedOperation
fromqiskit.circuit
? I feel like it should be there as it is a public interface. If we are wouldn't this line pick it up as an attribute of the circuit module?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.
Indeed, that was an omission on my part. 77d044d exports this together with the modifiers. This also removes the need to check the name in the
if
above.