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 decomposition of an instruction with a single qubit and clbit #8614

Merged
merged 2 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion qiskit/transpiler/passes/basis/decompose.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ def run(self, dag: DAGCircuit) -> DAGCircuit:
continue
# TODO: allow choosing among multiple decomposition rules
rule = node.op.definition.data
if len(rule) == 1 and len(node.qargs) == len(rule[0].qubits) == 1:
if (
len(rule) == 1
and len(node.qargs) == len(rule[0].qubits) == 1 # to preserve gate order
and len(node.cargs) == len(rule[0].clbits) == 0
):
if node.op.definition.global_phase:
dag.global_phase += node.op.definition.global_phase
dag.substitute_node(node, rule[0].operation, inplace=True)
Expand Down
13 changes: 13 additions & 0 deletions releasenotes/notes/fix-decomp-1q-1c-84f369f9a897a5b7.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
fixes:
- |
Fixed a bug where decomposing an instruction with one qubit and one classical bit
containing a single quantum gate failed. Now the following decomposes as expected::

block = QuantumCircuit(1, 1)
block.h(0)

circuit = QuantumCircuit(1, 1)
circuit.append(block, [0], [0])

decomposed = circuit.decompose()
15 changes: 15 additions & 0 deletions test/python/transpiler/test_decompose.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,18 @@ def test_decompose_reps(self):
decom_circ = self.complex_circuit.decompose(reps=2)
decomposed = self.complex_circuit.decompose().decompose()
self.assertEqual(decom_circ, decomposed)

def test_decompose_single_qubit_clbit(self):
"""Test the decomposition of a block with a single qubit and clbit works.

Regression test of Qiskit/qiskit-terra#8591.
"""
block = QuantumCircuit(1, 1)
block.h(0)

circuit = QuantumCircuit(1, 1)
circuit.append(block, [0], [0])

decomposed = circuit.decompose()

self.assertEqual(decomposed, block)