Skip to content

Commit

Permalink
self.dag_might_have_modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Luciano Bello committed Nov 2, 2019
1 parent 2e27145 commit ec8e31a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions qiskit/transpiler/runningpassmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def __init__(self, max_iteration, callback):
"""Initialize an empty PassManager object (with no passes scheduled).
Args:
max_iteration (int): The schedule looping iterates until the condition is met or until
max_iteration is reached.
max_iteration (int): The schedule looping iterates until the condition
is met or until max_iteration is reached.
callback (func): A callback function that will be called after each
pass execution. The function will be called with 5 keyword
arguments:
Expand Down Expand Up @@ -363,12 +363,17 @@ class RollbackIfController(FlowController):
""" The set of passes is rolled back if a condition is true."""

def __init__(self, passes, options, rollback_if=None, **_):
self.dag_might_have_modifications = False
for pass_ in passes:
if pass_.is_transformation_pass:
self.dag_might_have_modifications = True
break
self.rollback_if = rollback_if
super().__init__(passes, options)

def do_passes(self, pass_manager, dag, property_set):
original_property_set = deepcopy(pass_manager.property_set)
dag_copy = deepcopy(dag)
dag_copy = deepcopy(dag) if self.dag_might_have_modifications else dag
for pass_ in self:
dag_copy = pass_manager._do_pass(pass_, dag_copy)
if self.rollback_if(pass_manager.property_set):
Expand Down

0 comments on commit ec8e31a

Please sign in to comment.