Skip to content

Commit

Permalink
Handle Qiskit 1.0 removals (#1363)
Browse files Browse the repository at this point in the history
* Handle Qiskit 1.0 removals

* Remove removed qiskit modules

* add both qiskit synthesis imports

* fix docs build

* fix lint errors from 1.0.0RC1

* update basicaer import

* Update qiskit_ibm_runtime/fake_provider/fake_backend.py

Co-authored-by: Elena Peña Tapia <[email protected]>

* address comments

* Update imports & docstrings

---------

Co-authored-by: Elena Peña Tapia <[email protected]>
  • Loading branch information
kt474 and ElePT authored Feb 5, 2024
1 parent 7789fb3 commit f4d2853
Show file tree
Hide file tree
Showing 17 changed files with 33 additions and 84 deletions.
8 changes: 2 additions & 6 deletions qiskit_ibm_runtime/estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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__)


Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
18 changes: 11 additions & 7 deletions qiskit_ibm_runtime/fake_provider/fake_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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"""
Expand Down Expand Up @@ -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"""
Expand Down
8 changes: 0 additions & 8 deletions qiskit_ibm_runtime/qpy/binary_io/circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion test/integration/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/unit/mock/fake_api_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions test/unit/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/unit/test_backend_retrieval.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 1 addition & 9 deletions test/unit/test_data_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -96,21 +96,13 @@ 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

subtests = (
SparsePauliOp(Pauli("XYZX"), coeffs=[2]),
SparsePauliOp(Pauli("XYZX"), coeffs=[coeff_y]),
SparsePauliOp(Pauli("XYZX"), coeffs=[1 + 2j]),
deprecated_op,
)

for operator in subtests:
Expand Down
2 changes: 1 addition & 1 deletion test/unit/test_ibm_primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion test/unit/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions test/unit/test_runtime_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion test/unit/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 0 additions & 36 deletions test/unit/transpiler/passes/scheduling/control_flow_test_case.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions test/unit/transpiler/passes/scheduling/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit f4d2853

Please sign in to comment.