Skip to content

Commit

Permalink
Deprecate QuantumInstance and Opflow (Qiskit/qiskit#9176)
Browse files Browse the repository at this point in the history
* Deprecate QuantumInstance and Opflow

* Add .. deprecated:: to init modules

* Add link to url guide

* Remove internal use of opflow

* Fix black

* Discard old changes in deprecation.py

* Update decorators

* Remove  from docstring

* Update sphinx deprecations, fix lint, fix tests

* Remove hanging Deprecated in docstring

* Remove old Deprecation messages

* Revert "Remove old Deprecation messages"

This reverts commit 6924130e12ffdfde971ff1e25434ee84bf983482.

* Revert "Remove hanging Deprecated in docstring"

This reverts commit cfb04f50e6a30a33955b57be4ab5bbdb9035923c.

* Revert "Remove  from docstring"

This reverts commit 50e5954ecd4a729e7101e8ea4bf493240ae8b59e.

* Change Deprecation to Deprecated

* Remove catch warnings in main code

* Fix missing decorators

* Fix tests

* Shorten message

* Fix black

* Shorten qi message

* Remove checks for QDrift's internal use of opflow (changed in this PR)

* Add warning catchers to unit tests

* Remove opflow from qaoa ansatz tests

* Remove opflow from non-related tests

* Restore some opflow tests for completion

* Fix black

* Remove catch warnings

* Refactor adaptVQE tests, remove opflow from observables evaluator

* Fix tests, lint

Fix tests, lint

Fix CI failures

Fix tests CI

Fix unit tests

Fix CI again

Fix lint

Restore vqd test

Remove unused import

* Delete qobj test to fix CI until Qiskit/qiskit#9322 is merged

* Refactor gradients test warnings

* Remove warning filter

* Refactor rest of tests to assert warnings

* Fix formatting

* Restore unchanged unit tests

Restore opflow test case

Restore estimator test

Restore unchanged tests

* Go back to old opflow test setup

* Revert "Refactor gradients test warnings", only keep qi assertWarns

This reverts commit 9c0a37f3bc3068a9b1ccd122298cfefe556d4135.

* Restore opflow unittests

* Fix tests

* Fix lint

* Fix qaoa repeated test

* Add module deprecation warning

* Divide message in multiple lines

* Fix lint

* :mod:: -> :mod:

* Deprecate Z2 symmetries

---------

Co-authored-by: ElePT <epenatap@gmail.com>
Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>
Co-authored-by: woodsp-ibm <woodsp@us.ibm.com>
  • Loading branch information
4 people authored Apr 18, 2023
1 parent c7df5fe commit aa30930
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 20 deletions.
47 changes: 46 additions & 1 deletion qiskit_algorithms/utils/backend_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2018, 2021.
# (C) Copyright IBM 2018, 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
Expand All @@ -13,6 +13,7 @@
"""backend utility functions"""

import logging
from qiskit.utils.deprecation import deprecate_func

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -49,6 +50,10 @@ def _get_backend_provider(backend):
return provider


@deprecate_func(
since="0.24.0",
additional_msg="For code migration guidelines, visit https://qisk.it/qi_migration.",
)
def has_ibmq():
"""Check if IBMQ is installed."""
if not _PROVIDER_CHECK.checked_ibmq:
Expand All @@ -66,6 +71,10 @@ def has_ibmq():
return _PROVIDER_CHECK.has_ibmq


@deprecate_func(
since="0.24.0",
additional_msg="For code migration guidelines, visit https://qisk.it/qi_migration.",
)
def has_aer():
"""Check if Aer is installed."""
if not _PROVIDER_CHECK.checked_aer:
Expand All @@ -82,6 +91,10 @@ def has_aer():
return _PROVIDER_CHECK.has_aer


@deprecate_func(
since="0.24.0",
additional_msg="For code migration guidelines, visit https://qisk.it/qi_migration.",
)
def is_aer_provider(backend):
"""Detect whether or not backend is from Aer provider.
Expand All @@ -102,6 +115,10 @@ def is_aer_provider(backend):
return False


@deprecate_func(
since="0.24.0",
additional_msg="For code migration guidelines, visit https://qisk.it/qi_migration.",
)
def is_basicaer_provider(backend):
"""Detect whether or not backend is from BasicAer provider.
Expand All @@ -115,6 +132,10 @@ def is_basicaer_provider(backend):
return isinstance(_get_backend_provider(backend), BasicAerProvider)


@deprecate_func(
since="0.24.0",
additional_msg="For code migration guidelines, visit https://qisk.it/qi_migration.",
)
def is_ibmq_provider(backend):
"""Detect whether or not backend is from IBMQ provider.
Expand All @@ -131,6 +152,10 @@ def is_ibmq_provider(backend):
return False


@deprecate_func(
since="0.24.0",
additional_msg="For code migration guidelines, visit https://qisk.it/qi_migration.",
)
def is_aer_statevector_backend(backend):
"""
Return True if backend object is statevector and from Aer provider.
Expand All @@ -143,6 +168,10 @@ def is_aer_statevector_backend(backend):
return is_statevector_backend(backend) and is_aer_provider(backend)


@deprecate_func(
since="0.24.0",
additional_msg="For code migration guidelines, visit https://qisk.it/qi_migration.",
)
def is_statevector_backend(backend):
"""
Return True if backend object is statevector.
Expand All @@ -168,6 +197,10 @@ def is_statevector_backend(backend):
return backend.name.startswith("statevector")


@deprecate_func(
since="0.24.0",
additional_msg="For code migration guidelines, visit https://qisk.it/qi_migration.",
)
def is_simulator_backend(backend):
"""
Return True if backend is a simulator.
Expand All @@ -183,6 +216,10 @@ def is_simulator_backend(backend):
return False


@deprecate_func(
since="0.24.0",
additional_msg="For code migration guidelines, visit https://qisk.it/qi_migration.",
)
def is_local_backend(backend):
"""
Return True if backend is a local backend.
Expand All @@ -198,6 +235,10 @@ def is_local_backend(backend):
return False


@deprecate_func(
since="0.24.0",
additional_msg="For code migration guidelines, visit https://qisk.it/qi_migration.",
)
def is_aer_qasm(backend):
"""
Return True if backend is Aer Qasm simulator
Expand All @@ -214,6 +255,10 @@ def is_aer_qasm(backend):
return ret


@deprecate_func(
since="0.24.0",
additional_msg="For code migration guidelines, visit https://qisk.it/qi_migration.",
)
def support_backend_options(backend):
"""
Return True if backend supports backend_options
Expand Down
25 changes: 21 additions & 4 deletions qiskit_algorithms/utils/measurement_error_mitigation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2019, 2021.
# (C) Copyright IBM 2019, 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
Expand All @@ -27,13 +27,18 @@
CompleteMeasFitter,
TensoredMeasFitter,
)
from qiskit.utils.deprecation import deprecate_func


@deprecate_func(
since="0.24.0",
additional_msg="For code migration guidelines, visit https://qisk.it/qi_migration.",
)
def get_measured_qubits(
transpiled_circuits: List[QuantumCircuit],
) -> Tuple[List[int], Dict[str, List[int]]]:
"""
Retrieve the measured qubits from transpiled circuits.
Deprecated: Retrieve the measured qubits from transpiled circuits.
Args:
transpiled_circuits: a list of transpiled circuits
Expand Down Expand Up @@ -73,9 +78,13 @@ def get_measured_qubits(
return sorted(qubit_index), qubit_mappings


@deprecate_func(
since="0.24.0",
additional_msg="For code migration guidelines, visit https://qisk.it/qi_migration.",
)
def get_measured_qubits_from_qobj(qobj: QasmQobj) -> Tuple[List[int], Dict[str, List[int]]]:
"""
Retrieve the measured qubits from transpiled circuits.
Deprecated: Retrieve the measured qubits from transpiled circuits.
Args:
qobj: qobj
Expand Down Expand Up @@ -114,6 +123,10 @@ def get_measured_qubits_from_qobj(qobj: QasmQobj) -> Tuple[List[int], Dict[str,
return sorted(qubit_index), qubit_mappings


@deprecate_func(
since="0.24.0",
additional_msg="For code migration guidelines, visit https://qisk.it/qi_migration.",
)
def build_measurement_error_mitigation_circuits(
qubit_list: List[int],
fitter_cls: Callable,
Expand All @@ -122,7 +135,7 @@ def build_measurement_error_mitigation_circuits(
compile_config: Optional[Dict] = None,
mit_pattern: Optional[List[List[int]]] = None,
) -> Tuple[QuantumCircuit, List[str], List[str]]:
"""Build measurement error mitigation circuits
"""Deprecated: Build measurement error mitigation circuits
Args:
qubit_list: list of ordered qubits used in the algorithm
fitter_cls: CompleteMeasFitter or TensoredMeasFitter
Expand Down Expand Up @@ -189,6 +202,10 @@ def build_measurement_error_mitigation_circuits(
return t_meas_calibs_circuits, state_labels, circlabel


@deprecate_func(
since="0.24.0",
additional_msg="For code migration guidelines, visit https://qisk.it/qi_migration.",
)
def build_measurement_error_mitigation_qobj(
qubit_list: List[int],
fitter_cls: Callable,
Expand Down
7 changes: 6 additions & 1 deletion qiskit_algorithms/utils/mitigation/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2019.
# (C) Copyright IBM 2019, 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
Expand All @@ -21,6 +21,11 @@
.. currentmodule:: qiskit.utils.mitigation
.. deprecated:: 0.24.0
This module is deprecated and will be removed no sooner than 3 months
after the release date. For code migration guidelines,
visit https://qisk.it/qi_migration.
.. warning::
The user-facing API stability of this module is not guaranteed except for
Expand Down
15 changes: 12 additions & 3 deletions qiskit_algorithms/utils/mitigation/_filters.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2019.
# (C) Copyright IBM 2019, 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
Expand Down Expand Up @@ -31,17 +31,22 @@
from qiskit import QiskitError
from qiskit.tools import parallel_map
from qiskit.utils.mitigation.circuits import count_keys
from qiskit.utils.deprecation import deprecate_func


class MeasurementFilter:
"""
Measurement error mitigation filter.
Deprecated: Measurement error mitigation filter.
Produced from a measurement calibration fitter and can be applied
to data.
"""

@deprecate_func(
since="0.24.0",
additional_msg="For code migration guidelines, visit https://qisk.it/qi_migration.",
)
def __init__(self, cal_matrix: np.matrix, state_labels: list):
"""
Initialize a measurement error mitigation filter using the cal_matrix
Expand Down Expand Up @@ -214,12 +219,16 @@ def _apply_correction(self, resultidx, raw_data, method):

class TensoredFilter:
"""
Tensored measurement error mitigation filter.
Deprecated: Tensored measurement error mitigation filter.
Produced from a tensored measurement calibration fitter and can be applied
to data.
"""

@deprecate_func(
since="0.24.0",
additional_msg="For code migration guidelines, visit https://qisk.it/qi_migration.",
)
def __init__(self, cal_matrices: np.matrix, substate_labels_list: list, mit_pattern: list):
"""
Initialize a tensored measurement error mitigation filter using
Expand Down
21 changes: 17 additions & 4 deletions qiskit_algorithms/utils/mitigation/circuits.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2019.
# (C) Copyright IBM 2019, 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
Expand All @@ -19,10 +19,15 @@
use the fitters to produce a filter.
"""
from typing import List, Tuple, Union
from qiskit.utils.deprecation import deprecate_func


@deprecate_func(
since="0.24.0",
additional_msg="For code migration guidelines, visit https://qisk.it/qi_migration.",
)
def count_keys(num_qubits: int) -> List[str]:
"""Return ordered count keys.
"""Deprecated: Return ordered count keys.
Args:
num_qubits: The number of qubits in the generated list.
Expand All @@ -35,14 +40,18 @@ def count_keys(num_qubits: int) -> List[str]:
return [bin(j)[2:].zfill(num_qubits) for j in range(2**num_qubits)]


@deprecate_func(
since="0.24.0",
additional_msg="For code migration guidelines, visit https://qisk.it/qi_migration.",
)
def complete_meas_cal(
qubit_list: List[int] = None,
qr: Union[int, List["QuantumRegister"]] = None,
cr: Union[int, List["ClassicalRegister"]] = None,
circlabel: str = "",
) -> Tuple[List["QuantumCircuit"], List[str]]:
"""
Return a list of measurement calibration circuits for the full
Deprecated: Return a list of measurement calibration circuits for the full
Hilbert space.
If the circuit contains :math:`n` qubits, then :math:`2^n` calibration circuits
Expand Down Expand Up @@ -112,14 +121,18 @@ def complete_meas_cal(
return cal_circuits, state_labels


@deprecate_func(
since="0.24.0",
additional_msg="For code migration guidelines, visit https://qisk.it/qi_migration.",
)
def tensored_meas_cal(
mit_pattern: List[List[int]] = None,
qr: Union[int, List["QuantumRegister"]] = None,
cr: Union[int, List["ClassicalRegister"]] = None,
circlabel: str = "",
) -> Tuple[List["QuantumCircuit"], List[List[int]]]:
"""
Return a list of calibration circuits
Deprecated: Return a list of calibration circuits
Args:
mit_pattern: Qubits on which to perform the
Expand Down
13 changes: 11 additions & 2 deletions qiskit_algorithms/utils/mitigation/fitters.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@
from qiskit import QiskitError
from qiskit.utils.mitigation.circuits import count_keys
from qiskit.utils.mitigation._filters import MeasurementFilter, TensoredFilter
from qiskit.utils.deprecation import deprecate_func


class CompleteMeasFitter:
"""
Measurement correction fitter for a full calibration
Deprecated: Measurement correction fitter for a full calibration
"""

@deprecate_func(
since="0.24.0",
additional_msg="For code migration guidelines, visit https://qisk.it/qi_migration.",
)
def __init__(
self,
results,
Expand Down Expand Up @@ -211,9 +216,13 @@ def readout_fidelity(self, label_list=None):

class TensoredMeasFitter:
"""
Measurement correction fitter for a tensored calibration.
Deprecated: Measurement correction fitter for a tensored calibration.
"""

@deprecate_func(
since="0.24.0",
additional_msg="For code migration guidelines, visit https://qisk.it/qi_migration.",
)
def __init__(
self,
results,
Expand Down
Loading

0 comments on commit aa30930

Please sign in to comment.