Skip to content

Commit

Permalink
Avoid collecting non atomic nodes in 1q runs (#5570)
Browse files Browse the repository at this point in the history
* Fixing issue 5543 avoid collecting non atomic nodes in 1q runs

* Update qiskit/dagcircuit/dagcircuit.py

Co-authored-by: Kevin Krsulich <kevin@krsulich.net>

Co-authored-by: Kevin Krsulich <kevin@krsulich.net>
Co-authored-by: Kevin Krsulich <kevin.krsulich@ibm.com>
  • Loading branch information
3 people authored Jan 7, 2021
1 parent 74ed881 commit e193de0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions qiskit/dagcircuit/dagcircuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1384,6 +1384,8 @@ def filter_fn(node):
return node.type == 'op' and len(node.qargs) == 1 \
and len(node.cargs) == 0 and node.condition is None \
and not node.op.is_parameterized() \
and isinstance(node.op, Gate) \
and hasattr(node.op, '__array__')

group_list = rx.collect_runs(self._multi_graph, filter_fn)
return set(tuple(x) for x in group_list)
Expand Down
11 changes: 11 additions & 0 deletions test/python/dagcircuit/test_dagcircuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from qiskit.circuit import QuantumCircuit
from qiskit.circuit import Measure
from qiskit.circuit import Reset
from qiskit.circuit import Delay
from qiskit.circuit import Gate, Instruction
from qiskit.circuit import Parameter
from qiskit.circuit.library.standard_gates.i import IGate
Expand Down Expand Up @@ -712,6 +713,8 @@ def test_dag_collect_runs_conditional_in_middle(self):

def test_dag_collect_1q_runs(self):
"""Test the collect_1q_runs method with 3 different gates."""
self.dag.apply_operation_back(Reset(), [self.qubit0])
self.dag.apply_operation_back(Delay(100), [self.qubit0])
self.dag.apply_operation_back(U1Gate(3.14), [self.qubit0])
self.dag.apply_operation_back(U1Gate(3.14), [self.qubit0])
self.dag.apply_operation_back(U1Gate(3.14), [self.qubit0])
Expand All @@ -736,6 +739,8 @@ def test_dag_collect_1q_runs(self):

def test_dag_collect_1q_runs_start_with_conditional(self):
"""Test collect 1q runs with a conditional at the start of the run."""
self.dag.apply_operation_back(Reset(), [self.qubit0])
self.dag.apply_operation_back(Delay(100), [self.qubit0])
h_gate = HGate()
h_gate.condition = self.condition
self.dag.apply_operation_back(
Expand All @@ -752,6 +757,8 @@ def test_dag_collect_1q_runs_start_with_conditional(self):

def test_dag_collect_1q_runs_conditional_in_middle(self):
"""Test collect_1q_runs with a conditional in the middle of a run."""
self.dag.apply_operation_back(Reset(), [self.qubit0])
self.dag.apply_operation_back(Delay(100), [self.qubit0])
h_gate = HGate()
h_gate.condition = self.condition
self.dag.apply_operation_back(HGate(), [self.qubit0])
Expand All @@ -769,6 +776,8 @@ def test_dag_collect_1q_runs_conditional_in_middle(self):
def test_dag_collect_1q_runs_with_parameterized_gate(self):
"""Test collect 1q splits on parameterized gates."""
theta = Parameter('theta')
self.dag.apply_operation_back(Reset(), [self.qubit0])
self.dag.apply_operation_back(Delay(100), [self.qubit0])
self.dag.apply_operation_back(HGate(), [self.qubit0])
self.dag.apply_operation_back(HGate(), [self.qubit0])
self.dag.apply_operation_back(U1Gate(theta), [self.qubit0])
Expand All @@ -783,6 +792,8 @@ def test_dag_collect_1q_runs_with_parameterized_gate(self):

def test_dag_collect_1q_runs_with_cx_in_middle(self):
"""Test collect_1q_runs_with a cx in the middle of the run."""
self.dag.apply_operation_back(Reset(), [self.qubit0])
self.dag.apply_operation_back(Delay(100), [self.qubit0])
self.dag.apply_operation_back(HGate(), [self.qubit0])
self.dag.apply_operation_back(HGate(), [self.qubit0])
self.dag.apply_operation_back(U1Gate(3.14), [self.qubit0])
Expand Down

0 comments on commit e193de0

Please sign in to comment.