Skip to content

Commit

Permalink
Add dedicated scheduling stage to FullPassManager
Browse files Browse the repository at this point in the history
  • Loading branch information
mtreinish committed Sep 10, 2021
1 parent c86a7fb commit f177d5f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
18 changes: 18 additions & 0 deletions qiskit/transpiler/passmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ class FullPassManager(PassManager):
6. Optimization - The main optimization loop, this will typically run in a loop trying to optimize
the circuit until a condtion (such as fixed depth) is reached.
7. Post-Optimization - Any passes to run after the main optimization loop
8. Scheduling - Any hardware aware scheduling passes
These stages will be executed in order and any stage set to ``None`` will be skipped. If
a :class:`~qiskit.transpiler.PassManager` input is being used for more than 1 stage here
Expand All @@ -348,6 +349,7 @@ class FullPassManager(PassManager):
"pre_optimization",
"optimization",
"post_optimization",
"scheduling",
]

def __init__(
Expand All @@ -359,6 +361,7 @@ def __init__(
pre_optimization=None,
optimization=None,
post_optimization=None,
scheduling=None,
):
"""Initialize a new FullPassManager object
Expand All @@ -377,6 +380,7 @@ def __init__(
optimization loop stage
post_opt (PassManager): A pass manager to run after the optimization
loop
scheduling (PassManager): A pass manager to run any scheduling passes
"""
super().__init__()
self._init = init
Expand All @@ -386,6 +390,7 @@ def __init__(
self._pre_optimization = pre_optimization
self._optimization = optimization
self._post_optimization = post_optimization
self._scheduling = scheduling
self._update_passmanager()

def _update_passmanager(self):
Expand All @@ -404,6 +409,8 @@ def _update_passmanager(self):
self._pass_sets.extend(self._optimization._pass_sets)
if self._post_optimization:
self._pass_sets.extend(self._post_optimization._pass_sets)
if self._scheduling:
self._pass_sets.extend(self._scheduling._pass_sets)

@property
def init(self):
Expand Down Expand Up @@ -470,3 +477,14 @@ def post_optimization(self, value):
"""Set the :class:`~qiskit.transpiler.PassManager` for the post_optimization stage."""
self._post_optimization = value
self._update_passmanager()

@property
def scheduling(self):
"""Get the :class:`~qiskit.transpiler.PassManager` for the scheduling stage."""
return self._post_optimization

@scheduling.setter
def scheduling(self, value):
"""Set the :class:`~qiskit.transpiler.PassManager` for the scheduling stage."""
self._post_optimization = value
self._update_passmanager()
4 changes: 2 additions & 2 deletions qiskit/transpiler/preset_passmanagers/level0.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ def _choose_layout_condition(property_set):
pre_opt += translation
else:
pre_opt = None
post_opt = common.generate_scheduling_post_opt(
sched = common.generate_scheduling_post_opt(
instruction_durations, scheduling_method, timing_constraints, inst_map
)
return FullPassManager(
layout=layout,
routing=routing,
translation=translation,
pre_optimization=pre_opt,
post_optimization=post_opt,
scheduling=sched,
)
4 changes: 2 additions & 2 deletions qiskit/transpiler/preset_passmanagers/level1.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def _opt_control(property_set):
unroll = [pass_ for x in translation.passes() for pass_ in x["passes"]]
opt_loop = _depth_check + _opt + unroll
optimization.append(opt_loop, do_while=_opt_control)
post_optimization = common.generate_scheduling_post_opt(
sched = common.generate_scheduling_post_opt(
instruction_durations, scheduling_method, timing_constraints, inst_map
)

Expand All @@ -166,5 +166,5 @@ def _opt_control(property_set):
translation=translation,
pre_optimization=pre_optimization,
optimization=optimization,
post_optimization=post_optimization,
scheduling=sched,
)
4 changes: 2 additions & 2 deletions qiskit/transpiler/preset_passmanagers/level2.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def _opt_control(property_set):
unroll = [pass_ for x in translation.passes() for pass_ in x["passes"]]
opt_loop = _depth_check + _opt + unroll
optimization.append(opt_loop, do_while=_opt_control)
post_optimization = common.generate_scheduling_post_opt(
sched = common.generate_scheduling_post_opt(
instruction_durations, scheduling_method, timing_constraints, inst_map
)

Expand All @@ -204,5 +204,5 @@ def _opt_control(property_set):
translation=translation,
pre_optimization=pre_optimization,
optimization=optimization,
post_optimization=post_optimization,
scheduling=sched,
)
4 changes: 2 additions & 2 deletions qiskit/transpiler/preset_passmanagers/level3.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def _opt_control(property_set):
unroll = [pass_ for x in translation.passes() for pass_ in x["passes"]]
opt_loop = _depth_check + _opt + unroll
optimization.append(opt_loop, do_while=_opt_control)
post_optimization = common.generate_scheduling_post_opt(
sched = common.generate_scheduling_post_opt(
instruction_durations, scheduling_method, timing_constraints, inst_map
)
return FullPassManager(
Expand All @@ -228,5 +228,5 @@ def _opt_control(property_set):
translation=translation,
pre_optimization=pre_optimization,
optimization=optimization,
post_optimization=post_optimization,
scheduling=sched,
)

0 comments on commit f177d5f

Please sign in to comment.