Skip to content

Commit

Permalink
Look at predecessors of output_map
Browse files Browse the repository at this point in the history
Suggested at #11266 (comment)

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
  • Loading branch information
garrison and mtreinish committed Nov 17, 2023
1 parent 01ddf91 commit f358d46
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions qiskit/transpiler/passes/optimization/remove_final_reset.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

"""Remove reset when it is the final instruction on a qubit."""

from qiskit.circuit import Reset
from qiskit.dagcircuit import DAGOutNode
from qiskit.circuit import Reset, Qubit
from qiskit.dagcircuit import DAGOpNode
from qiskit.transpiler.basepasses import TransformationPass


Expand All @@ -29,9 +29,9 @@ def run(self, dag):
Returns:
DAGCircuit: the optimized DAG.
"""
resets = dag.op_nodes(Reset)
for reset in resets:
successor = next(dag.successors(reset))
if isinstance(successor, DAGOutNode):
dag.remove_op_node(reset)
for output_node in dag.output_map.values():
if isinstance(output_node.wire, Qubit):
pred = next(dag.predecessors(output_node))
if isinstance(pred, DAGOpNode) and isinstance(pred.op, Reset):
dag.remove_op_node(pred)
return dag

0 comments on commit f358d46

Please sign in to comment.