Skip to content

Commit

Permalink
Move generate_preset_pass_manager to a standalone file (Qiskit#12762)
Browse files Browse the repository at this point in the history
* Move generate_preset_pass_manager to generate_preset_pass_manager.py

* Add top-level import and reno

* Apply suggestions from Matt's code review

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

* Add import path from qiskit.transpiler too

* Fix cyclic import issue

* Fix cyclic import issue in tools/pgo_scripts

* Address cyclic import issues. Reorder imports alphabetically when relevant.

* Fix docstring issue

* Update releasenotes/notes/add-generate-preset-pm-global-import-efb12f185f3f738b.yaml

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

---------

Co-authored-by: Matthew Treinish <[email protected]>
  • Loading branch information
ElePT and mtreinish committed Jul 24, 2024
1 parent 38e466b commit a46208c
Show file tree
Hide file tree
Showing 27 changed files with 549 additions and 527 deletions.
3 changes: 2 additions & 1 deletion qiskit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
_config = _user_config.get_config()

from qiskit.compiler import transpile, assemble, schedule, sequence

from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
from .version import __version__

__all__ = [
Expand All @@ -115,4 +115,5 @@
"schedule",
"sequence",
"transpile",
"generate_preset_pass_manager",
]
2 changes: 1 addition & 1 deletion qiskit/compiler/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from qiskit.exceptions import QiskitError
from qiskit.pulse import InstructionScheduleMap, Schedule
from qiskit.providers.backend import Backend
from qiskit.scheduler import ScheduleConfig
from qiskit.scheduler.config import ScheduleConfig
from qiskit.scheduler.schedule_circuit import schedule_circuit
from qiskit.utils.parallel import parallel_map

Expand Down
1 change: 1 addition & 0 deletions qiskit/transpiler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,7 @@
from .coupling import CouplingMap
from .layout import Layout, TranspileLayout
from .instruction_durations import InstructionDurations
from .preset_passmanagers import generate_preset_pass_manager
from .target import Target
from .target import InstructionProperties
from .target import QubitProperties
3 changes: 1 addition & 2 deletions qiskit/transpiler/instruction_durations.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
from typing import Optional, List, Tuple, Union, Iterable

import qiskit.circuit
from qiskit.circuit import Barrier, Delay
from qiskit.circuit import Instruction, ParameterExpression
from qiskit.circuit import Barrier, Delay, Instruction, ParameterExpression
from qiskit.circuit.duration import duration_in_dt
from qiskit.providers import Backend
from qiskit.transpiler.exceptions import TranspilerError
Expand Down
8 changes: 3 additions & 5 deletions qiskit/transpiler/passes/basis/translate_parameterized.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@
from __future__ import annotations

from qiskit.circuit import Instruction, ParameterExpression, Qubit, Clbit
from qiskit.circuit.equivalence_library import EquivalenceLibrary
from qiskit.converters import circuit_to_dag
from qiskit.dagcircuit import DAGCircuit, DAGOpNode
from qiskit.circuit.equivalence_library import EquivalenceLibrary
from qiskit.exceptions import QiskitError
from qiskit.transpiler import Target

from qiskit.transpiler.basepasses import TransformationPass

from .basis_translator import BasisTranslator
from qiskit.transpiler.passes.basis.basis_translator import BasisTranslator
from qiskit.transpiler.target import Target


class TranslateParameterizedGates(TransformationPass):
Expand Down
6 changes: 3 additions & 3 deletions qiskit/transpiler/passes/calibration/rx_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
import numpy as np

from qiskit.circuit import Instruction
from qiskit.circuit.library.standard_gates import RXGate
from qiskit.exceptions import QiskitError
from qiskit.pulse import Schedule, ScheduleBlock, builder, ScalableSymbolicPulse
from qiskit.pulse.channels import Channel
from qiskit.pulse.library.symbolic_pulses import Drag
from qiskit.transpiler.passes.calibration.base_builder import CalibrationBuilder
from qiskit.transpiler import Target
from qiskit.circuit.library.standard_gates import RXGate
from qiskit.exceptions import QiskitError
from qiskit.transpiler.target import Target


class RXCalibrationBuilder(CalibrationBuilder):
Expand Down
5 changes: 4 additions & 1 deletion qiskit/transpiler/passes/layout/sabre_pre_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@

import itertools

from qiskit.transpiler import CouplingMap, Target, AnalysisPass, TranspilerError
from qiskit.transpiler.basepasses import AnalysisPass
from qiskit.transpiler.coupling import CouplingMap
from qiskit.transpiler.exceptions import TranspilerError
from qiskit.transpiler.passes.layout.vf2_layout import VF2Layout
from qiskit.transpiler.target import Target
from qiskit._accelerate.error_map import ErrorMap


Expand Down
4 changes: 2 additions & 2 deletions qiskit/transpiler/passes/layout/set_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
# that they have been altered from the originals.

"""Set the ``layout`` property to the given layout."""
from qiskit.transpiler import Layout
from qiskit.transpiler.exceptions import InvalidLayoutError
from qiskit.transpiler.basepasses import AnalysisPass
from qiskit.transpiler.exceptions import InvalidLayoutError
from qiskit.transpiler.layout import Layout


class SetLayout(AnalysisPass):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
from qiskit.circuit import Gate, QuantumCircuit, Qubit
from qiskit.converters import circuit_to_dag
from qiskit.dagcircuit import DAGCircuit, DAGOpNode
from qiskit.transpiler import TransformationPass, Layout, TranspilerError

from qiskit.transpiler.basepasses import TransformationPass
from qiskit.transpiler.exceptions import TranspilerError
from qiskit.transpiler.layout import Layout
from qiskit.transpiler.passes.routing.commuting_2q_gate_routing.swap_strategy import SwapStrategy
from qiskit.transpiler.passes.routing.commuting_2q_gate_routing.commuting_2q_block import (
Commuting2qBlock,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import numpy as np

from qiskit.exceptions import QiskitError
from qiskit.transpiler import CouplingMap
from qiskit.transpiler.coupling import CouplingMap


class SwapStrategy:
Expand Down
3 changes: 2 additions & 1 deletion qiskit/transpiler/passes/routing/layout_transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@

import numpy as np

from qiskit.transpiler import Layout, CouplingMap
from qiskit.transpiler.basepasses import TransformationPass
from qiskit.transpiler.coupling import CouplingMap
from qiskit.transpiler.exceptions import TranspilerError
from qiskit.transpiler.layout import Layout
from qiskit.transpiler.passes.routing.algorithms import ApproximateTokenSwapper
from qiskit.transpiler.target import Target

Expand Down
4 changes: 2 additions & 2 deletions qiskit/transpiler/passes/routing/star_prerouting.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
from math import floor, log10

from qiskit.circuit import Barrier
from qiskit.circuit.library import SwapGate
from qiskit.dagcircuit import DAGOpNode, DAGDepNode, DAGDependency, DAGCircuit
from qiskit.transpiler import Layout
from qiskit.transpiler.basepasses import TransformationPass
from qiskit.circuit.library import SwapGate
from qiskit.transpiler.layout import Layout


class StarBlock:
Expand Down
3 changes: 1 addition & 2 deletions qiskit/transpiler/passes/scheduling/alap.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
from qiskit.circuit import Delay, Qubit, Measure
from qiskit.dagcircuit import DAGCircuit
from qiskit.transpiler.exceptions import TranspilerError
from qiskit.transpiler.passes.scheduling.base_scheduler import BaseSchedulerTransform
from qiskit.utils.deprecation import deprecate_func

from .base_scheduler import BaseSchedulerTransform


class ALAPSchedule(BaseSchedulerTransform):
"""ALAP Scheduling pass, which schedules the **stop** time of instructions as late as possible.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from qiskit.circuit.delay import Delay
from qiskit.dagcircuit import DAGCircuit
from qiskit.transpiler.basepasses import AnalysisPass
from qiskit.transpiler import Target
from qiskit.transpiler.target import Target


class InstructionDurationCheck(AnalysisPass):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from qiskit.pulse import Play
from qiskit.transpiler.basepasses import AnalysisPass
from qiskit.transpiler.exceptions import TranspilerError
from qiskit.transpiler import Target
from qiskit.transpiler.target import Target


class ValidatePulseGates(AnalysisPass):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from qiskit.dagcircuit import DAGCircuit, DAGOpNode, DAGOutNode
from qiskit.transpiler.basepasses import AnalysisPass
from qiskit.transpiler.exceptions import TranspilerError
from qiskit.transpiler import Target
from qiskit.transpiler.target import Target


class ConstrainedReschedule(AnalysisPass):
Expand Down
3 changes: 1 addition & 2 deletions qiskit/transpiler/passes/scheduling/asap.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
from qiskit.circuit import Delay, Qubit, Measure
from qiskit.dagcircuit import DAGCircuit
from qiskit.transpiler.exceptions import TranspilerError
from qiskit.transpiler.passes.scheduling.base_scheduler import BaseSchedulerTransform
from qiskit.utils.deprecation import deprecate_func

from .base_scheduler import BaseSchedulerTransform


class ASAPSchedule(BaseSchedulerTransform):
"""ASAP Scheduling pass, which schedules the start time of instructions as early as possible..
Expand Down
8 changes: 4 additions & 4 deletions qiskit/transpiler/passes/scheduling/base_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
"""Base circuit scheduling pass."""
import warnings

from qiskit.transpiler import InstructionDurations
from qiskit.transpiler.basepasses import TransformationPass
from qiskit.transpiler.passes.scheduling.time_unit_conversion import TimeUnitConversion
from qiskit.dagcircuit import DAGOpNode, DAGCircuit, DAGOutNode
from qiskit.circuit import Delay, Gate, Measure, Reset
from qiskit.circuit.parameterexpression import ParameterExpression
from qiskit.dagcircuit import DAGOpNode, DAGCircuit, DAGOutNode
from qiskit.transpiler.basepasses import TransformationPass
from qiskit.transpiler.exceptions import TranspilerError
from qiskit.transpiler.instruction_durations import InstructionDurations
from qiskit.transpiler.passes.scheduling.time_unit_conversion import TimeUnitConversion
from qiskit.transpiler.target import Target


Expand Down
4 changes: 2 additions & 2 deletions qiskit/transpiler/passes/scheduling/dynamical_decoupling.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
from qiskit.dagcircuit import DAGOpNode, DAGInNode
from qiskit.quantum_info.operators.predicates import matrix_equal
from qiskit.synthesis.one_qubit import OneQubitEulerDecomposer
from qiskit.transpiler import InstructionDurations
from qiskit.transpiler.passes.optimization import Optimize1qGates
from qiskit.transpiler.basepasses import TransformationPass
from qiskit.transpiler.exceptions import TranspilerError
from qiskit.transpiler.instruction_durations import InstructionDurations
from qiskit.transpiler.passes.optimization import Optimize1qGates
from qiskit.utils.deprecation import deprecate_func


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
from qiskit.transpiler.exceptions import TranspilerError
from qiskit.transpiler.instruction_durations import InstructionDurations
from qiskit.transpiler.passes.optimization import Optimize1qGates
from qiskit.transpiler.passes.scheduling.padding.base_padding import BasePadding
from qiskit.transpiler.target import Target

from .base_padding import BasePadding

logger = logging.getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@

import warnings

from qiskit.transpiler import InstructionDurations
from qiskit.transpiler.basepasses import AnalysisPass
from qiskit.transpiler.passes.scheduling.time_unit_conversion import TimeUnitConversion
from qiskit.dagcircuit import DAGOpNode, DAGCircuit
from qiskit.circuit import Delay, Gate
from qiskit.circuit.parameterexpression import ParameterExpression
from qiskit.dagcircuit import DAGOpNode, DAGCircuit
from qiskit.transpiler.basepasses import AnalysisPass
from qiskit.transpiler.exceptions import TranspilerError
from qiskit.transpiler.instruction_durations import InstructionDurations
from qiskit.transpiler.passes.scheduling.time_unit_conversion import TimeUnitConversion
from qiskit.transpiler.target import Target


Expand Down
35 changes: 18 additions & 17 deletions qiskit/transpiler/passes/synthesis/unitary_synthesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,9 @@
from functools import partial
import numpy as np

from qiskit.converters import circuit_to_dag, dag_to_circuit
from qiskit.transpiler import CouplingMap, Target
from qiskit.transpiler.basepasses import TransformationPass
from qiskit.transpiler.exceptions import TranspilerError
from qiskit.dagcircuit.dagcircuit import DAGCircuit, DAGOpNode
from qiskit.synthesis.one_qubit import one_qubit_decompose
from qiskit.transpiler.passes.optimization.optimize_1q_decomposition import _possible_decomposers
from qiskit.synthesis.two_qubit.xx_decompose import XXDecomposer, XXEmbodiments
from qiskit.synthesis.two_qubit.two_qubit_decompose import (
TwoQubitBasisDecomposer,
TwoQubitWeylDecomposition,
)
from qiskit.quantum_info import Operator
from qiskit.circuit.controlflow import CONTROL_FLOW_OP_NAMES
from qiskit.circuit import Gate, Parameter, CircuitInstruction
from qiskit.circuit.library.standard_gates import get_standard_gate_name_mapping
from qiskit.circuit.library.standard_gates import (
iSwapGate,
CXGate,
Expand All @@ -62,13 +50,26 @@
RYGate,
RGate,
)
from qiskit.transpiler.passes.synthesis import plugin
from qiskit.converters import circuit_to_dag, dag_to_circuit
from qiskit.dagcircuit.dagcircuit import DAGCircuit, DAGOpNode
from qiskit.exceptions import QiskitError
from qiskit.providers.models import BackendProperties
from qiskit.quantum_info import Operator
from qiskit.synthesis.one_qubit import one_qubit_decompose
from qiskit.synthesis.two_qubit.xx_decompose import XXDecomposer, XXEmbodiments
from qiskit.synthesis.two_qubit.two_qubit_decompose import (
TwoQubitBasisDecomposer,
TwoQubitWeylDecomposition,
)
from qiskit.transpiler.basepasses import TransformationPass
from qiskit.transpiler.coupling import CouplingMap
from qiskit.transpiler.exceptions import TranspilerError
from qiskit.transpiler.passes.optimization.optimize_1q_decomposition import (
Optimize1qGatesDecomposition,
_possible_decomposers,
)
from qiskit.providers.models import BackendProperties
from qiskit.circuit.library.standard_gates import get_standard_gate_name_mapping
from qiskit.exceptions import QiskitError
from qiskit.transpiler.passes.synthesis import plugin
from qiskit.transpiler.target import Target


GATE_NAME_MAP = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
QuantumCircuit,
)
from qiskit.dagcircuit import DAGCircuit
from qiskit.transpiler import TransformationPass
from qiskit.transpiler.basepasses import TransformationPass


class ConvertConditionsToIfOps(TransformationPass):
Expand Down
Loading

0 comments on commit a46208c

Please sign in to comment.