Skip to content

Commit

Permalink
Force at least one classical bit in qpd_measurements register (#563)
Browse files Browse the repository at this point in the history
* Force at least one classical bit in `qpd_measurements` register

This is a potential workaround to
openqasm/qe-qasm#37

* Add release note
  • Loading branch information
garrison authored Apr 25, 2024
1 parent d379dea commit 06cebeb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
8 changes: 4 additions & 4 deletions circuit_knitting/cutting/qpd/decompose.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
<https://github.com/openqasm/qe-qasm/issues/37>`__.
6 changes: 3 additions & 3 deletions test/cutting/qpd/test_qpd.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ 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)
circ.h(0)
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)
Expand All @@ -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:
Expand Down

0 comments on commit 06cebeb

Please sign in to comment.