Skip to content

Commit 974ad78

Browse files
wshankseliarbel
andauthored
Prepare for Qiskit 2.0 by addressing removed classes and methods (#1526)
This change prepares for Qiskit 2.0 by guarding or replacing references to objects removed in Qiskit 2.0. ## Detailed list of changes: ### Compatibility changes: * Guard references to `BackendV1`. `BackendV1` was removed in Qiskit 2.0. There were only a few remaining references to `BackendV1` after the previous removal of pulse support, so it was not hard to keep the remaining support for now but it should be removed when Qiskit 1 is no longer supported. * Update usage of `qiskit.result.Result.header` to expect a dict (Qiskit 2) as well as a class (Qiskit 1). `ExperimentData` gets the circuit metadata from the header (by convention the metadata is copied into the result and `ExperimentData` relies on this). * Add classes `MeasLevel` and `MeasReturnType` to enumerate the expected measurement level (kerneled or classified) and return type (averaged or not). Previously, private classes of Qiskit were inadvertently used for these purposes but they were removed in Qiskit 2.0. * Remove null default `inst_map` transpile options from experiments. These should have been removed along with the rest of pulse support. * Update tests to use `GenericBackendV2` or a custom `BackendV2` in place of removed `FakeOpenPulse2Q` and `Fake5QV1` backends from Qiskit. * Remove suppression of Qiskit deprecation warnings from the tests. * Remove stray references to `ProviderV1` in tests. * Update the saved `QuantumVolume` results for Qiskit 2.0's change in the quantum volume algorithm. * Vendor deprecation decorators to prepare for their removal from Qiskit's public API (see [here](Qiskit/qiskit#11296 (review))). At first it appeared that these methods would be changed late in the Qiskit 2.0 cycle but the change was pushed back in time. Still the plan is to make the functions private, so we need to stop using them. ### Other changes * Provide a more specific warning in `LocalReadouMitigator` if it is used with a backend without a ``properties()`` method or with a backend that does not the required readout error properties. * Fix a performance issue in `QuantumVolume`. When Qiskit Aer is installed, `QuantumVolume` uses `AerSimulator` to simulate the outcomes of the quantum volume circuits to determine the heavy output probabilities. In its default instantiation, `AerSimulator` regenerates its `Target` every time it is accessed and this generation takes an appreciable amount of time. Because the target was being accessed separately for every circuit, this overhead could accumulate to over a minute in the standard 100 circuit experiment. This overhead was reduced by processing all the circuits in one pass. * Switch `FineFrequency` tests to use `T2HahnBackend` in place `MockIQBackend` since it provides a more realistic backend emulation. * Fix the `stacklevel` on the deprecation warning for `RestlessNode`. --------- Co-authored-by: Eli Arbel <arbel@il.ibm.com>
1 parent 00f2533 commit 974ad78

42 files changed

Lines changed: 743 additions & 257 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CONTRIBUTING.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,12 +424,11 @@ release notes.
424424

425425
#### Adding deprecation warnings
426426

427-
We use the deprecation wrappers in [Qiskit
428-
Utilities](https://docs.quantum.ibm.com/api/qiskit/utils) to add warnings:
427+
We use deprecation wrappers in `qiskit_experiments.framework.deprecation` to add warnings:
429428

430429
```python
431430

432-
from qiskit.utils.deprecation import deprecate_func
431+
from qiskit_experiments.framework.deprecation import deprecate_func
433432

434433
@deprecate_func(
435434
since="0.5",

docs/conf.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,12 @@ def setup(app):
211211
# Should come up with better way to address this
212212

213213
from qiskit_experiments.curve_analysis import ParameterRepr
214+
from qiskit_experiments.framework import MeasLevel, MeasReturnType
214215

215216

216217
def maybe_skip_member(app, what, name, obj, skip, options):
218+
if skip:
219+
return True
217220
skip_names = [
218221
"analysis",
219222
"set_run_options",
@@ -234,6 +237,11 @@ def maybe_skip_member(app, what, name, obj, skip, options):
234237
ParameterRepr.repr,
235238
ParameterRepr.unit,
236239
]
240+
if (
241+
not name.isupper() and
242+
(getattr(MeasLevel, name, None) == obj or getattr(MeasReturnType, name, None) == obj)
243+
):
244+
return True
237245
if not skip:
238246
return (name in skip_names or obj in skip_members) and what == "attribute"
239247
return skip

docs/manuals/characterization/t1.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ for qubit 0.
3737
.. jupyter-execute::
3838

3939
import numpy as np
40-
from qiskit.qobj.utils import MeasLevel
41-
from qiskit_experiments.framework import ParallelExperiment
40+
from qiskit_experiments.framework import MeasLevel, ParallelExperiment
4241
from qiskit_experiments.library import T1
4342
from qiskit_experiments.library.characterization.analysis.t1_analysis import T1KerneledAnalysis
4443

docs/tutorials/custom_experiment.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ perfect symmetrical results between :math:`|0000\rangle` and :math:`|1111\rangle
601601

602602
.. jupyter-execute::
603603

604-
expdata_ideal = exp.run(AerSimulator(), shots=shots)
604+
expdata_ideal = exp.run(backend_ideal, shots=shots)
605605
counts_ideal = expdata_ideal.analysis_results("counts").value
606606
print(counts_ideal)
607607

docs/tutorials/getting_started.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ supports can be set:
297297

298298
.. jupyter-execute::
299299

300-
from qiskit.qobj.utils import MeasLevel
300+
from qiskit_experiments.framework import MeasLevel
301301

302302
exp.set_run_options(shots=1000,
303303
meas_level=MeasLevel.CLASSIFIED)

qiskit_experiments/curve_analysis/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
import lmfit
2020
import numpy as np
2121
import pandas as pd
22-
from qiskit.utils.deprecation import deprecate_func
2322
from qiskit.utils import detach_prefix
2423
from uncertainties import UFloat, wrap as wrap_function
2524
from uncertainties import unumpy
2625

2726
from qiskit_experiments.curve_analysis.curve_data import CurveFitResult
2827
from qiskit_experiments.exceptions import AnalysisError, QiskitError
2928
from qiskit_experiments.framework import AnalysisResultData
29+
from qiskit_experiments.framework.deprecation import deprecate_func
3030

3131

3232
UNUMPY_FUNCS = {fn: getattr(unumpy, fn) for fn in unumpy.__all__}

qiskit_experiments/data_processing/mitigation/local_readout_mitigator.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616

1717
import math
18+
import warnings
1819
from typing import Optional, List, Tuple, Iterable, Callable, Union, Dict
1920
import numpy as np
2021

@@ -53,6 +54,8 @@ def __init__(
5354
Raises:
5455
QiskitError: matrices sizes do not agree with number of qubits
5556
"""
57+
if assignment_matrices is None and backend is None:
58+
raise QiskitError("Either assignment_matrices or backend must be provided.")
5659
if assignment_matrices is None:
5760
assignment_matrices = self._from_backend(backend, qubits)
5861
else:
@@ -293,7 +296,14 @@ def stddev_upper_bound(self, shots: int, qubits: List[int] = None):
293296

294297
def _from_backend(self, backend, qubits):
295298
"""Calculates amats from backend properties readout_error"""
296-
backend_qubits = backend.properties().qubits
299+
try:
300+
backend_qubits = backend.properties().qubits
301+
except AttributeError as exc:
302+
raise QiskitError(
303+
"Either assignment_matrices must be passed or a backend "
304+
"supporting backend.properties().qubits"
305+
) from exc
306+
297307
if qubits is not None:
298308
if any(qubit >= len(backend_qubits) for qubit in qubits):
299309
raise QiskitError("The chosen backend does not contain the specified qubits.")
@@ -304,13 +314,20 @@ def _from_backend(self, backend, qubits):
304314
amats = np.zeros([num_qubits, 2, 2], dtype=float)
305315

306316
for qubit_idx, qubit_prop in enumerate(backend_qubits):
317+
props_to_find = {"prob_meas0_prep1", "prob_meas1_prep0"}
307318
for prop in qubit_prop:
308319
if prop.name == "prob_meas0_prep1":
320+
props_to_find.discard(prop.name)
309321
(amats[qubit_idx])[0, 1] = prop.value
310322
(amats[qubit_idx])[1, 1] = 1 - prop.value
311323
if prop.name == "prob_meas1_prep0":
324+
props_to_find.discard(prop.name)
312325
(amats[qubit_idx])[1, 0] = prop.value
313326
(amats[qubit_idx])[0, 0] = 1 - prop.value
327+
if props_to_find:
328+
warnings.warn(
329+
f"Expected readout error properties were missing: {','.join(props_to_find)}"
330+
)
314331

315332
return amats
316333

qiskit_experiments/data_processing/nodes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from uncertainties import unumpy as unp, ufloat
2424

2525
from qiskit.result.postprocess import format_counts_memory
26-
from qiskit.utils import deprecate_func
26+
from qiskit_experiments.framework.deprecation import deprecate_func
2727
from qiskit_experiments.data_processing.data_action import DataAction, TrainableDataAction
2828
from qiskit_experiments.data_processing.exceptions import DataProcessorError
2929
from qiskit_experiments.data_processing.discriminator import BaseDiscriminator
@@ -921,6 +921,7 @@ class RestlessNode(DataAction, ABC):
921921
"processor on an experiment."
922922
),
923923
package_name="qiskit-experiments",
924+
stacklevel=3,
924925
)
925926
def __init__(
926927
self, validate: bool = True, memory_allocation: ShotOrder = ShotOrder.circuit_first

qiskit_experiments/data_processing/processor_library.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414

1515
import warnings
1616
from typing import Union, Optional, List
17-
from qiskit.qobj.utils import MeasLevel, MeasReturnType
1817

19-
from qiskit_experiments.framework import ExperimentData, Options
18+
from qiskit_experiments.framework import ExperimentData, MeasLevel, MeasReturnType, Options
2019
from qiskit_experiments.data_processing.exceptions import DataProcessorError
2120
from qiskit_experiments.data_processing.data_action import DataAction
2221
from qiskit_experiments.data_processing.data_processor import DataProcessor

qiskit_experiments/framework/__init__.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@
9999
Job
100100
BaseJob
101101
ExtendedJob
102+
MeasLevel
103+
MeasReturnType
102104
103105
.. _composite-experiment:
104106
@@ -145,6 +147,17 @@
145147
FigureData,
146148
FigureType,
147149
)
150+
from .provider_interfaces import (
151+
BaseJob,
152+
BaseProvider,
153+
ExtendedJob,
154+
IBMProvider,
155+
Job,
156+
MeasLevel,
157+
MeasReturnType,
158+
Provider,
159+
)
160+
148161
from .base_analysis import BaseAnalysis
149162
from .base_experiment import BaseExperiment
150163
from .backend_timing import BackendTiming
@@ -159,4 +172,3 @@
159172
CompositeAnalysis,
160173
)
161174
from .json import ExperimentEncoder, ExperimentDecoder
162-
from .provider_interfaces import BaseJob, BaseProvider, ExtendedJob, IBMProvider, Job, Provider

0 commit comments

Comments
 (0)