Skip to content
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
5 changes: 3 additions & 2 deletions qiskit/dagcircuit/dagcircuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1441,10 +1441,11 @@ def _collect_1q_runs(self):
while len(s) == 1 and \
s[0].type == "op" and \
len(s[0].qargs) == 1 and \
len(s[0].cargs) == 0 and \
not s[0].cargs and \
s[0].condition is None and \
s[0] not in nodes_seen and \
not s[0].op.is_parameterized() and \
isinstance(node.op, Gate):
isinstance(s[0].op, Gate):
group.append(s[0])
nodes_seen.add(s[0])
s = self._multi_graph.successors(s[0]._node_id)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
fixes:
- |
Fixed an issue introduced in 0.16.2 that would cause errors when running
:func:`~qiskit.compiler.transpile` on a circuit with a series of 1 qubit
gates and a non-gate instruction that only operates on a qubit (e.g.
:class:`~qiskit.circuit.Reset`). Fixes
`#5736 <https://github.com/Qiskit/qiskit-terra/issues/5736>`__
15 changes: 15 additions & 0 deletions test/python/dagcircuit/test_dagcircuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,21 @@ def test_dag_collect_1q_runs(self):
else:
self.fail('Unknown run encountered')

def test_dag_no_reset_in_collect_1q_runs(self):
"""Test a run does not include a reset instruction."""
dag = DAGCircuit()
qreg = QuantumRegister(1, 'qr')
creg = ClassicalRegister(1, 'cr')
dag.add_qreg(qreg)
dag.add_creg(creg)
dag.apply_operation_back(U1Gate(3.14), [qreg[0]])
dag.apply_operation_back(HGate(), [qreg[0]])
dag.apply_operation_back(Reset(), [qreg[0]])
dag.apply_operation_back(Measure(), [qreg[0]], [creg[0]])
runs = dag._collect_1q_runs()
self.assertEqual([[x.name for x in run] for run in runs],
[['u1', 'h']])

def test_dag_collect_1q_runs_start_with_conditional(self):
"""Test collect 1q runs with a conditional at the start of the run."""
h_gate = HGate()
Expand Down