Skip to content

Commit 0f7c6f6

Browse files
Fix qpy for MCMTGate (#14096)
* Add MCMXGate to custom operations * Add test and reno --------- Co-authored-by: Shelly Garion <46566946+ShellyGarion@users.noreply.github.com>
1 parent 4675335 commit 0f7c6f6

3 files changed

Lines changed: 15 additions & 0 deletions

File tree

qiskit/qpy/binary_io/circuits.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,11 @@ def _write_instruction(
783783
custom_operations[gate_class_name] = instruction.operation
784784
custom_operations_list.append(gate_class_name)
785785

786+
elif isinstance(instruction.operation, library.MCMTGate):
787+
gate_class_name = instruction.operation.name + "_" + str(uuid.uuid4())
788+
custom_operations[gate_class_name] = instruction.operation
789+
custom_operations_list.append(gate_class_name)
790+
786791
condition_type = type_keys.Condition.NONE
787792
condition_register = b""
788793
condition_value = 0
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
fixes:
3+
- |
4+
Fixed a bug in QPY (:mod:`qiskit.qpy`) where circuits containing gates of class
5+
:class:`.MCMTGate` would fail to serialize.
6+
See `#13965 <https://github.com/Qiskit/qiskit/issues/13965>`__.

test/python/circuit/test_circuit_load_from_qpy.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from qiskit.circuit.gate import Gate
3131
from qiskit.circuit.library import (
3232
XGate,
33+
ZGate,
3334
CXGate,
3435
RYGate,
3536
QFT,
@@ -41,6 +42,7 @@
4142
MCXGrayCode,
4243
MCXRecursive,
4344
MCXVChain,
45+
MCMTGate,
4446
UCRXGate,
4547
UCRYGate,
4648
UCRZGate,
@@ -1261,11 +1263,13 @@ def test_standard_control_gates(self):
12611263
mcx_gray_gate = MCXGrayCode(5)
12621264
mcx_recursive_gate = MCXRecursive(4)
12631265
mcx_vchain_gate = MCXVChain(3)
1266+
mcmt_gate = MCMTGate(ZGate(), 2, 1)
12641267
qc.append(mcu1_gate, [0, 2, 1])
12651268
qc.append(mcx_gate, list(range(0, 6)))
12661269
qc.append(mcx_gray_gate, list(range(0, 6)))
12671270
qc.append(mcx_recursive_gate, list(range(0, 5)))
12681271
qc.append(mcx_vchain_gate, list(range(0, 5)))
1272+
qc.append(mcmt_gate, list(range(0, 3)))
12691273
qc.mcp(np.pi, [0, 2], 1)
12701274
qc.mcx([0, 2], 1)
12711275
qc.measure_all()

0 commit comments

Comments
 (0)