Skip to content

Commit

Permalink
Fix nested FlowController instances forgetting passes
Browse files Browse the repository at this point in the history
gh-6962 added support for nested `FlowController` instances.  It did
not, however, propagate any `DAGCircuit` output by its internal passes
into the transpilation loop, which meant that if a pass returned a new
DAG rather than mutating the input, the changes would be thrown away.
Similar behaviour was occuring with the pass "normalisation" step;
incorrect classes would raise an error, but if the normalisation needed
to raise a single pass to a list, the result would not be re-bound into
the nested controller.
  • Loading branch information
jakelishman committed Oct 3, 2022
1 parent b935ae9 commit a363da7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
8 changes: 6 additions & 2 deletions qiskit/transpiler/passmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,12 @@ def _normalize_passes(
passes = [passes]
for pass_ in passes:
if isinstance(pass_, FlowController):
# Normalize passes in nested FlowController
PassManager._normalize_passes(pass_.passes)
# Normalize passes in nested FlowController.
# TODO: Internal renormalisation should be the responsibility of the
# `FlowController`, but the separation between `FlowController`,
# `RunningPassManager` and `PassManager` is so muddled right now, it would be better
# to do this as part of more top-down refactoring. ---Jake, 2022-10-03.
pass_.passes = PassManager._normalize_passes(pass_.passes)
elif not isinstance(pass_, BasePass):
raise TranspilerError(
"%s is not a BasePass or FlowController instance " % pass_.__class__
Expand Down
2 changes: 1 addition & 1 deletion qiskit/transpiler/runningpassmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def _do_pass(self, pass_, dag, options):
pass_.do_while = partial(pass_.do_while, self.fenced_property_set)

for _pass in pass_:
self._do_pass(_pass, dag, pass_.options)
dag = self._do_pass(_pass, dag, pass_.options)
else:
raise TranspilerError(
"Expecting type BasePass or FlowController, got %s." % type(pass_)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
fixes:
- |
Nesting a :class:`.FlowController` inside another in a :class:`.PassManager`
could previously cause some transpiler passes to become "forgotten" during
transpilation, if the passes returned a new :class:`.DAGCircuit` rather than
mutating their input. Nested :class:`.FlowController`\ s will now affect
the transpilation correctly.

0 comments on commit a363da7

Please sign in to comment.