Skip to content
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 DiagonalGate QPY serialisation #10376

Merged
merged 9 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion qiskit/qpy/binary_io/circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,14 @@ def _read_instruction(file_obj, circuit, registers, custom_operations, version,
gate.ctrl_state = instruction.ctrl_state
gate.condition = condition_tuple
else:
if gate_name in {"Initialize", "StatePreparation", "UCRXGate", "UCRYGate", "UCRZGate"}:
if gate_name in {
"Initialize",
"StatePreparation",
"UCRXGate",
"UCRYGate",
"UCRZGate",
"DiagonalGate",
}:
gate = gate_class(params)
else:
if gate_name == "Barrier":
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
fixes:
- |
Fixed the deserialization of :class:`.DiagonalGate` instances through QPY.
See `#10364 <https://github.com/Qiskit/qiskit-terra/issues/10364>`__.
15 changes: 15 additions & 0 deletions test/python/circuit/test_circuit_load_from_qpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1408,6 +1408,21 @@ def test_incomplete_owned_bits(self):
self.assertEqual(qc, new_circuit)
self.assertDeprecatedBitProperties(qc, new_circuit)

def test_diagonal_gate(self):
"""Test that a `DiagonalGate` successfully roundtrips."""
qc = QuantumCircuit(2)
qc.diagonal([1, -1, -1, 1], [0, 1])
with io.BytesIO() as fptr:
dump(qc, fptr)
fptr.seek(0)
new_circuit = load(fptr)[0]
# DiagonalGate (and a bunch of the qiskit.extensions gates) have non-deterministic
# definitions with regard to internal instruction names, so cannot be directly compared for
# equality.
self.assertIs(type(qc.data[0].operation), type(new_circuit.data[0].operation))
self.assertEqual(qc.data[0].operation.params, new_circuit.data[0].operation.params)
self.assertDeprecatedBitProperties(qc, new_circuit)

def test_qpy_deprecation(self):
"""Test the old import path's deprecations fire."""
with self.assertWarnsRegex(DeprecationWarning, "is deprecated"):
Expand Down