diff --git a/qiskit_ibm_runtime/estimator.py b/qiskit_ibm_runtime/estimator.py index 1e4160332..622311b4b 100644 --- a/qiskit_ibm_runtime/estimator.py +++ b/qiskit_ibm_runtime/estimator.py @@ -16,7 +16,6 @@ import os from typing import Optional, Dict, Sequence, Any, Union import logging -import typing from qiskit.circuit import QuantumCircuit from qiskit.quantum_info.operators.base_operator import BaseOperator @@ -31,9 +30,6 @@ # pylint: disable=unused-import,cyclic-import from .session import Session -if typing.TYPE_CHECKING: - from qiskit.opflow import PauliSumOp - logger = logging.getLogger(__name__) @@ -118,7 +114,7 @@ def __init__( def run( # pylint: disable=arguments-differ self, circuits: QuantumCircuit | Sequence[QuantumCircuit], - observables: BaseOperator | PauliSumOp | Sequence[BaseOperator | PauliSumOp], + observables: BaseOperator | Sequence[BaseOperator], parameter_values: Sequence[float] | Sequence[Sequence[float]] | None = None, **kwargs: Any, ) -> RuntimeJob: @@ -154,7 +150,7 @@ def run( # pylint: disable=arguments-differ def _run( # pylint: disable=arguments-differ self, circuits: Sequence[QuantumCircuit], - observables: Sequence[BaseOperator | PauliSumOp], + observables: Sequence[BaseOperator], parameter_values: Sequence[Sequence[float]], **kwargs: Any, ) -> RuntimeJob: diff --git a/qiskit_ibm_runtime/fake_provider/fake_backend.py b/qiskit_ibm_runtime/fake_provider/fake_backend.py index 023d4beee..58b7ac19b 100644 --- a/qiskit_ibm_runtime/fake_provider/fake_backend.py +++ b/qiskit_ibm_runtime/fake_provider/fake_backend.py @@ -29,7 +29,6 @@ from qiskit import pulse from qiskit.exceptions import QiskitError from qiskit.utils import optionals as _optionals -from qiskit.providers import basicaer from qiskit.transpiler import Target from qiskit.providers import Options from qiskit.providers.backend_compat import convert_to_target @@ -39,6 +38,11 @@ decode_pulse_defaults, ) +try: + from qiskit.providers.basicaer import QasmSimulatorPy as BasicSimulator +except ImportError: + from qiskit.providers.basic_provider import BasicSimulator + class _Credentials: def __init__(self, token: str = "123456", url: str = "https://") -> None: @@ -128,7 +132,7 @@ def _setup_sim(self) -> None: self.set_options(noise_model=noise_model) else: - self.sim = basicaer.QasmSimulatorPy() + self.sim = BasicSimulator() def _get_conf_dict_from_json(self) -> dict: if not self.conf_filename: @@ -205,7 +209,7 @@ def _default_options(cls) -> Options: return AerSimulator._default_options() else: - return basicaer.QasmSimulatorPy._default_options() + return BasicSimulator._default_options() @property def dtm(self) -> float: @@ -304,12 +308,12 @@ def run(self, run_input, **options): # type: ignore This method runs circuit jobs (an individual or a list of QuantumCircuit ) and pulse jobs (an individual or a list of Schedule or ScheduleBlock) - using BasicAer or Aer simulator and returns a + using BasicAer simulator/ BasicSimulator or Aer simulator and returns a :class:`~qiskit.providers.Job` object. If qiskit-aer is installed, jobs will be run using AerSimulator with noise model of the fake backend. Otherwise, jobs will be run using - BasicAer simulator without noise. + BasicAer simulator/ BasicSimulator simulator without noise. Currently noisy simulation of a pulse job is not supported yet in FakeBackendV2. @@ -475,7 +479,7 @@ def _setup_sim(self) -> None: # it when run() is called self.set_options(noise_model=noise_model) else: - self.sim = basicaer.QasmSimulatorPy() + self.sim = BasicSimulator() def properties(self) -> BackendProperties: """Return backend properties""" @@ -536,7 +540,7 @@ def _default_options(cls) -> Options: return QasmSimulator._default_options() else: - return basicaer.QasmSimulatorPy._default_options() + return BasicSimulator._default_options() def run(self, run_input, **kwargs): # type: ignore """Main job in simulator""" diff --git a/qiskit_ibm_runtime/qpy/binary_io/circuits.py b/qiskit_ibm_runtime/qpy/binary_io/circuits.py index 11591e103..f51f48b7d 100644 --- a/qiskit_ibm_runtime/qpy/binary_io/circuits.py +++ b/qiskit_ibm_runtime/qpy/binary_io/circuits.py @@ -24,7 +24,6 @@ import numpy as np from qiskit import circuit as circuit_mod -from qiskit import extensions from qiskit.circuit import library, controlflow, CircuitInstruction, ControlFlowOp from qiskit.circuit.classical import expr from qiskit.circuit.classicalregister import ClassicalRegister, Clbit @@ -34,7 +33,6 @@ from qiskit.circuit.instruction import Instruction from qiskit.circuit.quantumcircuit import QuantumCircuit from qiskit.circuit.quantumregister import QuantumRegister, Qubit -from qiskit.extensions import quantum_initializer from qiskit.quantum_info.operators import SparsePauliOp from qiskit.synthesis import evolution as evo_synth from qiskit.transpiler.layout import Layout, TranspileLayout @@ -301,10 +299,6 @@ def _read_instruction( # type: ignore[no-untyped-def] gate_class = getattr(library, gate_name) elif hasattr(circuit_mod, gate_name): gate_class = getattr(circuit_mod, gate_name) - elif hasattr(extensions, gate_name): - gate_class = getattr(extensions, gate_name) - elif hasattr(quantum_initializer, gate_name): - gate_class = getattr(quantum_initializer, gate_name) elif hasattr(controlflow, gate_name): gate_class = getattr(controlflow, gate_name) else: @@ -626,8 +620,6 @@ def _write_instruction( # type: ignore[no-untyped-def] ( not hasattr(library, gate_class_name) and not hasattr(circuit_mod, gate_class_name) - and not hasattr(extensions, gate_class_name) - and not hasattr(quantum_initializer, gate_class_name) and not hasattr(controlflow, gate_class_name) ) or gate_class_name == "Gate" diff --git a/qiskit_ibm_runtime/transpiler/passes/scheduling/__init__.py b/qiskit_ibm_runtime/transpiler/passes/scheduling/__init__.py index e22b816d8..90308b73c 100644 --- a/qiskit_ibm_runtime/transpiler/passes/scheduling/__init__.py +++ b/qiskit_ibm_runtime/transpiler/passes/scheduling/__init__.py @@ -43,7 +43,6 @@ from qiskit_ibm_runtime.transpiler.passes.scheduling import PadDelay from qiskit_ibm_runtime.fake_provider import FakeJakarta - backend = FakeJakarta() # Temporary workaround for mock backends. For real backends this is not required. diff --git a/qiskit_ibm_runtime/transpiler/passes/scheduling/dynamical_decoupling.py b/qiskit_ibm_runtime/transpiler/passes/scheduling/dynamical_decoupling.py index 40c24d54c..b7406263a 100644 --- a/qiskit_ibm_runtime/transpiler/passes/scheduling/dynamical_decoupling.py +++ b/qiskit_ibm_runtime/transpiler/passes/scheduling/dynamical_decoupling.py @@ -23,12 +23,16 @@ from qiskit.circuit.reset import Reset from qiskit.dagcircuit import DAGCircuit, DAGNode, DAGInNode, DAGOpNode from qiskit.quantum_info.operators.predicates import matrix_equal -from qiskit.quantum_info.synthesis import OneQubitEulerDecomposer from qiskit.transpiler.exceptions import TranspilerError from qiskit.transpiler.instruction_durations import InstructionDurations from qiskit.transpiler.passes.optimization import Optimize1qGates from qiskit.transpiler import CouplingMap +try: + from qiskit.quantum_info.synthesis import OneQubitEulerDecomposer +except ImportError: + from qiskit.synthesis import OneQubitEulerDecomposer + from .block_base_padder import BlockBasePadder diff --git a/test/integration/test_options.py b/test/integration/test_options.py index 00db91774..89c90006e 100644 --- a/test/integration/test_options.py +++ b/test/integration/test_options.py @@ -13,12 +13,12 @@ """Tests for job functions using real runtime service.""" from qiskit import QuantumCircuit -from qiskit.providers.fake_provider import FakeManila from qiskit.circuit.library import RealAmplitudes from qiskit.quantum_info import SparsePauliOp from qiskit_aer.noise import NoiseModel from qiskit_ibm_runtime import Session, Sampler, Options, Estimator +from qiskit_ibm_runtime.fake_provider import FakeManila from qiskit_ibm_runtime.exceptions import RuntimeJobFailureError from ..ibm_test_case import IBMIntegrationTestCase diff --git a/test/unit/mock/fake_api_backend.py b/test/unit/mock/fake_api_backend.py index 6ad2e4f5c..75b06c9d0 100644 --- a/test/unit/mock/fake_api_backend.py +++ b/test/unit/mock/fake_api_backend.py @@ -15,7 +15,7 @@ from datetime import datetime as python_datetime from dataclasses import dataclass -from qiskit.providers.fake_provider import FakeLima +from qiskit_ibm_runtime.fake_provider import FakeLima @dataclass diff --git a/test/unit/test_backend.py b/test/unit/test_backend.py index bbf86631c..3eda26ed2 100644 --- a/test/unit/test_backend.py +++ b/test/unit/test_backend.py @@ -16,11 +16,10 @@ import warnings from qiskit import transpile, qasm3, QuantumCircuit -from qiskit.providers.fake_provider import FakeManila from qiskit.providers.models import BackendStatus from qiskit_ibm_runtime.exceptions import IBMBackendValueError - +from qiskit_ibm_runtime.fake_provider import FakeManila from qiskit_ibm_runtime.ibm_backend import IBMBackend from ..ibm_test_case import IBMTestCase diff --git a/test/unit/test_backend_retrieval.py b/test/unit/test_backend_retrieval.py index de809d096..0de18f164 100644 --- a/test/unit/test_backend_retrieval.py +++ b/test/unit/test_backend_retrieval.py @@ -15,7 +15,7 @@ import uuid from qiskit.providers.exceptions import QiskitBackendNotFoundError -from qiskit.providers.fake_provider import FakeLima +from qiskit_ibm_runtime.fake_provider import FakeLima from .mock.fake_runtime_service import FakeRuntimeService from .mock.fake_api_backend import FakeApiBackendSpecs diff --git a/test/unit/test_data_serialization.py b/test/unit/test_data_serialization.py index eaeaed192..72d5bf687 100644 --- a/test/unit/test_data_serialization.py +++ b/test/unit/test_data_serialization.py @@ -25,11 +25,11 @@ from qiskit.circuit import Parameter, QuantumCircuit from qiskit.circuit.library import EfficientSU2, CXGate, PhaseGate, U2Gate -from qiskit.providers.fake_provider import FakeNairobi from qiskit.quantum_info import SparsePauliOp, Pauli, Statevector from qiskit.result import Result from qiskit_aer.noise import NoiseModel from qiskit_ibm_runtime.utils import RuntimeEncoder, RuntimeDecoder +from qiskit_ibm_runtime.fake_provider import FakeNairobi from .mock.fake_runtime_client import CustomResultRuntimeJob from .mock.fake_runtime_service import FakeRuntimeService from ..ibm_test_case import IBMTestCase @@ -96,13 +96,6 @@ def test_coder_qc(self): def test_coder_operators(self): """Test runtime encoder and decoder for operators.""" - # filter warnings triggered by opflow imports - with warnings.catch_warnings(): - warnings.filterwarnings("ignore", category=DeprecationWarning) - from qiskit.opflow import PauliSumOp # pylint: disable=import-outside-toplevel - - deprecated_op = PauliSumOp(SparsePauliOp(Pauli("XYZX"), coeffs=[2])) - coeff_x = Parameter("x") coeff_y = coeff_x + 1 @@ -110,7 +103,6 @@ def test_coder_operators(self): SparsePauliOp(Pauli("XYZX"), coeffs=[2]), SparsePauliOp(Pauli("XYZX"), coeffs=[coeff_y]), SparsePauliOp(Pauli("XYZX"), coeffs=[1 + 2j]), - deprecated_op, ) for operator in subtests: diff --git a/test/unit/test_ibm_primitives.py b/test/unit/test_ibm_primitives.py index 9e73464d8..5850ff1b9 100644 --- a/test/unit/test_ibm_primitives.py +++ b/test/unit/test_ibm_primitives.py @@ -23,7 +23,7 @@ from qiskit.circuit import QuantumCircuit from qiskit.quantum_info import SparsePauliOp -from qiskit.providers.fake_provider import FakeManila +from qiskit_ibm_runtime.fake_provider import FakeManila from qiskit_ibm_runtime import ( Sampler, diff --git a/test/unit/test_options.py b/test/unit/test_options.py index 572bd0950..15eb86202 100644 --- a/test/unit/test_options.py +++ b/test/unit/test_options.py @@ -16,12 +16,13 @@ from ddt import data, ddt from qiskit.providers import BackendV1 -from qiskit.providers.fake_provider import FakeManila, FakeNairobiV2 + from qiskit.transpiler import CouplingMap from qiskit_aer.noise import NoiseModel from qiskit_ibm_runtime import Options, RuntimeOptions from qiskit_ibm_runtime.utils.qctrl import _warn_and_clean_options +from qiskit_ibm_runtime.fake_provider import FakeManila, FakeNairobiV2 from ..ibm_test_case import IBMTestCase from ..utils import dict_keys_equal, dict_paritally_equal, flat_dict_partially_equal diff --git a/test/unit/test_runtime_ws.py b/test/unit/test_runtime_ws.py index 27c3230c4..3dc232a1b 100644 --- a/test/unit/test_runtime_ws.py +++ b/test/unit/test_runtime_ws.py @@ -15,7 +15,6 @@ import time from unittest.mock import MagicMock -from qiskit.providers.fake_provider import FakeQasmSimulator from qiskit.quantum_info import SparsePauliOp from qiskit_ibm_runtime import ( RuntimeJob, @@ -235,7 +234,6 @@ def _get_job(self, callback=None, job_id=JOB_ID_PROGRESS_DONE, backend=None): params = ClientParameters( channel="ibm_quantum", token="my_token", url=MockWsServer.VALID_WS_URL ) - backend = backend or FakeQasmSimulator() job = RuntimeJob( backend=backend, api_client=BaseFakeRuntimeClient(), diff --git a/test/unit/test_session.py b/test/unit/test_session.py index fc62751e5..5e228acbb 100644 --- a/test/unit/test_session.py +++ b/test/unit/test_session.py @@ -17,8 +17,8 @@ from concurrent.futures import ThreadPoolExecutor, wait from unittest.mock import MagicMock, Mock, patch -from qiskit.providers.fake_provider import FakeManila +from qiskit_ibm_runtime.fake_provider import FakeManila from qiskit_ibm_runtime import Session from qiskit_ibm_runtime.ibm_backend import IBMBackend from qiskit_ibm_runtime.utils.default_session import _DEFAULT_SESSION diff --git a/test/unit/transpiler/passes/scheduling/control_flow_test_case.py b/test/unit/transpiler/passes/scheduling/control_flow_test_case.py deleted file mode 100644 index b64822883..000000000 --- a/test/unit/transpiler/passes/scheduling/control_flow_test_case.py +++ /dev/null @@ -1,36 +0,0 @@ -# This code is part of Qiskit. -# -# (C) Copyright IBM 2022, 2023. -# -# This code is licensed under the Apache License, Version 2.0. You may -# obtain a copy of this license in the LICENSE.txt file in the root directory -# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. -# -# Any modifications or derivative works of this code must retain this -# copyright notice, and modified files need to carry a notice indicating -# that they have been altered from the originals. - -"""Enhanced test case for control flow circuits.""" - -from typing import Any, Optional - -from qiskit import QuantumCircuit -from qiskit.test._canonical import canonicalize_control_flow - -from .....ibm_test_case import IBMTestCase - - -class ControlFlowTestCase(IBMTestCase): - """Test case that enforces control flow canonicalization of quantum circuits.""" - - def assertEqual( # pylint: disable=arguments-differ - self, first: Any, second: Any, msg: Optional[str] = None - ) -> None: - """Modify assertEqual to canonicalize the quantum circuit.""" - if isinstance(first, QuantumCircuit): - first = canonicalize_control_flow(first) - - if isinstance(second, QuantumCircuit): - second = canonicalize_control_flow(second) - - super().assertEqual(first, second, msg=msg) # pylint: disable=no-value-for-parameter diff --git a/test/unit/transpiler/passes/scheduling/test_dynamical_decoupling.py b/test/unit/transpiler/passes/scheduling/test_dynamical_decoupling.py index 145420478..df42b629b 100644 --- a/test/unit/transpiler/passes/scheduling/test_dynamical_decoupling.py +++ b/test/unit/transpiler/passes/scheduling/test_dynamical_decoupling.py @@ -35,13 +35,13 @@ DynamicCircuitInstructionDurations, ) -from .control_flow_test_case import ControlFlowTestCase +from .....ibm_test_case import IBMTestCase # pylint: disable=invalid-name,not-context-manager @ddt -class TestPadDynamicalDecoupling(ControlFlowTestCase): +class TestPadDynamicalDecoupling(IBMTestCase): """Tests PadDynamicalDecoupling pass.""" def setUp(self): diff --git a/test/unit/transpiler/passes/scheduling/test_scheduler.py b/test/unit/transpiler/passes/scheduling/test_scheduler.py index e9ed82e1f..3170a3e5f 100644 --- a/test/unit/transpiler/passes/scheduling/test_scheduler.py +++ b/test/unit/transpiler/passes/scheduling/test_scheduler.py @@ -15,12 +15,12 @@ from unittest.mock import patch from qiskit import ClassicalRegister, QuantumCircuit, QuantumRegister, transpile -from qiskit.providers.fake_provider import FakeJakarta from qiskit.pulse import Schedule, Play, Constant, DriveChannel from qiskit.transpiler.passes import ConvertConditionsToIfOps from qiskit.transpiler.passmanager import PassManager from qiskit.transpiler.exceptions import TranspilerError +from qiskit_ibm_runtime.fake_provider import FakeJakarta from qiskit_ibm_runtime.transpiler.passes.scheduling.pad_delay import PadDelay from qiskit_ibm_runtime.transpiler.passes.scheduling.scheduler import ( ALAPScheduleAnalysis, @@ -30,12 +30,12 @@ DynamicCircuitInstructionDurations, ) -from .control_flow_test_case import ControlFlowTestCase +from .....ibm_test_case import IBMTestCase # pylint: disable=invalid-name,not-context-manager -class TestASAPSchedulingAndPaddingPass(ControlFlowTestCase): +class TestASAPSchedulingAndPaddingPass(IBMTestCase): """Tests the ASAP Scheduling passes""" def test_if_test_gate_after_measure(self): @@ -808,7 +808,7 @@ def test_c_if_plugin_conversion_with_transpile(self): self.assertEqual(expected, scheduled) -class TestALAPSchedulingAndPaddingPass(ControlFlowTestCase): +class TestALAPSchedulingAndPaddingPass(IBMTestCase): """Tests the ALAP Scheduling passes""" def test_alap(self):