Skip to content

Commit

Permalink
more transpiler docs improvements (#11300) (#11329)
Browse files Browse the repository at this point in the history
* more transpiler docs improvements

* Update qiskit/transpiler/__init__.py

Co-authored-by: Matthew Treinish <[email protected]>

* use double ticks and remove extra line of code

---------

Co-authored-by: Matthew Treinish <[email protected]>
(cherry picked from commit d3b08ad)

Co-authored-by: Kevin J. Sung <[email protected]>
  • Loading branch information
mergify[bot] and kevinsung authored Nov 28, 2023
1 parent 68acb4d commit 13ed4ac
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions qiskit/transpiler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,40 +105,45 @@
.. code-block:: python
from qiskit.circuit.library import XGate, HGate, RXGate, PhaseGate, TGate, TdgGate
import numpy as np
from qiskit.circuit.library import HGate, PhaseGate, RXGate, TdgGate, TGate, XGate
from qiskit.transpiler import PassManager
from qiskit.transpiler.passes import ALAPScheduleAnalysis, PadDynamicalDecoupling
from qiskit.transpiler.passes import CXCancellation, InverseCancellation
from qiskit.transpiler.passes import (
ALAPScheduleAnalysis,
CXCancellation,
InverseCancellation,
PadDynamicalDecoupling,
)
backend_durations = backend.target.durations()
dd_sequence = [XGate(), XGate()]
scheduling_pm = PassManager([
ALAPScheduleAnalysis(backend_durations),
PadDynamicalDecoupling(backend_durations, dd_sequence),
])
scheduling_pm = PassManager(
[
ALAPScheduleAnalysis(target=backend.target),
PadDynamicalDecoupling(target=backend.target, dd_sequence=dd_sequence),
]
)
inverse_gate_list = [
HGate(),
(RXGate(np.pi / 4), RXGate(-np.pi / 4)),
(PhaseGate(np.pi / 4), PhaseGate(-np.pi / 4)),
(TGate(), TdgGate()),
])
logical_opt = PassManager([
CXCancellation(),
InverseCancellation([HGate(), (RXGate(np.pi / 4), RXGate(-np.pi / 4))
])
]
logical_opt = PassManager(
[
CXCancellation(),
InverseCancellation(inverse_gate_list),
]
)
# Add pre-layout stage to run extra logical optimization
pass_manager.pre_layout = logical_opt
# Set scheduling stage to custom pass manager
pass_manager.scheduling = scheduling_pm
Then when :meth:`~.StagedPassManager.run` is called on ``pass_manager`` the
``logical_opt`` :class:`~.PassManager` will be called prior to the ``layout`` stage
and for the ``scheduling`` stage our custom :class:`~.PassManager`
``scheduling_pm`` will be used.
Now, when the staged pass manager is run via the :meth:`~.StagedPassManager.run` method,
the ``logical_opt`` pass manager will be called before the ``layout`` stage, and the
``scheduling_pm`` pass manager will be used for the ``scheduling`` stage instead of the default.
Custom Pass Managers
====================
Expand Down

0 comments on commit 13ed4ac

Please sign in to comment.