From a38947ec345611a406c9ecfad5d344a169188e66 Mon Sep 17 00:00:00 2001 From: Jim Garrison Date: Wed, 24 Apr 2024 15:07:00 -0400 Subject: [PATCH 1/2] Force at least one classical bit in `qpd_measurements` register This is a potential workaround to https://github.com/openqasm/qe-qasm/issues/37 --- circuit_knitting/cutting/qpd/decompose.py | 8 ++++---- test/cutting/qpd/test_qpd.py | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/circuit_knitting/cutting/qpd/decompose.py b/circuit_knitting/cutting/qpd/decompose.py index 999a66437..035b2101e 100644 --- a/circuit_knitting/cutting/qpd/decompose.py +++ b/circuit_knitting/cutting/qpd/decompose.py @@ -145,10 +145,10 @@ def _decompose_qpd_measurements( if instruction.operation.name.lower() == "qpd_measure" ] - # Create a classical register for the qpd measurement results. This is - # partly for convenience, partly to work around - # https://github.com/Qiskit/qiskit-aer/issues/1660. - reg = ClassicalRegister(len(qpd_measure_ids), name="qpd_measurements") + # Create a classical register for the qpd measurement results. + # We force at least one classical bit as a workaround to + # https://github.com/openqasm/qe-qasm/issues/37. + reg = ClassicalRegister(max(1, len(qpd_measure_ids)), name="qpd_measurements") circuit.add_register(reg) # Place the measurement instructions diff --git a/test/cutting/qpd/test_qpd.py b/test/cutting/qpd/test_qpd.py index 7a539131b..59c1b7e04 100644 --- a/test/cutting/qpd/test_qpd.py +++ b/test/cutting/qpd/test_qpd.py @@ -148,7 +148,7 @@ def test_decompose_qpd_instructions(self): with self.subTest("Empty circuit"): circ = QuantumCircuit() new_circ = decompose_qpd_instructions(QuantumCircuit(), []) - circ.add_register(ClassicalRegister(0, name="qpd_measurements")) + circ.add_register(ClassicalRegister(1, name="qpd_measurements")) self.assertEqual(circ, new_circ) with self.subTest("No QPD circuit"): circ = QuantumCircuit(2, 1) @@ -156,7 +156,7 @@ def test_decompose_qpd_instructions(self): circ.cx(0, 1) circ.measure(1, 0) new_circ = decompose_qpd_instructions(circ, []) - circ.add_register(ClassicalRegister(0, name="qpd_measurements")) + circ.add_register(ClassicalRegister(1, name="qpd_measurements")) self.assertEqual(circ, new_circ) with self.subTest("Single QPD gate"): circ = QuantumCircuit(2) @@ -165,7 +165,7 @@ def test_decompose_qpd_instructions(self): qpd_gate = TwoQubitQPDGate(qpd_basis) circ.data.append(CircuitInstruction(qpd_gate, qubits=[0, 1])) decomp_circ = decompose_qpd_instructions(circ, [[0]], map_ids=[0]) - circ_compare.add_register(ClassicalRegister(0, name="qpd_measurements")) + circ_compare.add_register(ClassicalRegister(1, name="qpd_measurements")) self.assertEqual(decomp_circ, circ_compare) with self.subTest("Incorrect map index size"): with pytest.raises(ValueError) as e_info: From a2ffe3a607f6d377e5067cdbb604dcdf22d826a9 Mon Sep 17 00:00:00 2001 From: Jim Garrison Date: Wed, 24 Apr 2024 21:02:48 -0400 Subject: [PATCH 2/2] Add release note --- .../notes/nonzero-register-size-e112e34417ff79b9.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 releasenotes/notes/nonzero-register-size-e112e34417ff79b9.yaml diff --git a/releasenotes/notes/nonzero-register-size-e112e34417ff79b9.yaml b/releasenotes/notes/nonzero-register-size-e112e34417ff79b9.yaml new file mode 100644 index 000000000..66f30b777 --- /dev/null +++ b/releasenotes/notes/nonzero-register-size-e112e34417ff79b9.yaml @@ -0,0 +1,8 @@ +--- +fixes: + - | + Added a workaround so that the classical registers in the + generated circuits will always contain at least one bit. This is + currently necessary for the experiments to be able to reach IBM + Quantum's hardware backends due to an `openqasm parser issue + `__.