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

Raise error eagerly on bad unitary synthesis method #11367

Merged
merged 6 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
16 changes: 8 additions & 8 deletions qiskit/transpiler/passes/synthesis/unitary_synthesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,11 @@ def __init__(
target: The optional :class:`~.Target` for the target device the pass
is compiling for. If specified this will supersede the values
set for ``basis_gates``, ``coupling_map``, and ``backend_props``.

Raises:
TranspilerError: if ``method`` was specified but is not found in the
installed plugins list. The list of installed plugins can be queried with
:func:`~qiskit.transpiler.passes.synthesis.plugin.unitary_synthesis_plugin_names`
"""
super().__init__()
self._basis_gates = set(basis_gates or ())
Expand Down Expand Up @@ -358,6 +363,9 @@ def __init__(

self._synth_gates = set(self._synth_gates) - self._basis_gates

if self.method != "default" and self.method not in self.plugins.ext_plugins:
raise TranspilerError("Specified methodd: %s not found in plugin list" % self.method)

def run(self, dag: DAGCircuit) -> DAGCircuit:
"""Run the UnitarySynthesis pass on ``dag``.

Expand All @@ -366,15 +374,7 @@ def run(self, dag: DAGCircuit) -> DAGCircuit:

Returns:
Output dag with UnitaryGates synthesized to target basis.

Raises:
TranspilerError: if ``method`` was specified for the class and is not
found in the installed plugins list. The list of installed
plugins can be queried with
:func:`~qiskit.transpiler.passes.synthesis.plugin.unitary_synthesis_plugin_names`
"""
if self.method != "default" and self.method not in self.plugins.ext_plugins:
raise TranspilerError("Specified method: %s not found in plugin list" % self.method)

# If there aren't any gates to synthesize in the circuit we can skip all the iteration
# and just return.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
fixes:
- |
fixes issue #11355. If a nonexistent synthesis plugin is passed, `generate_preset_pass_manager` now raises an error
the pass manager is created, not when it is run.
14 changes: 14 additions & 0 deletions test/python/transpiler/test_stage_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from qiskit.compiler.transpiler import transpile
from qiskit.test import QiskitTestCase
from qiskit.transpiler import PassManager, PassManagerConfig, CouplingMap
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
from qiskit.transpiler.preset_passmanagers.builtin_plugins import BasicSwapPassManager
from qiskit.transpiler.preset_passmanagers.plugin import (
PassManagerStagePluginManager,
Expand Down Expand Up @@ -113,3 +114,16 @@ def test_routing_plugins(self, optimization_level, routing_method):
backend = QasmSimulatorPy()
counts = backend.run(tqc, shots=1000).result().get_counts()
self.assertDictAlmostEqual(counts, {"0000": 500, "1111": 500}, delta=100)

@combine(
optimization_level=list(range(4)),
)
def test_unitary_synthesis_plugins(self, optimization_level):
"""Test unitary synthesis plugins"""
backend = QasmSimulatorPy()
with self.assertRaises(TranspilerError):
_ = generate_preset_pass_manager(
optimization_level=optimization_level,
backend=backend,
unitary_synthesis_method="not a method",
)