more transpiler docs improvements (#11300)

* more transpiler docs improvements

* Update qiskit/transpiler/__init__.py

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>

* use double ticks and remove extra line of code

---------

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
This commit is contained in:
Kevin J. Sung 2023-11-27 13:00:45 -05:00 committed by GitHub
parent 89642bd1bd
commit d3b08adf69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 19 deletions

View File

@ -105,28 +105,35 @@ also add initial logical optimization prior to routing, you would do something l
.. 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
@ -134,11 +141,9 @@ also add initial logical optimization prior to routing, you would do something l
# 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
====================