Skip to content
Merged
26 changes: 4 additions & 22 deletions qiskit/transpiler/passmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

"""Manager for a set of Passes and their scheduling during transpilation."""

import warnings
from typing import Union, List, Callable, Dict, Any

import dill
Expand All @@ -31,29 +30,15 @@ class PassManager:
def __init__(
self,
passes: Union[BasePass, List[BasePass]] = None,
max_iteration: int = 1000,
callback: Callable = None
):
max_iteration: int = 1000):
"""Initialize an empty `PassManager` object (with no passes scheduled).

Args:
passes: A pass set (as defined in :py:func:`qiskit.transpiler.PassManager.append`)
to be added to the pass manager schedule.
max_iteration: The maximum number of iterations the schedule will be looped if the
condition is not met.
callback: DEPRECATED - A callback function that will be called after each pass
execution.

.. deprecated:: 0.13.0
The ``callback`` parameter is deprecated in favor of
``PassManager.run(..., callback=callback, ...)``.
"""
self.callback = None

if callback:
warnings.warn("Setting a callback at construction time is being deprecated in favor of"
"PassManager.run(..., callback=callback,...)", DeprecationWarning, 2)
self.callback = callback
# the pass manager's schedule of passes, including any control-flow.
# Populated via PassManager.append().

Expand Down Expand Up @@ -148,7 +133,7 @@ def __len__(self):
return len(self._pass_sets)

def __getitem__(self, index):
new_passmanager = PassManager(max_iteration=self.max_iteration, callback=self.callback)
new_passmanager = PassManager(max_iteration=self.max_iteration)
_pass_sets = self._pass_sets[index]
if isinstance(_pass_sets, dict):
_pass_sets = [_pass_sets]
Expand All @@ -157,13 +142,12 @@ def __getitem__(self, index):

def __add__(self, other):
if isinstance(other, PassManager):
new_passmanager = PassManager(max_iteration=self.max_iteration, callback=self.callback)
new_passmanager = PassManager(max_iteration=self.max_iteration)
new_passmanager._pass_sets = self._pass_sets + other._pass_sets
return new_passmanager
else:
try:
new_passmanager = PassManager(max_iteration=self.max_iteration,
callback=self.callback)
new_passmanager = PassManager(max_iteration=self.max_iteration)
new_passmanager._pass_sets += self._pass_sets
new_passmanager.append(other)
return new_passmanager
Expand Down Expand Up @@ -283,8 +267,6 @@ def _run_single_circuit(
The transformed circuit.
"""
running_passmanager = self._create_running_passmanager()
if callback is None and self.callback: # TODO to remove with __init__(callback)
callback = self.callback
result = running_passmanager.run(circuit, output_name=output_name, callback=callback)
self.property_set = running_passmanager.property_set
return result
Expand Down
5 changes: 5 additions & 0 deletions releasenotes/notes/pm_cb_remove_5522-30358587a8db2701.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
upgrade:
- |
The parameter `callback` in :class:`~qiskit.transpiler.PassManager` class contruction is being removed.
The deprecation warning was released in 0.13 (April 2020) and now it is being fully dropped.