diff --git a/src/mqt/core/__init__.py b/src/mqt/core/__init__.py index f58aafc04..8c1510442 100644 --- a/src/mqt/core/__init__.py +++ b/src/mqt/core/__init__.py @@ -35,8 +35,6 @@ def load(input_circuit: QuantumComputation | str | os.PathLike[str] | QuantumCir The :class:`~mqt.core.ir.QuantumComputation`. Raises: - ValueError: If the input circuit is a Qiskit :class:`~qiskit.circuit.QuantumCircuit`, - but the `qiskit` extra is not installed. FileNotFoundError: If the input circuit is a file name and the file does not exist. """ if isinstance(input_circuit, QuantumComputation): @@ -54,11 +52,8 @@ def load(input_circuit: QuantumComputation | str | os.PathLike[str] | QuantumCir return QuantumComputation(input_str) - try: - from .plugins.qiskit import qiskit_to_mqt - except ImportError: - msg = "Qiskit is not installed. Please install `mqt.core[qiskit]` to use Qiskit circuits as input." - raise ValueError(msg) from None + # At this point, we know that the input is a Qiskit QuantumCircuit + from .plugins.qiskit import qiskit_to_mqt return qiskit_to_mqt(input_circuit) diff --git a/src/mqt/core/plugins/qiskit.py b/src/mqt/core/plugins/qiskit.py index 01edf9ff6..a23730592 100644 --- a/src/mqt/core/plugins/qiskit.py +++ b/src/mqt/core/plugins/qiskit.py @@ -13,7 +13,7 @@ import warnings from typing import TYPE_CHECKING, cast -from qiskit.circuit import AncillaQubit, AncillaRegister, Clbit, Instruction, ParameterExpression, Qubit +from qiskit.circuit import AncillaQubit, AncillaRegister, Clbit, Qubit from ..ir import QuantumComputation from ..ir.operations import ( @@ -29,7 +29,7 @@ if TYPE_CHECKING: from collections.abc import Mapping, Sequence - from qiskit.circuit import QuantumCircuit + from qiskit.circuit import Instruction, ParameterExpression, QuantumCircuit def qiskit_to_mqt(circ: QuantumCircuit) -> QuantumComputation: diff --git a/test/python/test_load.py b/test/python/test_load.py index a151aa545..a6c406b10 100644 --- a/test/python/test_load.py +++ b/test/python/test_load.py @@ -9,12 +9,8 @@ from __future__ import annotations -import sys from pathlib import Path -import pytest -from qiskit import QuantumCircuit, qasm2 - from mqt.core import load from mqt.core.ir import QuantumComputation @@ -92,11 +88,14 @@ def test_loading_nonexistent_file() -> None: def test_loading_qiskit_circuit() -> None: """Test whether importing a Qiskit circuit works.""" + from qiskit import QuantumCircuit + from qiskit.qasm2 import dumps + qiskit_circuit = QuantumCircuit(2, 2) qiskit_circuit.h(0) qiskit_circuit.cx(0, 1) qiskit_circuit.measure(range(2), range(2)) - qasm = qasm2.dumps(qiskit_circuit) + qasm = dumps(qiskit_circuit) # load the circuit qc = load(qiskit_circuit) @@ -110,14 +109,6 @@ def test_loading_qiskit_circuit() -> None: assert "".join(qasm.split()) in "".join(qc_qasm.split()) -def test_qiskit_import_error(monkeypatch: pytest.MonkeyPatch) -> None: - """Test that trying to import a Qiskit circuit without the `qiskit` extra raises an error.""" - monkeypatch.setitem(sys.modules, "mqt.core.plugins.qiskit", None) - - with pytest.raises(ValueError, match="Qiskit is not installed"): - load(QuantumCircuit()) - - def test_loading_qasm2_string() -> None: """Test whether importing a QASM2 string works.""" qasm = 'OPENQASM 2.0;\ninclude "qelib1.inc";\nqreg q[2];\ncreg c[2];\nh q[0];\ncx q[0], q[1];\nmeasure q -> c;\n' diff --git a/test/python/test_qiskit.py b/test/python/test_qiskit.py index 357ecb36d..4e8cce2dd 100644 --- a/test/python/test_qiskit.py +++ b/test/python/test_qiskit.py @@ -12,8 +12,8 @@ from typing import cast import pytest -from qiskit import QuantumCircuit, transpile -from qiskit.circuit import AncillaRegister, ClassicalRegister, Parameter, QuantumRegister +from qiskit import transpile +from qiskit.circuit import AncillaRegister, ClassicalRegister, Parameter, QuantumCircuit, QuantumRegister from qiskit.circuit.library import U2Gate, XXMinusYYGate, XXPlusYYGate from qiskit.providers.fake_provider import GenericBackendV2