Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new transpiler exception class for too many qubits #11241

Merged
merged 4 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions qiskit/compiler/transpiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from qiskit.pulse import Schedule, InstructionScheduleMap
from qiskit.transpiler import Layout, CouplingMap, PropertySet
from qiskit.transpiler.basepasses import BasePass
from qiskit.transpiler.exceptions import TranspilerError
from qiskit.transpiler.exceptions import TranspilerError, CircuitTooWideForTarget
from qiskit.transpiler.instruction_durations import InstructionDurations, InstructionDurationsType
from qiskit.transpiler.passes.synthesis.high_level_synthesis import HLSConfig
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
Expand Down Expand Up @@ -455,7 +455,7 @@ def _check_circuits_coupling_map(circuits, cmap, backend):
# If coupling_map is not None or num_qubits == 1
num_qubits = len(circuit.qubits)
if max_qubits is not None and (num_qubits > max_qubits):
raise TranspilerError(
raise CircuitTooWideForTarget(
f"Number of qubits ({num_qubits}) in {circuit.name} "
f"is greater than maximum ({max_qubits}) in the coupling_map"
)
Expand Down
10 changes: 9 additions & 1 deletion qiskit/transpiler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,8 @@
.. autoexception:: TranspilerAccessError
.. autoexception:: CouplingError
.. autoexception:: LayoutError
.. autoexception:: CircuitTooWideForTarget

"""

# For backward compatibility
Expand All @@ -1263,7 +1265,13 @@
from .passmanager import PassManager, StagedPassManager
from .passmanager_config import PassManagerConfig
from .propertyset import PropertySet # pylint: disable=no-name-in-module
from .exceptions import TranspilerError, TranspilerAccessError, CouplingError, LayoutError
from .exceptions import (
TranspilerError,
TranspilerAccessError,
CouplingError,
LayoutError,
CircuitTooWideForTarget,
)
from .fencedobjs import FencedDAGCircuit, FencedPropertySet
from .basepasses import AnalysisPass, TransformationPass
from .coupling import CouplingMap
Expand Down
4 changes: 4 additions & 0 deletions qiskit/transpiler/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,7 @@ def __init__(self, *msg):
def __str__(self):
"""Return the message."""
return repr(self.msg)


class CircuitTooWideForTarget(TranspilerError):
"""Error raised if the circuit is too wide for the target."""
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
features:
- |
Added a new exception class :exc:`.CircuitToWideForTarget` which
subclasses :exc:`.TranspilerError`. It's used in places where a
:exc:`.TranspilerError` was previously raised when the error was that
the number of circuit qubits was larger than the target backend's qubits.
The new class enables more differentiating between this error condition and
other :exc:`.TranspilerError`\s.
4 changes: 2 additions & 2 deletions test/python/compiler/test_transpiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
from qiskit.test import QiskitTestCase, slow_test
from qiskit.tools import parallel
from qiskit.transpiler import CouplingMap, Layout, PassManager, TransformationPass
from qiskit.transpiler.exceptions import TranspilerError
from qiskit.transpiler.exceptions import TranspilerError, CircuitTooWideForTarget
from qiskit.transpiler.passes import BarrierBeforeFinalMeasurements, GateDirection, VF2PostLayout
from qiskit.transpiler.passmanager_config import PassManagerConfig
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager, level_0_pass_manager
Expand Down Expand Up @@ -987,7 +987,7 @@ def test_check_circuit_width(self):

qc = QuantumCircuit(15, 15)

with self.assertRaises(TranspilerError):
with self.assertRaises(CircuitTooWideForTarget):
transpile(qc, coupling_map=cmap)

@data(0, 1, 2, 3)
Expand Down