|
105 | 105 |
|
106 | 106 | .. code-block:: python
|
107 | 107 |
|
108 |
| - from qiskit.circuit.library import XGate, HGate, RXGate, PhaseGate, TGate, TdgGate |
| 108 | + import numpy as np |
| 109 | + from qiskit.circuit.library import HGate, PhaseGate, RXGate, TdgGate, TGate, XGate |
109 | 110 | from qiskit.transpiler import PassManager
|
110 |
| - from qiskit.transpiler.passes import ALAPScheduleAnalysis, PadDynamicalDecoupling |
111 |
| - from qiskit.transpiler.passes import CXCancellation, InverseCancellation |
| 111 | + from qiskit.transpiler.passes import ( |
| 112 | + ALAPScheduleAnalysis, |
| 113 | + CXCancellation, |
| 114 | + InverseCancellation, |
| 115 | + PadDynamicalDecoupling, |
| 116 | + ) |
112 | 117 |
|
113 |
| - backend_durations = backend.target.durations() |
114 | 118 | dd_sequence = [XGate(), XGate()]
|
115 |
| - scheduling_pm = PassManager([ |
116 |
| - ALAPScheduleAnalysis(backend_durations), |
117 |
| - PadDynamicalDecoupling(backend_durations, dd_sequence), |
118 |
| - ]) |
| 119 | + scheduling_pm = PassManager( |
| 120 | + [ |
| 121 | + ALAPScheduleAnalysis(target=backend.target), |
| 122 | + PadDynamicalDecoupling(target=backend.target, dd_sequence=dd_sequence), |
| 123 | + ] |
| 124 | + ) |
119 | 125 | inverse_gate_list = [
|
120 | 126 | HGate(),
|
121 | 127 | (RXGate(np.pi / 4), RXGate(-np.pi / 4)),
|
122 | 128 | (PhaseGate(np.pi / 4), PhaseGate(-np.pi / 4)),
|
123 | 129 | (TGate(), TdgGate()),
|
124 |
| -
|
125 |
| - ]) |
126 |
| - logical_opt = PassManager([ |
127 |
| - CXCancellation(), |
128 |
| - InverseCancellation([HGate(), (RXGate(np.pi / 4), RXGate(-np.pi / 4)) |
129 |
| - ]) |
| 130 | + ] |
| 131 | + logical_opt = PassManager( |
| 132 | + [ |
| 133 | + CXCancellation(), |
| 134 | + InverseCancellation(inverse_gate_list), |
| 135 | + ] |
| 136 | + ) |
130 | 137 |
|
131 | 138 |
|
132 | 139 | # Add pre-layout stage to run extra logical optimization
|
133 | 140 | pass_manager.pre_layout = logical_opt
|
134 | 141 | # Set scheduling stage to custom pass manager
|
135 | 142 | pass_manager.scheduling = scheduling_pm
|
136 | 143 |
|
137 |
| -
|
138 |
| -Then when :meth:`~.StagedPassManager.run` is called on ``pass_manager`` the |
139 |
| -``logical_opt`` :class:`~.PassManager` will be called prior to the ``layout`` stage |
140 |
| -and for the ``scheduling`` stage our custom :class:`~.PassManager` |
141 |
| -``scheduling_pm`` will be used. |
| 144 | +Now, when the staged pass manager is run via the :meth:`~.StagedPassManager.run` method, |
| 145 | +the ``logical_opt`` pass manager will be called before the ``layout`` stage, and the |
| 146 | +``scheduling_pm`` pass manager will be used for the ``scheduling`` stage instead of the default. |
142 | 147 |
|
143 | 148 | Custom Pass Managers
|
144 | 149 | ====================
|
|
0 commit comments