diff --git a/qiskit/algorithms/evolvers/trotterization/trotter_qrte.py b/qiskit/algorithms/evolvers/trotterization/trotter_qrte.py index e91793570d51..20c1bff6e174 100644 --- a/qiskit/algorithms/evolvers/trotterization/trotter_qrte.py +++ b/qiskit/algorithms/evolvers/trotterization/trotter_qrte.py @@ -50,18 +50,23 @@ class TrotterQRTE(RealEvolver): .. jupyter-execute:: + import warnings from qiskit.opflow import X, Z, Zero from qiskit.algorithms import EvolutionProblem, TrotterQRTE from qiskit import BasicAer from qiskit.utils import QuantumInstance - operator = X + Z + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + operator = X + Z initial_state = Zero time = 1 evolution_problem = EvolutionProblem(operator, 1, initial_state) # LieTrotter with 1 rep backend = BasicAer.get_backend("statevector_simulator") - quantum_instance = QuantumInstance(backend=backend) + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + quantum_instance = QuantumInstance(backend=backend) trotter_qrte = TrotterQRTE(quantum_instance=quantum_instance) evolved_state = trotter_qrte.evolve(evolution_problem).evolved_state """ diff --git a/qiskit/algorithms/linear_solvers/observables/absolute_average.py b/qiskit/algorithms/linear_solvers/observables/absolute_average.py index 300c31edaed9..a937c1186ce1 100644 --- a/qiskit/algorithms/linear_solvers/observables/absolute_average.py +++ b/qiskit/algorithms/linear_solvers/observables/absolute_average.py @@ -54,7 +54,9 @@ class AbsoluteAverage(LinearSystemObservable): # Observable operator observable_op = observable.observable(num_qubits) - state_vec = (~StateFn(observable_op) @ StateFn(qc)).eval() + with warnings.catch_warnings(): + warnings.simplefilter('ignore') + state_vec = (~StateFn(observable_op) @ StateFn(qc)).eval() # Obtain result result = observable.post_processing(state_vec, num_qubits) diff --git a/qiskit/algorithms/linear_solvers/observables/matrix_functional.py b/qiskit/algorithms/linear_solvers/observables/matrix_functional.py index ca0cfecf16bc..1eb249722952 100644 --- a/qiskit/algorithms/linear_solvers/observables/matrix_functional.py +++ b/qiskit/algorithms/linear_solvers/observables/matrix_functional.py @@ -63,10 +63,12 @@ class MatrixFunctional(LinearSystemObservable): observable_ops = observable.observable(num_qubits) state_vecs = [] # First is the norm - state_vecs.append((~StateFn(observable_ops[0]) @ StateFn(qcs[0])).eval()) - for i in range(1, len(observable_ops), 2): - state_vecs += [(~StateFn(observable_ops[i]) @ StateFn(qcs[i])).eval(), - (~StateFn(observable_ops[i + 1]) @ StateFn(qcs[i + 1])).eval()] + with warnings.catch_warnings(): + warnings.simplefilter('ignore') + state_vecs.append((~StateFn(observable_ops[0]) @ StateFn(qcs[0])).eval()) + for i in range(1, len(observable_ops), 2): + state_vecs += [(~StateFn(observable_ops[i]) @ StateFn(qcs[i])).eval(), + (~StateFn(observable_ops[i + 1]) @ StateFn(qcs[i + 1])).eval()] # Obtain result result = observable.post_processing(state_vecs, num_qubits) diff --git a/qiskit/opflow/__init__.py b/qiskit/opflow/__init__.py index df980959be75..37f86c5f9764 100644 --- a/qiskit/opflow/__init__.py +++ b/qiskit/opflow/__init__.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2019, 2020. +# (C) Copyright IBM 2019, 2022. # # 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 @@ -17,7 +17,7 @@ .. currentmodule:: qiskit.opflow -Operators and State functions are the building blocks of Quantum Algorithms. +Deprecation: Operators and State functions are the building blocks of Quantum Algorithms. A library for Quantum Algorithms & Applications is more than a collection of algorithms wrapped in Python functions. It needs to provide tools to make writing @@ -77,8 +77,9 @@ Operator Base Class =================== -The OperatorBase serves as the base class for all Operators, State functions and measurements, and -enforces the presence and consistency of methods to manipulate these objects conveniently. +Deprecation: The OperatorBase serves as the base class for all Operators, State functions +and measurements, and enforces the presence and consistency of methods to manipulate these +objects conveniently. .. autosummary:: :toctree: ../stubs/ @@ -90,8 +91,8 @@ Operator Globals ================ -The :mod:`operator_globals` is a set of immutable Operator instances that are convenient building -blocks to reach for while working with the Operator flow. +Deprecation: The :mod:`operator_globals` is a set of immutable Operator instances that are +convenient building blocks to reach for while working with the Operator flow. One qubit Pauli operators: :attr:`X`, :attr:`Y`, :attr:`Z`, :attr:`I` @@ -108,8 +109,8 @@ Operators --------- -The Operators submodules include the PrimitiveOp, ListOp, and StateFn class groups which -represent the primary Operator modules. +Deprecation: The Operators submodules include the PrimitiveOp, ListOp, and StateFn class +groups which represent the primary Operator modules. .. autosummary:: :toctree: ../stubs/ @@ -122,12 +123,12 @@ Converters ---------- -The Converter submodules include objects which manipulate Operators, usually recursing over an -Operator structure and changing certain Operators' representation. For example, the -:class:`~.expectations.PauliExpectation` traverses an Operator structure, and replaces all of the -:class:`~.state_fns.OperatorStateFn` measurements containing non-diagonal Pauli terms into -diagonalizing circuits following by :class:`~.state_fns.OperatorStateFn` measurement containing -only diagonal Paulis. +Deprecation: The Converter submodules include objects which manipulate Operators, +usually recursing over an Operator structure and changing certain Operators' representation. +For example, the :class:`~.expectations.PauliExpectation` traverses an Operator structure, and +replaces all of the :class:`~.state_fns.OperatorStateFn` measurements containing non-diagonal +Pauli terms into diagonalizing circuits following by :class:`~.state_fns.OperatorStateFn` +measurement containing only diagonal Paulis. .. autosummary:: :toctree: ../stubs/ diff --git a/qiskit/opflow/converters/__init__.py b/qiskit/opflow/converters/__init__.py index 14272be076fd..d017fbf5cffd 100644 --- a/qiskit/opflow/converters/__init__.py +++ b/qiskit/opflow/converters/__init__.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -16,7 +16,7 @@ .. currentmodule:: qiskit.opflow.converters -Converters are objects which manipulate Operators, usually traversing an Operator to +Deprecation: Converters are objects which manipulate Operators, usually traversing an Operator to change certain sub-Operators into a desired representation. Often the converted Operator is isomorphic or approximate to the original Operator in some way, but not always. For example, a converter may accept :class:`~qiskit.opflow.primitive_ops.CircuitOp` and return a diff --git a/qiskit/opflow/converters/abelian_grouper.py b/qiskit/opflow/converters/abelian_grouper.py index 1b8b516166a3..d040c4eebfbd 100644 --- a/qiskit/opflow/converters/abelian_grouper.py +++ b/qiskit/opflow/converters/abelian_grouper.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -13,6 +13,7 @@ """AbelianGrouper Class""" from collections import defaultdict +import warnings from typing import List, Tuple, Union, cast import numpy as np @@ -27,10 +28,11 @@ from qiskit.opflow.primitive_ops.pauli_op import PauliOp from qiskit.opflow.primitive_ops.pauli_sum_op import PauliSumOp from qiskit.opflow.state_fns.operator_state_fn import OperatorStateFn +from qiskit.utils.deprecation import deprecate_function class AbelianGrouper(ConverterBase): - """The AbelianGrouper converts SummedOps into a sum of Abelian sums. + """Deprecation: The AbelianGrouper converts SummedOps into a sum of Abelian sums. Meaning, it will traverse the Operator, and when it finds a SummedOp, it will evaluate which of the summed sub-Operators commute with one another. It will then convert each of the groups of @@ -41,12 +43,19 @@ class AbelianGrouper(ConverterBase): diagonalized together. """ + @deprecate_function( + "The AbelianGrouper opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) def __init__(self, traverse: bool = True) -> None: """ Args: traverse: Whether to convert only the Operator passed to ``convert``, or traverse down that Operator. """ + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + super().__init__() self._traverse = traverse def convert(self, operator: OperatorBase) -> OperatorBase: diff --git a/qiskit/opflow/converters/circuit_sampler.py b/qiskit/opflow/converters/circuit_sampler.py index 47253d0e0667..f878f1fd8a33 100644 --- a/qiskit/opflow/converters/circuit_sampler.py +++ b/qiskit/opflow/converters/circuit_sampler.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -14,6 +14,7 @@ import logging +import warnings from functools import partial from time import time from typing import Any, Dict, List, Optional, Tuple, Union, cast @@ -32,13 +33,14 @@ from qiskit.providers import Backend from qiskit.utils.backend_utils import is_aer_provider, is_statevector_backend from qiskit.utils.quantum_instance import QuantumInstance +from qiskit.utils.deprecation import deprecate_function logger = logging.getLogger(__name__) class CircuitSampler(ConverterBase): """ - The CircuitSampler traverses an Operator and converts any CircuitStateFns into + Deprecation: The CircuitSampler traverses an Operator and converts any CircuitStateFns into approximations of the state function by a DictStateFn or VectorStateFn using a quantum backend. Note that in order to approximate the value of the CircuitStateFn, it must 1) send state function through a depolarizing channel, which will destroy all phase information and @@ -51,6 +53,10 @@ class CircuitSampler(ConverterBase): you are better off using a different CircuitSampler for each Operator to avoid cache thrashing. """ + @deprecate_function( + "The CircuitSampler opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) def __init__( self, backend: Union[Backend, QuantumInstance], @@ -76,6 +82,9 @@ def __init__( Raises: ValueError: Set statevector or param_qobj True when not supported by backend. """ + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + super().__init__() self._quantum_instance = ( backend if isinstance(backend, QuantumInstance) else QuantumInstance(backend=backend) ) diff --git a/qiskit/opflow/converters/converter_base.py b/qiskit/opflow/converters/converter_base.py index 043702a31d8e..c6084eb8730c 100644 --- a/qiskit/opflow/converters/converter_base.py +++ b/qiskit/opflow/converters/converter_base.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -15,11 +15,12 @@ from abc import ABC, abstractmethod from qiskit.opflow.operator_base import OperatorBase +from qiskit.utils.deprecation import deprecate_function class ConverterBase(ABC): r""" - Converters take an Operator and return a new Operator, generally isomorphic + Deprecation: Converters take an Operator and return a new Operator, generally isomorphic in some way with the first, but with certain desired properties. For example, a converter may accept ``CircuitOp`` and return a ``SummedOp`` of ``PauliOps`` representing the circuit unitary. Converters may not @@ -29,6 +30,13 @@ class ConverterBase(ABC): in the number of qubits unless a clever trick is known (such as the use of sparse matrices).""" + @deprecate_function( + "The ConverterBase opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) + def __init__(self) -> None: + pass + @abstractmethod def convert(self, operator: OperatorBase) -> OperatorBase: """Accept the Operator and return the converted Operator diff --git a/qiskit/opflow/converters/dict_to_circuit_sum.py b/qiskit/opflow/converters/dict_to_circuit_sum.py index 0b34ddd734ec..4e06d704a752 100644 --- a/qiskit/opflow/converters/dict_to_circuit_sum.py +++ b/qiskit/opflow/converters/dict_to_circuit_sum.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -12,22 +12,28 @@ """DictToCircuitSum Class """ +import warnings from qiskit.opflow.converters.converter_base import ConverterBase from qiskit.opflow.list_ops.list_op import ListOp from qiskit.opflow.operator_base import OperatorBase from qiskit.opflow.state_fns.circuit_state_fn import CircuitStateFn from qiskit.opflow.state_fns.dict_state_fn import DictStateFn from qiskit.opflow.state_fns.vector_state_fn import VectorStateFn +from qiskit.utils.deprecation import deprecate_function class DictToCircuitSum(ConverterBase): r""" - Converts ``DictStateFns`` or ``VectorStateFns`` to equivalent ``CircuitStateFns`` or sums - thereof. The behavior of this class can be mostly replicated by calling ``to_circuit_op`` on - an Operator, but with the added control of choosing whether to convert only ``DictStateFns`` + Deprecation: Converts ``DictStateFns`` or ``VectorStateFns`` to equivalent ``CircuitStateFns`` + or sums thereof. The behavior of this class can be mostly replicated by calling ``to_circuit_op`` + on an Operator, but with the added control of choosing whether to convert only ``DictStateFns`` or ``VectorStateFns``, rather than both. """ + @deprecate_function( + "The DictToCircuitSum opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) def __init__( self, traverse: bool = True, convert_dicts: bool = True, convert_vectors: bool = True ) -> None: @@ -38,6 +44,9 @@ def __init__( convert_dicts: Whether to convert VectorStateFn. convert_vectors: Whether to convert DictStateFns. """ + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + super().__init__() self._traverse = traverse self._convert_dicts = convert_dicts self._convert_vectors = convert_vectors diff --git a/qiskit/opflow/converters/pauli_basis_change.py b/qiskit/opflow/converters/pauli_basis_change.py index cdc78c227d26..e832cec3d4a1 100644 --- a/qiskit/opflow/converters/pauli_basis_change.py +++ b/qiskit/opflow/converters/pauli_basis_change.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -12,6 +12,7 @@ """ PauliBasisChange Class """ +import warnings from functools import partial, reduce from typing import Callable, List, Optional, Tuple, Union, cast @@ -30,11 +31,12 @@ from qiskit.opflow.state_fns.operator_state_fn import OperatorStateFn from qiskit.opflow.state_fns.state_fn import StateFn from qiskit.quantum_info import Pauli +from qiskit.utils.deprecation import deprecate_function class PauliBasisChange(ConverterBase): r""" - Converter for changing Paulis into other bases. By default, the diagonal basis + Deprecation: Converter for changing Paulis into other bases. By default, the diagonal basis composed only of Pauli {Z, I}^n is used as the destination basis to which to convert. Meaning, if a Pauli containing X or Y terms is passed in, which cannot be sampled or evolved natively on some Quantum hardware, the Pauli can be replaced by a @@ -55,6 +57,10 @@ class PauliBasisChange(ConverterBase): this method, such as the placement of the CNOT chains. """ + @deprecate_function( + "The PauliBasisChange opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) def __init__( self, destination_basis: Optional[Union[Pauli, PauliOp]] = None, @@ -83,6 +89,9 @@ def __init__( beginning and ending operators are equivalent. """ + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + super().__init__() if destination_basis is not None: self.destination = destination_basis # type: ignore else: diff --git a/qiskit/opflow/converters/two_qubit_reduction.py b/qiskit/opflow/converters/two_qubit_reduction.py index a8a3756016e6..2de080ed4855 100644 --- a/qiskit/opflow/converters/two_qubit_reduction.py +++ b/qiskit/opflow/converters/two_qubit_reduction.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -13,6 +13,7 @@ """ Z2 Symmetry Tapering Converter Class """ import logging +import warnings from typing import List, Tuple, Union, cast from qiskit.opflow.converters.converter_base import ConverterBase @@ -20,14 +21,15 @@ from qiskit.opflow.primitive_ops.pauli_sum_op import PauliSumOp from qiskit.opflow.primitive_ops.tapered_pauli_sum_op import Z2Symmetries from qiskit.quantum_info import Pauli +from qiskit.utils.deprecation import deprecate_function logger = logging.getLogger(__name__) class TwoQubitReduction(ConverterBase): """ - Two qubit reduction converter which eliminates the central and last qubit in a list of Pauli - that has diagonal operators (Z,I) at those positions. + Deprecation: Two qubit reduction converter which eliminates the central and last + qubit in a list of Pauli that has diagonal operators (Z,I) at those positions. Chemistry specific method: It can be used to taper two qubits in parity and binary-tree mapped @@ -35,12 +37,19 @@ class TwoQubitReduction(ConverterBase): sectors, (block spin order) according to the number of particles in the system. """ + @deprecate_function( + "The TwoQubitReduction opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) def __init__(self, num_particles: Union[int, List[int], Tuple[int, int]]): """ Args: num_particles: number of particles, if it is a list, the first number is alpha and the second number if beta. """ + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + super().__init__() if isinstance(num_particles, (tuple, list)): num_alpha = num_particles[0] num_beta = num_particles[1] diff --git a/qiskit/opflow/evolutions/__init__.py b/qiskit/opflow/evolutions/__init__.py index 907781c0d100..b1c136f6cf4c 100644 --- a/qiskit/opflow/evolutions/__init__.py +++ b/qiskit/opflow/evolutions/__init__.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -16,8 +16,9 @@ .. currentmodule:: qiskit.opflow.evolutions -Evolutions are converters which traverse an Operator tree, replacing any :class:`EvolvedOp` `e` -with a Schrodinger equation-style evolution :class:`~qiskit.opflow.primitive_ops.CircuitOp` +Deprecation: Evolutions are converters which traverse an Operator tree, replacing +any :class:`EvolvedOp` `e` with a Schrodinger equation-style evolution +:class:`~qiskit.opflow.primitive_ops.CircuitOp` equalling or approximating the matrix exponential of -i * the Operator contained inside (`e.primitive`). The Evolutions are essentially implementations of Hamiltonian Simulation algorithms, including various methods for Trotterization. diff --git a/qiskit/opflow/evolutions/evolution_base.py b/qiskit/opflow/evolutions/evolution_base.py index 7043beedb1c6..fa7686f8e135 100644 --- a/qiskit/opflow/evolutions/evolution_base.py +++ b/qiskit/opflow/evolutions/evolution_base.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -12,15 +12,17 @@ """ EvolutionBase Class """ +import warnings from abc import ABC, abstractmethod from qiskit.opflow.operator_base import OperatorBase from qiskit.opflow.converters.converter_base import ConverterBase +from qiskit.utils.deprecation import deprecate_function class EvolutionBase(ConverterBase, ABC): r""" - A base for Evolution converters. + Deprecation: A base for Evolution converters. Evolutions are converters which traverse an Operator tree, replacing any ``EvolvedOp`` `e` with a Schrodinger equation-style evolution ``CircuitOp`` equalling or approximating the matrix exponential of -i * the Operator contained inside (`e.primitive`). The Evolutions are @@ -29,6 +31,15 @@ class EvolutionBase(ConverterBase, ABC): """ + @deprecate_function( + "The EvolutionBase opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) + def __init__(self) -> None: + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + super().__init__() + @abstractmethod def convert(self, operator: OperatorBase) -> OperatorBase: """Traverse the operator, replacing any ``EvolutionOps`` with their equivalent evolution diff --git a/qiskit/opflow/evolutions/evolution_factory.py b/qiskit/opflow/evolutions/evolution_factory.py index 6fda3d7cbffb..f993a702b3f9 100644 --- a/qiskit/opflow/evolutions/evolution_factory.py +++ b/qiskit/opflow/evolutions/evolution_factory.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -16,14 +16,19 @@ from qiskit.opflow.evolutions.evolution_base import EvolutionBase from qiskit.opflow.evolutions.pauli_trotter_evolution import PauliTrotterEvolution from qiskit.opflow.evolutions.matrix_evolution import MatrixEvolution +from qiskit.utils.deprecation import deprecate_function class EvolutionFactory: - """A factory class for convenient automatic selection of an Evolution algorithm based on the - Operator to be converted. + """Deprecation: A factory class for convenient automatic selection of an + Evolution algorithm based on the Operator to be converted. """ @staticmethod + @deprecate_function( + "The EvolutionFactory.build opflow method is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) def build(operator: OperatorBase = None) -> EvolutionBase: r""" A factory method for convenient automatic selection of an Evolution algorithm based on the diff --git a/qiskit/opflow/evolutions/evolved_op.py b/qiskit/opflow/evolutions/evolved_op.py index e4427e858ec4..e56c32447333 100644 --- a/qiskit/opflow/evolutions/evolved_op.py +++ b/qiskit/opflow/evolutions/evolved_op.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -12,6 +12,7 @@ """ EvolutionOp Class """ +import warnings from typing import List, Optional, Set, Union, cast import numpy as np @@ -27,11 +28,12 @@ from qiskit.opflow.primitive_ops.matrix_op import MatrixOp from qiskit.opflow.primitive_ops.primitive_op import PrimitiveOp from qiskit.quantum_info import Statevector +from qiskit.utils.deprecation import deprecate_function class EvolvedOp(PrimitiveOp): r""" - Class for wrapping Operator Evolutions for compilation (``convert``) by an EvolutionBase + Deprecation: Class for wrapping Operator Evolutions for compilation (``convert``) by an EvolutionBase method later, essentially acting as a placeholder. Note that EvolvedOp is a weird case of PrimitiveOp. It happens to be that it fits into the PrimitiveOp interface nearly perfectly, and it essentially represents a placeholder for a PrimitiveOp later, even though it doesn't @@ -39,6 +41,10 @@ class EvolvedOp(PrimitiveOp): but would have ended up copying and pasting a lot of code from PrimitiveOp.""" primitive: PrimitiveOp + @deprecate_function( + "The EvolvedOp opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) def __init__( self, primitive: OperatorBase, coeff: Union[complex, ParameterExpression] = 1.0 ) -> None: @@ -47,7 +53,9 @@ def __init__( primitive: The operator being wrapped to signify evolution later. coeff: A coefficient multiplying the operator """ - super().__init__(primitive, coeff=coeff) + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + super().__init__(primitive, coeff=coeff) def primitive_strings(self) -> Set[str]: return self.primitive.primitive_strings() diff --git a/qiskit/opflow/evolutions/matrix_evolution.py b/qiskit/opflow/evolutions/matrix_evolution.py index b26ecf773798..0657c60d0658 100644 --- a/qiskit/opflow/evolutions/matrix_evolution.py +++ b/qiskit/opflow/evolutions/matrix_evolution.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -12,6 +12,7 @@ """ MatrixEvolution Class """ +import warnings import logging from qiskit.opflow.evolutions.evolution_base import EvolutionBase @@ -20,16 +21,26 @@ from qiskit.opflow.operator_base import OperatorBase from qiskit.opflow.primitive_ops.matrix_op import MatrixOp from qiskit.opflow.primitive_ops.pauli_op import PauliOp +from qiskit.utils.deprecation import deprecate_function logger = logging.getLogger(__name__) class MatrixEvolution(EvolutionBase): r""" - Performs Evolution by classical matrix exponentiation, constructing a circuit with + Deprecation: Performs Evolution by classical matrix exponentiation, constructing a circuit with ``UnitaryGates`` or ``HamiltonianGates`` containing the exponentiation of the Operator. """ + @deprecate_function( + "The MatrixEvolution opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) + def __init__(self) -> None: + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + super().__init__() + def convert(self, operator: OperatorBase) -> OperatorBase: r""" Traverse the operator, replacing ``EvolvedOps`` with ``CircuitOps`` containing diff --git a/qiskit/opflow/evolutions/pauli_trotter_evolution.py b/qiskit/opflow/evolutions/pauli_trotter_evolution.py index 5521ba3f86a3..5ddfde839017 100644 --- a/qiskit/opflow/evolutions/pauli_trotter_evolution.py +++ b/qiskit/opflow/evolutions/pauli_trotter_evolution.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -12,6 +12,7 @@ """ PauliTrotterEvolution Class """ +import warnings import logging from typing import Optional, Union, cast @@ -32,6 +33,7 @@ from qiskit.opflow.primitive_ops.circuit_op import CircuitOp from qiskit.opflow.primitive_ops.pauli_sum_op import PauliSumOp from qiskit.opflow.primitive_ops.primitive_op import PrimitiveOp +from qiskit.utils.deprecation import deprecate_function # TODO uncomment when we implement Abelian grouped evolution. # from qiskit.opflow.converters.abelian_grouper import AbelianGrouper @@ -41,8 +43,8 @@ class PauliTrotterEvolution(EvolutionBase): r""" - An Evolution algorithm replacing exponentiated sums of Paulis by changing them each to the - Z basis, rotating with an rZ, changing back, and Trotterizing. + Deprecation: An Evolution algorithm replacing exponentiated sums of Paulis by changing + them each to the Z basis, rotating with an rZ, changing back, and Trotterizing. More specifically, we compute basis change circuits for each Pauli into a single-qubit Z, evolve the Z by the desired evolution time with an rZ gate, and change the basis back using @@ -50,6 +52,10 @@ class PauliTrotterEvolution(EvolutionBase): evolution circuits are composed together by Trotterization scheme. """ + @deprecate_function( + "The PauliTrotterEvolution opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) def __init__( self, trotter_mode: Optional[Union[str, TrotterizationBase]] = "trotter", @@ -69,7 +75,9 @@ def __init__( # sub-groups, so a single diagonalization circuit can be used for each group # rather than each Pauli. """ - + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + super().__init__() if isinstance(trotter_mode, TrotterizationBase): self._trotter = trotter_mode else: diff --git a/qiskit/opflow/evolutions/trotterizations/__init__.py b/qiskit/opflow/evolutions/trotterizations/__init__.py index f177f5ce36c6..e2edec5810b2 100644 --- a/qiskit/opflow/evolutions/trotterizations/__init__.py +++ b/qiskit/opflow/evolutions/trotterizations/__init__.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -11,7 +11,8 @@ # that they have been altered from the originals. """ -Trotterization methods - Algorithms for approximating Exponentials of Operator Sums. +Deprecation: Trotterization methods - Algorithms for +approximating Exponentials of Operator Sums. """ diff --git a/qiskit/opflow/evolutions/trotterizations/qdrift.py b/qiskit/opflow/evolutions/trotterizations/qdrift.py index 89c6ced0b144..83e9a2082620 100644 --- a/qiskit/opflow/evolutions/trotterizations/qdrift.py +++ b/qiskit/opflow/evolutions/trotterizations/qdrift.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020, 2021. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -26,16 +26,21 @@ from qiskit.opflow.primitive_ops.pauli_sum_op import PauliSumOp from qiskit.opflow.primitive_ops.primitive_op import PrimitiveOp from qiskit.utils import algorithm_globals +from qiskit.utils.deprecation import deprecate_function # pylint: disable=invalid-name class QDrift(TrotterizationBase): - """The QDrift Trotterization method, which selects each each term in the + """Deprecation: The QDrift Trotterization method, which selects each each term in the Trotterization randomly, with a probability proportional to its weight. Based on the work of Earl Campbell in https://arxiv.org/abs/1811.08017. """ + @deprecate_function( + "The QDrift opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) def __init__(self, reps: int = 1) -> None: r""" Args: diff --git a/qiskit/opflow/evolutions/trotterizations/suzuki.py b/qiskit/opflow/evolutions/trotterizations/suzuki.py index 9ba2878d8e76..24604700c4d4 100644 --- a/qiskit/opflow/evolutions/trotterizations/suzuki.py +++ b/qiskit/opflow/evolutions/trotterizations/suzuki.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -23,17 +23,22 @@ from qiskit.opflow.operator_base import OperatorBase from qiskit.opflow.primitive_ops.pauli_sum_op import PauliSumOp from qiskit.opflow.primitive_ops.primitive_op import PrimitiveOp +from qiskit.utils.deprecation import deprecate_function class Suzuki(TrotterizationBase): r""" - Suzuki Trotter expansion, composing the evolution circuits of each Operator in the sum + Deprecation: Suzuki Trotter expansion, composing the evolution circuits of each Operator in the sum together by a recursive "bookends" strategy, repeating the whole composed circuit ``reps`` times. Detailed in https://arxiv.org/pdf/quant-ph/0508139.pdf. """ + @deprecate_function( + "The Suzuki opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) def __init__(self, reps: int = 1, order: int = 2) -> None: """ Args: diff --git a/qiskit/opflow/evolutions/trotterizations/trotter.py b/qiskit/opflow/evolutions/trotterizations/trotter.py index a6d8e68b8754..4602a44f7513 100644 --- a/qiskit/opflow/evolutions/trotterizations/trotter.py +++ b/qiskit/opflow/evolutions/trotterizations/trotter.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -13,14 +13,19 @@ """ Trotter Class """ from qiskit.opflow.evolutions.trotterizations.suzuki import Suzuki +from qiskit.utils.deprecation import deprecate_function class Trotter(Suzuki): r""" - Simple Trotter expansion, composing the evolution circuits of each Operator in the sum + Deprecation: Simple Trotter expansion, composing the evolution circuits of each Operator in the sum together ``reps`` times and dividing the evolution time of each by ``reps``. """ + @deprecate_function( + "The Trotter opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) def __init__(self, reps: int = 1) -> None: r""" Args: diff --git a/qiskit/opflow/evolutions/trotterizations/trotterization_base.py b/qiskit/opflow/evolutions/trotterizations/trotterization_base.py index f76f78e10389..83d444bb80e6 100644 --- a/qiskit/opflow/evolutions/trotterizations/trotterization_base.py +++ b/qiskit/opflow/evolutions/trotterizations/trotterization_base.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -12,21 +12,29 @@ """ Trotterization Algorithm Base """ +import warnings from abc import abstractmethod from qiskit.opflow.evolutions.evolution_base import EvolutionBase from qiskit.opflow.operator_base import OperatorBase +from qiskit.utils.deprecation import deprecate_function # TODO centralize handling of commuting groups class TrotterizationBase(EvolutionBase): - """A base for Trotterization methods, algorithms for approximating exponentiations of + """Deprecation: A base for Trotterization methods, algorithms for approximating exponentiations of operator sums by compositions of exponentiations. """ + @deprecate_function( + "The TrotterizationBase opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) def __init__(self, reps: int = 1) -> None: - + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + super().__init__() self._reps = reps @property diff --git a/qiskit/opflow/evolutions/trotterizations/trotterization_factory.py b/qiskit/opflow/evolutions/trotterizations/trotterization_factory.py index 4f5b071b9775..c2c39d89ae97 100644 --- a/qiskit/opflow/evolutions/trotterizations/trotterization_factory.py +++ b/qiskit/opflow/evolutions/trotterizations/trotterization_factory.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -16,12 +16,17 @@ from qiskit.opflow.evolutions.trotterizations.suzuki import Suzuki from qiskit.opflow.evolutions.trotterizations.trotter import Trotter from qiskit.opflow.evolutions.trotterizations.trotterization_base import TrotterizationBase +from qiskit.utils.deprecation import deprecate_function class TrotterizationFactory: - """A factory for conveniently creating TrotterizationBase instances.""" + """Deprecation: A factory for conveniently creating TrotterizationBase instances.""" @staticmethod + @deprecate_function( + "The TrotterizationFactory.build opflow method is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) def build(mode: str = "trotter", reps: int = 1) -> TrotterizationBase: """A factory for conveniently creating TrotterizationBase instances. diff --git a/qiskit/opflow/exceptions.py b/qiskit/opflow/exceptions.py index bf80dd3d22c6..544a5c66e666 100644 --- a/qiskit/opflow/exceptions.py +++ b/qiskit/opflow/exceptions.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2017, 2018. +# (C) Copyright IBM 2017, 2022. # # 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 @@ -13,9 +13,16 @@ """Exception for errors raised by Opflow module.""" from qiskit.exceptions import QiskitError +from qiskit.utils.deprecation import deprecate_function class OpflowError(QiskitError): - """For Opflow specific errors.""" + """Deprecation: For Opflow specific errors.""" - pass + @deprecate_function( + "The OpflowError opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) + def __init__(self, *message): + """Set the error message.""" + super().__init__(*message) diff --git a/qiskit/opflow/expectations/__init__.py b/qiskit/opflow/expectations/__init__.py index 8109dc0bad4c..26c0c89a9a45 100644 --- a/qiskit/opflow/expectations/__init__.py +++ b/qiskit/opflow/expectations/__init__.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -16,9 +16,9 @@ .. currentmodule:: qiskit.opflow.expectations -Expectations are converters which enable the computation of the expectation value of an -Observable with respect to some state function. They traverse an Operator tree, replacing -:class:`~qiskit.opflow.state_fns.OperatorStateFn` measurements with equivalent +Deprecation: Expectations are converters which enable the computation of the expectation +value of an Observable with respect to some state function. They traverse an Operator tree, +replacing :class:`~qiskit.opflow.state_fns.OperatorStateFn` measurements with equivalent measurements which are more amenable to computation on quantum or classical hardware. For example, if one would like to measure the expectation value of an Operator ``o`` expressed as a sum of Paulis with respect to some state diff --git a/qiskit/opflow/expectations/aer_pauli_expectation.py b/qiskit/opflow/expectations/aer_pauli_expectation.py index 33790531592a..9c6e5b0a3bd5 100644 --- a/qiskit/opflow/expectations/aer_pauli_expectation.py +++ b/qiskit/opflow/expectations/aer_pauli_expectation.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -12,6 +12,7 @@ """ AerPauliExpectation Class """ +import warnings import logging from functools import reduce from operator import add @@ -28,16 +29,26 @@ from qiskit.opflow.state_fns.circuit_state_fn import CircuitStateFn from qiskit.opflow.state_fns.operator_state_fn import OperatorStateFn from qiskit.quantum_info import SparsePauliOp +from qiskit.utils.deprecation import deprecate_function logger = logging.getLogger(__name__) class AerPauliExpectation(ExpectationBase): - r"""An Expectation converter for using Aer's operator snapshot to + r"""Deprecation: An Expectation converter for using Aer's operator snapshot to take expectations of quantum state circuits over Pauli observables. """ + @deprecate_function( + "The AerPauliExpectation opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) + def __init__(self) -> None: + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + super().__init__() + def convert(self, operator: OperatorBase) -> OperatorBase: """Accept an Operator and return a new Operator with the Pauli measurements replaced by AerSnapshot-based expectation circuits. diff --git a/qiskit/opflow/expectations/cvar_expectation.py b/qiskit/opflow/expectations/cvar_expectation.py index 641c17f9619f..27f144d0cfdd 100644 --- a/qiskit/opflow/expectations/cvar_expectation.py +++ b/qiskit/opflow/expectations/cvar_expectation.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -12,6 +12,7 @@ """The CVaR (Conditional Value at Risk) expectation class.""" +import warnings from typing import Optional, Union from qiskit.opflow.expectations.aer_pauli_expectation import AerPauliExpectation @@ -20,10 +21,11 @@ from qiskit.opflow.list_ops import ComposedOp, ListOp from qiskit.opflow.operator_base import OperatorBase from qiskit.opflow.state_fns import CVaRMeasurement, OperatorStateFn +from qiskit.utils.deprecation import deprecate_function class CVaRExpectation(ExpectationBase): - r"""Compute the Conditional Value at Risk (CVaR) expectation value. + r"""Deprecation: Compute the Conditional Value at Risk (CVaR) expectation value. The standard approach to calculating the expectation value of a Hamiltonian w.r.t. a state is to take the sample mean of the measurement outcomes. This corresponds to an estimator @@ -54,6 +56,10 @@ class CVaRExpectation(ExpectationBase): """ + @deprecate_function( + "The CVaRExpectation opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) def __init__(self, alpha: float, expectation: Optional[ExpectationBase] = None) -> None: """ Args: @@ -64,6 +70,9 @@ def __init__(self, alpha: float, expectation: Optional[ExpectationBase] = None) Raises: NotImplementedError: If the ``expectation`` is an AerPauliExpecation. """ + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + super().__init__() self.alpha = alpha if isinstance(expectation, AerPauliExpectation): raise NotImplementedError("AerPauliExpecation currently not supported.") diff --git a/qiskit/opflow/expectations/expectation_base.py b/qiskit/opflow/expectations/expectation_base.py index 5de7de7dbd3d..716caab60e5a 100644 --- a/qiskit/opflow/expectations/expectation_base.py +++ b/qiskit/opflow/expectations/expectation_base.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -12,6 +12,7 @@ """ ExpectationBase Class """ +import warnings from abc import abstractmethod from typing import Union @@ -19,11 +20,12 @@ from qiskit.opflow.converters import ConverterBase from qiskit.opflow.operator_base import OperatorBase +from qiskit.utils.deprecation import deprecate_function class ExpectationBase(ConverterBase): r""" - A base for Expectation value converters. Expectations are converters which enable the + Deprecation: A base for Expectation value converters. Expectations are converters which enable the computation of the expectation value of an Observable with respect to some state function. They traverse an Operator tree, replacing OperatorStateFn measurements with equivalent measurements which are more amenable to computation on quantum or classical hardware. For @@ -37,6 +39,15 @@ class ExpectationBase(ConverterBase): """ + @deprecate_function( + "The ExpectationBase opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) + def __init__(self) -> None: + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + super().__init__() + @abstractmethod def convert(self, operator: OperatorBase) -> OperatorBase: """Accept an Operator and return a new Operator with the measurements replaced by diff --git a/qiskit/opflow/expectations/expectation_factory.py b/qiskit/opflow/expectations/expectation_factory.py index 182d7993809a..7d95895ccfc0 100644 --- a/qiskit/opflow/expectations/expectation_factory.py +++ b/qiskit/opflow/expectations/expectation_factory.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -24,16 +24,21 @@ from qiskit.providers import Backend from qiskit.utils.backend_utils import has_aer, is_aer_qasm, is_statevector_backend from qiskit.utils.quantum_instance import QuantumInstance +from qiskit.utils.deprecation import deprecate_function logger = logging.getLogger(__name__) class ExpectationFactory: - """A factory class for convenient automatic selection of an Expectation based on the + """Deprecation: factory class for convenient automatic selection of an Expectation based on the Operator to be converted and backend used to sample the expectation value. """ @staticmethod + @deprecate_function( + "The ExpectationFactory.build opflow method is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) def build( operator: OperatorBase, backend: Optional[Union[Backend, QuantumInstance]] = None, diff --git a/qiskit/opflow/expectations/matrix_expectation.py b/qiskit/opflow/expectations/matrix_expectation.py index 917ae069f7a5..2c6b5d0fe782 100644 --- a/qiskit/opflow/expectations/matrix_expectation.py +++ b/qiskit/opflow/expectations/matrix_expectation.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -12,17 +12,28 @@ """ MatrixExpectation Class """ +import warnings from typing import Union from qiskit.opflow.expectations.expectation_base import ExpectationBase from qiskit.opflow.list_ops import ComposedOp, ListOp from qiskit.opflow.operator_base import OperatorBase from qiskit.opflow.state_fns.operator_state_fn import OperatorStateFn +from qiskit.utils.deprecation import deprecate_function class MatrixExpectation(ExpectationBase): - """An Expectation converter which converts Operator measurements to be matrix-based so they - can be evaluated by matrix multiplication.""" + """Deprecation: An Expectation converter which converts Operator measurements to + be matrix-based so they can be evaluated by matrix multiplication.""" + + @deprecate_function( + "The MatrixExpectation opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) + def __init__(self) -> None: + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + super().__init__() def convert(self, operator: OperatorBase) -> OperatorBase: """Accept an Operator and return a new Operator with the Pauli measurements replaced by diff --git a/qiskit/opflow/expectations/pauli_expectation.py b/qiskit/opflow/expectations/pauli_expectation.py index 86fc588514ea..03e5ac016462 100644 --- a/qiskit/opflow/expectations/pauli_expectation.py +++ b/qiskit/opflow/expectations/pauli_expectation.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -12,6 +12,7 @@ """ PauliExpectation Class """ +import warnings import logging from typing import Union @@ -27,13 +28,14 @@ from qiskit.opflow.primitive_ops.primitive_op import PrimitiveOp from qiskit.opflow.state_fns.operator_state_fn import OperatorStateFn from qiskit.opflow.state_fns.state_fn import StateFn +from qiskit.utils.deprecation import deprecate_function logger = logging.getLogger(__name__) class PauliExpectation(ExpectationBase): r""" - An Expectation converter for Pauli-basis observables by changing Pauli measurements to a + Deprecation: An Expectation converter for Pauli-basis observables by changing Pauli measurements to a diagonal ({Z, I}^n) basis and appending circuit post-rotations to the measured state function. Optionally groups the Paulis with the same post-rotations (those that commute with one another, or form Abelian groups) into single measurements to reduce circuit execution @@ -41,6 +43,10 @@ class PauliExpectation(ExpectationBase): """ + @deprecate_function( + "The PauliExpectation opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) def __init__(self, group_paulis: bool = True) -> None: """ Args: @@ -48,6 +54,9 @@ def __init__(self, group_paulis: bool = True) -> None: have the same diagonalizing circuit. """ + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + super().__init__() self._grouper = AbelianGrouper() if group_paulis else None def convert(self, operator: OperatorBase) -> OperatorBase: diff --git a/qiskit/opflow/gradients/__init__.py b/qiskit/opflow/gradients/__init__.py index 01c4b02a62eb..af8d40795a54 100644 --- a/qiskit/opflow/gradients/__init__.py +++ b/qiskit/opflow/gradients/__init__.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -14,9 +14,9 @@ Gradients (:mod:`qiskit.opflow.gradients`) ========================================== -Given an operator that represents either a quantum state resp. an expectation value, the gradient -framework enables the evaluation of gradients, natural gradients, Hessians, as well as the Quantum -Fisher Information. +Deprecation: Given an operator that represents either a quantum state resp. an expectation value, +the gradient framework enables the evaluation of gradients, natural gradients, +Hessians, as well as the Quantum Fisher Information. Suppose a parameterized quantum state `|ψ(θ)〉 = V(θ)|ψ〉` with input state `|ψ〉` and parameterized Ansatz `V(θ)`, and an Operator `O(ω)`. diff --git a/qiskit/opflow/gradients/circuit_gradients/__init__.py b/qiskit/opflow/gradients/circuit_gradients/__init__.py index eae08898049a..3fe8a5ee582f 100644 --- a/qiskit/opflow/gradients/circuit_gradients/__init__.py +++ b/qiskit/opflow/gradients/circuit_gradients/__init__.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 diff --git a/qiskit/opflow/gradients/circuit_gradients/circuit_gradient.py b/qiskit/opflow/gradients/circuit_gradients/circuit_gradient.py index 1b5a303cb0b6..e32946048e23 100644 --- a/qiskit/opflow/gradients/circuit_gradients/circuit_gradient.py +++ b/qiskit/opflow/gradients/circuit_gradients/circuit_gradient.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -12,17 +12,19 @@ """CircuitGradient Class """ +import warnings from abc import abstractmethod from typing import List, Union, Optional, Tuple, Set from qiskit import QuantumCircuit, QiskitError, transpile from qiskit.circuit import ParameterExpression, ParameterVector +from qiskit.utils.deprecation import deprecate_function from ...converters.converter_base import ConverterBase from ...operator_base import OperatorBase class CircuitGradient(ConverterBase): - r"""Circuit to gradient operator converter. + r"""Deprecation: Circuit to gradient operator converter. Converter for changing parameterized circuits into operators whose evaluation yields the gradient with respect to the circuit parameters. @@ -35,6 +37,15 @@ class CircuitGradient(ConverterBase): DerivativeBase - uses classical techniques to differentiate operator flow data structures """ + @deprecate_function( + "The CircuitGradient opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) + def __init__(self) -> None: + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + super().__init__() + # pylint: disable=arguments-differ @abstractmethod def convert( diff --git a/qiskit/opflow/gradients/circuit_gradients/lin_comb.py b/qiskit/opflow/gradients/circuit_gradients/lin_comb.py index 366fb59fd497..ed0f1542d8d3 100644 --- a/qiskit/opflow/gradients/circuit_gradients/lin_comb.py +++ b/qiskit/opflow/gradients/circuit_gradients/lin_comb.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020, 2021. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -12,6 +12,7 @@ """The module to compute the state gradient with the linear combination method.""" +import warnings from collections.abc import Iterable from copy import deepcopy from functools import partial @@ -50,6 +51,7 @@ ZGate, ) from qiskit.quantum_info import partial_trace +from qiskit.utils.deprecation import deprecate_function from ...operator_base import OperatorBase from ...list_ops.list_op import ListOp from ...list_ops.composed_op import ComposedOp @@ -67,7 +69,7 @@ class LinComb(CircuitGradient): - """Compute the state gradient d⟨ψ(ω)|O(θ)|ψ(ω)〉/ dω respectively the gradients of the + """Deprecation: Compute the state gradient d⟨ψ(ω)|O(θ)|ψ(ω)〉/ dω respectively the gradients of the sampling probabilities of the basis states of a state |ψ(ω)〉w.r.t. ω. This method employs a linear combination of unitaries, @@ -100,6 +102,10 @@ class LinComb(CircuitGradient): } # pylint: disable=signature-differs, arguments-differ + @deprecate_function( + "The LinComb opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) def __init__(self, aux_meas_op: OperatorBase = Z): """ Args: @@ -110,7 +116,9 @@ def __init__(self, aux_meas_op: OperatorBase = Z): Raises: ValueError: If the provided auxiliary measurement operator is not supported. """ - super().__init__() + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + super().__init__() if aux_meas_op not in [Z, -Y, (Z - 1j * Y)]: raise ValueError( "This auxiliary measurement operator is currently not supported. Please choose " diff --git a/qiskit/opflow/gradients/circuit_gradients/param_shift.py b/qiskit/opflow/gradients/circuit_gradients/param_shift.py index 435914f9f342..69c986c68523 100644 --- a/qiskit/opflow/gradients/circuit_gradients/param_shift.py +++ b/qiskit/opflow/gradients/circuit_gradients/param_shift.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -12,6 +12,7 @@ """The module to compute the state gradient with the parameter shift rule.""" +import warnings from collections.abc import Iterable from copy import deepcopy from functools import partial @@ -22,6 +23,7 @@ from qiskit import QuantumCircuit from qiskit.circuit import Parameter, ParameterExpression, ParameterVector +from qiskit.utils.deprecation import deprecate_function from .circuit_gradient import CircuitGradient from ...operator_base import OperatorBase from ...state_fns.state_fn import StateFn @@ -39,13 +41,17 @@ class ParamShift(CircuitGradient): - """Compute the gradient d⟨ψ(ω)|O(θ)|ψ(ω)〉/ dω respectively the gradients of the sampling + """Deprecation: Compute the gradient d⟨ψ(ω)|O(θ)|ψ(ω)〉/ dω respectively the gradients of the sampling probabilities of the basis states of a state |ψ(ω)〉w.r.t. ω with the parameter shift method. """ SUPPORTED_GATES = {"x", "y", "z", "h", "rx", "ry", "rz", "p", "u", "cx", "cy", "cz"} + @deprecate_function( + "The ParamShift opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) def __init__(self, analytic: bool = True, epsilon: float = 1e-6): r""" Args: @@ -57,7 +63,9 @@ def __init__(self, analytic: bool = True, epsilon: float = 1e-6): Raises: ValueError: If method != ``fin_diff`` and ``epsilon`` is not None. """ - + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + super().__init__() self._analytic = analytic self._epsilon = epsilon diff --git a/qiskit/opflow/gradients/circuit_qfis/__init__.py b/qiskit/opflow/gradients/circuit_qfis/__init__.py index d32126acd523..988b383700c1 100644 --- a/qiskit/opflow/gradients/circuit_qfis/__init__.py +++ b/qiskit/opflow/gradients/circuit_qfis/__init__.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 diff --git a/qiskit/opflow/gradients/circuit_qfis/circuit_qfi.py b/qiskit/opflow/gradients/circuit_qfis/circuit_qfi.py index 693f713263ae..8339c6ed1bc7 100644 --- a/qiskit/opflow/gradients/circuit_qfis/circuit_qfi.py +++ b/qiskit/opflow/gradients/circuit_qfis/circuit_qfi.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -12,16 +12,18 @@ """ CircuitQFI Class """ +import warnings from abc import abstractmethod from typing import List, Union from qiskit.circuit import ParameterExpression, ParameterVector +from qiskit.utils.deprecation import deprecate_function from ...converters.converter_base import ConverterBase from ...operator_base import OperatorBase class CircuitQFI(ConverterBase): - r"""Circuit to Quantum Fisher Information operator converter. + r"""Deprecation: Circuit to Quantum Fisher Information operator converter. Converter for changing parameterized circuits into operators whose evaluation yields Quantum Fisher Information metric tensor @@ -35,6 +37,15 @@ class CircuitQFI(ConverterBase): DerivativeBase - uses classical techniques to differentiate opflow data structures """ + @deprecate_function( + "The CircuitQFI opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) + def __init__(self) -> None: + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + super().__init__() + # pylint: disable=arguments-differ @abstractmethod def convert( diff --git a/qiskit/opflow/gradients/circuit_qfis/lin_comb_full.py b/qiskit/opflow/gradients/circuit_qfis/lin_comb_full.py index 81865180881f..02c085fb6ebf 100644 --- a/qiskit/opflow/gradients/circuit_qfis/lin_comb_full.py +++ b/qiskit/opflow/gradients/circuit_qfis/lin_comb_full.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020, 2021. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -12,11 +12,13 @@ """The module for Quantum the Fisher Information.""" +import warnings from typing import List, Union import numpy as np from qiskit.circuit import QuantumCircuit, QuantumRegister, ParameterVector, ParameterExpression from qiskit.utils.arithmetic import triu_to_dense +from qiskit.utils.deprecation import deprecate_function from ...operator_base import OperatorBase from ...list_ops.list_op import ListOp @@ -29,13 +31,17 @@ class LinCombFull(CircuitQFI): - r"""Compute the full Quantum Fisher Information (QFI). + r"""Deprecation: Compute the full Quantum Fisher Information (QFI). Given a pure, parameterized quantum state this class uses the linear combination of unitaries See also :class:`~qiskit.opflow.QFI`. """ # pylint: disable=signature-differs, arguments-differ + @deprecate_function( + "The LinCombFull opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) def __init__( self, aux_meas_op: OperatorBase = Z, @@ -52,7 +58,9 @@ def __init__( Raises: ValueError: If the provided auxiliary measurement operator is not supported. """ - super().__init__() + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + super().__init__() if aux_meas_op not in [Z, -Y, (Z - 1j * Y)]: raise ValueError( "This auxiliary measurement operator is currently not supported. Please choose " diff --git a/qiskit/opflow/gradients/circuit_qfis/overlap_block_diag.py b/qiskit/opflow/gradients/circuit_qfis/overlap_block_diag.py index 7daf6486685c..e2f8e0337ad7 100644 --- a/qiskit/opflow/gradients/circuit_qfis/overlap_block_diag.py +++ b/qiskit/opflow/gradients/circuit_qfis/overlap_block_diag.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -12,12 +12,14 @@ """The module for the Quantum Fisher Information.""" +import warnings from typing import List, Union import numpy as np from scipy.linalg import block_diag from qiskit.circuit import Parameter, ParameterVector, ParameterExpression from qiskit.utils.arithmetic import triu_to_dense +from qiskit.utils.deprecation import deprecate_function from ...list_ops.list_op import ListOp from ...primitive_ops.circuit_op import CircuitOp from ...expectations.pauli_expectation import PauliExpectation @@ -32,12 +34,21 @@ class OverlapBlockDiag(CircuitQFI): - r"""Compute the block-diagonal of the QFI given a pure, parameterized quantum state. + r"""Deprecation: Compute the block-diagonal of the QFI given a pure, parameterized quantum state. The blocks are given by all parameterized gates in quantum circuit layer. See also :class:`~qiskit.opflow.QFI`. """ + @deprecate_function( + "The OverlapBlockDiag opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) + def __init__(self) -> None: + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + super().__init__() + def convert( self, operator: Union[CircuitOp, CircuitStateFn], diff --git a/qiskit/opflow/gradients/circuit_qfis/overlap_diag.py b/qiskit/opflow/gradients/circuit_qfis/overlap_diag.py index 9efca9f6791b..ccb6afa9e582 100644 --- a/qiskit/opflow/gradients/circuit_qfis/overlap_diag.py +++ b/qiskit/opflow/gradients/circuit_qfis/overlap_diag.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -11,6 +11,8 @@ # that they have been altered from the originals. """The module for Quantum the Fisher Information.""" + +import warnings import copy from typing import List, Union @@ -18,6 +20,7 @@ from qiskit.circuit import ParameterVector, ParameterExpression from qiskit.circuit.library import RZGate, RXGate, RYGate from qiskit.converters import dag_to_circuit, circuit_to_dag +from qiskit.utils.deprecation import deprecate_function from ...list_ops.list_op import ListOp from ...primitive_ops.circuit_op import CircuitOp from ...expectations.pauli_expectation import PauliExpectation @@ -31,11 +34,20 @@ class OverlapDiag(CircuitQFI): - r"""Compute the diagonal of the QFI given a pure, parameterized quantum state. + r"""Deprecation: Compute the diagonal of the QFI given a pure, parameterized quantum state. See also :class:`~qiskit.opflow.QFI`. """ + @deprecate_function( + "The OverlapDiag opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) + def __init__(self) -> None: + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + super().__init__() + def convert( self, operator: Union[CircuitOp, CircuitStateFn], diff --git a/qiskit/opflow/gradients/derivative_base.py b/qiskit/opflow/gradients/derivative_base.py index 1e1b3fadb5b7..24f9319280ff 100644 --- a/qiskit/opflow/gradients/derivative_base.py +++ b/qiskit/opflow/gradients/derivative_base.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -20,6 +20,7 @@ from qiskit.utils.quantum_instance import QuantumInstance from qiskit.circuit import ParameterExpression, ParameterVector from qiskit.providers import Backend +from qiskit.utils.deprecation import deprecate_function from ..converters.converter_base import ConverterBase from ..expectations import ExpectationBase, PauliExpectation @@ -34,7 +35,7 @@ class DerivativeBase(ConverterBase): - r"""Base class for differentiating opflow objects. + r"""Deprecation: Base class for differentiating opflow objects. Converter for differentiating opflow objects and handling things like properly differentiating combo_fn's and enforcing product rules @@ -48,6 +49,15 @@ class DerivativeBase(ConverterBase): DerivativeBase - uses classical techniques to differentiate opflow data structures """ + @deprecate_function( + "The DerivativeBase opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) + def __init__(self) -> None: + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + super().__init__() + # pylint: disable=arguments-differ @abstractmethod def convert( diff --git a/qiskit/opflow/gradients/gradient.py b/qiskit/opflow/gradients/gradient.py index 1b7e6fd10333..2c1438ece240 100644 --- a/qiskit/opflow/gradients/gradient.py +++ b/qiskit/opflow/gradients/gradient.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -12,6 +12,7 @@ """The base interface for Opflow's gradient.""" +import warnings from typing import Union, List, Optional import functools import numpy as np @@ -19,6 +20,8 @@ from qiskit.circuit.quantumcircuit import _compare_parameters from qiskit.circuit import ParameterExpression, ParameterVector from qiskit.utils import optionals as _optionals +from qiskit.utils.deprecation import deprecate_function +from .circuit_gradients.circuit_gradient import CircuitGradient from ..expectations.pauli_expectation import PauliExpectation from .gradient_base import GradientBase from .derivative_base import _coeff_derivative @@ -33,7 +36,16 @@ class Gradient(GradientBase): - """Convert an operator expression to the first-order gradient.""" + """Deprecation: Convert an operator expression to the first-order gradient.""" + + @deprecate_function( + "The Gradient opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) + def __init__(self, grad_method: Union[str, CircuitGradient] = "param_shift", **kwargs): + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + super().__init__(grad_method=grad_method, **kwargs) def convert( self, diff --git a/qiskit/opflow/gradients/gradient_base.py b/qiskit/opflow/gradients/gradient_base.py index af38b5150b1c..a7714bbab28f 100644 --- a/qiskit/opflow/gradients/gradient_base.py +++ b/qiskit/opflow/gradients/gradient_base.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -12,18 +12,24 @@ """The base interface for Aqua's gradient.""" +import warnings from typing import Union +from qiskit.utils.deprecation import deprecate_function from .circuit_gradients.circuit_gradient import CircuitGradient from .derivative_base import DerivativeBase class GradientBase(DerivativeBase): - """Base class for first-order operator gradient. + """Deprecation: Base class for first-order operator gradient. Convert an operator expression to the first-order gradient. """ + @deprecate_function( + "The GradientBase opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) def __init__(self, grad_method: Union[str, CircuitGradient] = "param_shift", **kwargs): r""" Args: @@ -35,7 +41,9 @@ def __init__(self, grad_method: Union[str, CircuitGradient] = "param_shift", **k Raises: ValueError: If method != ``fin_diff`` and ``epsilon`` is not None. """ - + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + super().__init__() if isinstance(grad_method, CircuitGradient): self._grad_method = grad_method elif grad_method == "param_shift": diff --git a/qiskit/opflow/gradients/hessian.py b/qiskit/opflow/gradients/hessian.py index 60a05d131fb4..26c2bf4831c8 100644 --- a/qiskit/opflow/gradients/hessian.py +++ b/qiskit/opflow/gradients/hessian.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -12,6 +12,7 @@ """The module to compute Hessians.""" +import warnings from typing import Union, List, Tuple, Optional import functools import numpy as np @@ -19,6 +20,7 @@ from qiskit.circuit.quantumcircuit import _compare_parameters from qiskit.circuit import ParameterVector, ParameterExpression from qiskit.utils import optionals as _optionals +from qiskit.utils.deprecation import deprecate_function from ..operator_globals import Zero, One from ..state_fns.circuit_state_fn import CircuitStateFn from ..state_fns.state_fn import StateFn @@ -33,10 +35,20 @@ from .hessian_base import HessianBase from ..exceptions import OpflowError from ...utils.arithmetic import triu_to_dense +from .circuit_gradients.circuit_gradient import CircuitGradient class Hessian(HessianBase): - """Compute the Hessian of an expected value.""" + """Deprecation: Compute the Hessian of an expected value.""" + + @deprecate_function( + "The Hessian opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) + def __init__(self, hess_method: Union[str, CircuitGradient] = "param_shift", **kwargs): + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + super().__init__(hess_method=hess_method, **kwargs) def convert( self, diff --git a/qiskit/opflow/gradients/hessian_base.py b/qiskit/opflow/gradients/hessian_base.py index 4ed5b3381821..e8137f78c578 100644 --- a/qiskit/opflow/gradients/hessian_base.py +++ b/qiskit/opflow/gradients/hessian_base.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -12,15 +12,21 @@ """The module to compute Hessians.""" +import warnings from typing import Union +from qiskit.utils.deprecation import deprecate_function from .circuit_gradients.circuit_gradient import CircuitGradient from .derivative_base import DerivativeBase class HessianBase(DerivativeBase): - """Base class for the Hessian of an expected value.""" + """Deprecation: Base class for the Hessian of an expected value.""" + @deprecate_function( + "The HessianBase opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) def __init__(self, hess_method: Union[str, CircuitGradient] = "param_shift", **kwargs): r""" Args: @@ -32,7 +38,9 @@ def __init__(self, hess_method: Union[str, CircuitGradient] = "param_shift", **k Raises: ValueError: If method != ``fin_diff`` and ``epsilon`` is not None. """ - + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + super().__init__() if isinstance(hess_method, CircuitGradient): self._hess_method = hess_method elif hess_method == "param_shift": diff --git a/qiskit/opflow/gradients/natural_gradient.py b/qiskit/opflow/gradients/natural_gradient.py index 524bd9c35346..76d5fa25f09a 100644 --- a/qiskit/opflow/gradients/natural_gradient.py +++ b/qiskit/opflow/gradients/natural_gradient.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2018, 2020. +# (C) Copyright IBM 2018, 2022. # # 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 @@ -12,6 +12,7 @@ """ Natural Gradient. """ +import warnings from collections.abc import Iterable from typing import List, Tuple, Callable, Optional, Union import functools @@ -20,6 +21,7 @@ from qiskit.circuit.quantumcircuit import _compare_parameters from qiskit.circuit import ParameterVector, ParameterExpression from qiskit.utils import optionals as _optionals +from qiskit.utils.deprecation import deprecate_function from ..operator_base import OperatorBase from ..list_ops.list_op import ListOp from ..list_ops.composed_op import ComposedOp @@ -37,7 +39,7 @@ class NaturalGradient(GradientBase): - r"""Convert an operator expression to the first-order gradient. + r"""Deprecation: Convert an operator expression to the first-order gradient. Given an ill-posed inverse problem @@ -51,6 +53,10 @@ class NaturalGradient(GradientBase): where R(x) represents the penalization term. """ + @deprecate_function( + "The NaturalGradient opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) def __init__( self, grad_method: Union[str, CircuitGradient] = "lin_comb", @@ -72,7 +78,9 @@ def __init__( a least square solver is used without regularization kwargs (dict): Optional parameters for a CircuitGradient """ - super().__init__(grad_method) + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + super().__init__(grad_method) self._qfi_method = QFI(qfi_method) self._regularization = regularization diff --git a/qiskit/opflow/gradients/qfi.py b/qiskit/opflow/gradients/qfi.py index f9bd289aaa0e..a1b024a27523 100644 --- a/qiskit/opflow/gradients/qfi.py +++ b/qiskit/opflow/gradients/qfi.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -12,19 +12,22 @@ """The module for Quantum the Fisher Information.""" +import warnings from typing import List, Union, Optional import functools from qiskit.circuit.quantumcircuit import _compare_parameters from qiskit.circuit import ParameterExpression, ParameterVector +from qiskit.utils.deprecation import deprecate_function from ..list_ops.list_op import ListOp from ..expectations.pauli_expectation import PauliExpectation from ..state_fns.circuit_state_fn import CircuitStateFn from .qfi_base import QFIBase +from .circuit_qfis import CircuitQFI class QFI(QFIBase): - r"""Compute the Quantum Fisher Information (QFI). + r"""Deprecation: Compute the Quantum Fisher Information (QFI). Computes the QFI given a pure, parameterized quantum state, where QFI is: @@ -35,6 +38,15 @@ class QFI(QFIBase): """ + @deprecate_function( + "The QFI opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) + def __init__(self, qfi_method: Union[str, CircuitQFI] = "lin_comb_full"): + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + super().__init__(qfi_method=qfi_method) + def convert( self, operator: CircuitStateFn, diff --git a/qiskit/opflow/gradients/qfi_base.py b/qiskit/opflow/gradients/qfi_base.py index 77686741217b..32f33087689b 100644 --- a/qiskit/opflow/gradients/qfi_base.py +++ b/qiskit/opflow/gradients/qfi_base.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -12,15 +12,17 @@ """The module for Quantum the Fisher Information.""" +import warnings from typing import Union +from qiskit.utils.deprecation import deprecate_function from .derivative_base import DerivativeBase from .circuit_qfis import CircuitQFI class QFIBase(DerivativeBase): - r"""Base class for Quantum Fisher Information (QFI). + r"""Deprecation: Base class for Quantum Fisher Information (QFI). Compute the Quantum Fisher Information (QFI) given a pure, parameterized quantum state. @@ -29,6 +31,10 @@ class QFIBase(DerivativeBase): [QFI]kl= Re[〈∂kψ|∂lψ〉−〈∂kψ|ψ〉〈ψ|∂lψ〉] * 4. """ + @deprecate_function( + "The QFIBase opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) def __init__(self, qfi_method: Union[str, CircuitQFI] = "lin_comb_full"): r""" Args: @@ -39,7 +45,9 @@ def __init__(self, qfi_method: Union[str, CircuitQFI] = "lin_comb_full"): ValueError: if ``qfi_method`` is neither a ``CircuitQFI`` object nor one of the predefined strings. """ - + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + super().__init__() if isinstance(qfi_method, CircuitQFI): self._qfi_method = qfi_method diff --git a/qiskit/opflow/list_ops/__init__.py b/qiskit/opflow/list_ops/__init__.py index d2ae28d1f05b..bd93bffdc9f4 100644 --- a/qiskit/opflow/list_ops/__init__.py +++ b/qiskit/opflow/list_ops/__init__.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -16,7 +16,8 @@ .. currentmodule:: qiskit.opflow.list_ops -List Operators are classes for storing and manipulating lists of Operators, State functions, +Deprecation: List Operators are classes for storing and manipulating lists of Operators, +State functions, or Measurements, and include some rule or ``combo_fn`` defining how the Operator functions of the list constituents should be combined to form to cumulative Operator function of the :class:`ListOp`. For example, a :class:`SummedOp` has an addition-based ``combo_fn``, so once diff --git a/qiskit/opflow/list_ops/composed_op.py b/qiskit/opflow/list_ops/composed_op.py index 089934e7dc80..76f6addfaad6 100644 --- a/qiskit/opflow/list_ops/composed_op.py +++ b/qiskit/opflow/list_ops/composed_op.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -23,15 +23,20 @@ from qiskit.opflow.list_ops.list_op import ListOp from qiskit.opflow.operator_base import OperatorBase from qiskit.quantum_info import Statevector +from qiskit.utils.deprecation import deprecate_function class ComposedOp(ListOp): - """A class for lazily representing compositions of Operators. Often Operators cannot be + """Deprecation: A class for lazily representing compositions of Operators. Often Operators cannot be efficiently composed with one another, but may be manipulated further so that they can be composed later. This class holds logic to indicate that the Operators in ``oplist`` are meant to be composed, and therefore if they reach a point in which they can be, such as after conversion to QuantumCircuits or matrices, they can be reduced by composition.""" + @deprecate_function( + "The ComposedOp opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) def __init__( self, oplist: List[OperatorBase], diff --git a/qiskit/opflow/list_ops/list_op.py b/qiskit/opflow/list_ops/list_op.py index ce5178436abb..f9e5aad9e3fc 100644 --- a/qiskit/opflow/list_ops/list_op.py +++ b/qiskit/opflow/list_ops/list_op.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -12,6 +12,7 @@ """ ListOp Operator Class """ +import warnings from functools import reduce from numbers import Number from typing import Any, Callable, Dict, Iterator, List, Optional, Set, Sequence, Union, cast @@ -24,12 +25,13 @@ from qiskit.opflow.operator_base import OperatorBase from qiskit.quantum_info import Statevector from qiskit.utils import arithmetic +from qiskit.utils.deprecation import deprecate_function class ListOp(OperatorBase): """ - A Class for manipulating List Operators, and parent class to ``SummedOp``, ``ComposedOp``, - and ``TensoredOp``. + Deprecation: A Class for manipulating List Operators, and parent class to ``SummedOp``, + ``ComposedOp`` and ``TensoredOp``. List Operators are classes for storing and manipulating lists of Operators, State functions, or Measurements, and include some rule or ``combo_fn`` defining how the Operator functions @@ -53,6 +55,10 @@ class ListOp(OperatorBase): multiple dimensional lists. """ + @deprecate_function( + "The ListOp opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) def __init__( self, oplist: Sequence[OperatorBase], @@ -73,7 +79,9 @@ def __init__( Note that the default "recombination function" lambda above is essentially the identity - it accepts the list of values, and returns them in a list. """ - super().__init__() + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + super().__init__() self._oplist = self._check_input_types(oplist) self._combo_fn = combo_fn self._coeff = coeff diff --git a/qiskit/opflow/list_ops/summed_op.py b/qiskit/opflow/list_ops/summed_op.py index f856f4822acc..378948ba6015 100644 --- a/qiskit/opflow/list_ops/summed_op.py +++ b/qiskit/opflow/list_ops/summed_op.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -21,15 +21,20 @@ from qiskit.opflow.exceptions import OpflowError from qiskit.opflow.list_ops.list_op import ListOp from qiskit.opflow.operator_base import OperatorBase +from qiskit.utils.deprecation import deprecate_function class SummedOp(ListOp): - """A class for lazily representing sums of Operators. Often Operators cannot be + """Deprecation: A class for lazily representing sums of Operators. Often Operators cannot be efficiently added to one another, but may be manipulated further so that they can be later. This class holds logic to indicate that the Operators in ``oplist`` are meant to be added together, and therefore if they reach a point in which they can be, such as after evaluation or conversion to matrices, they can be reduced by addition.""" + @deprecate_function( + "The SummedOp opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) def __init__( self, oplist: List[OperatorBase], diff --git a/qiskit/opflow/list_ops/tensored_op.py b/qiskit/opflow/list_ops/tensored_op.py index 3ff574f00b50..e1faeb602304 100644 --- a/qiskit/opflow/list_ops/tensored_op.py +++ b/qiskit/opflow/list_ops/tensored_op.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -22,15 +22,20 @@ from qiskit.opflow.list_ops.list_op import ListOp from qiskit.opflow.operator_base import OperatorBase from qiskit.quantum_info import Statevector +from qiskit.utils.deprecation import deprecate_function class TensoredOp(ListOp): - """A class for lazily representing tensor products of Operators. Often Operators cannot be - efficiently tensored to one another, but may be manipulated further so that they can be + """Deprecation: A class for lazily representing tensor products of Operators. Often Operators + cannot be efficiently tensored to one another, but may be manipulated further so that they can be later. This class holds logic to indicate that the Operators in ``oplist`` are meant to be tensored together, and therefore if they reach a point in which they can be, such as after conversion to QuantumCircuits, they can be reduced by tensor product.""" + @deprecate_function( + "The TensoredOp opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) def __init__( self, oplist: List[OperatorBase], diff --git a/qiskit/opflow/mixins/star_algebra.py b/qiskit/opflow/mixins/star_algebra.py index 30ba75b8ffeb..b8d710fb32ee 100644 --- a/qiskit/opflow/mixins/star_algebra.py +++ b/qiskit/opflow/mixins/star_algebra.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2021. +# (C) Copyright IBM 2021, 2022. # # 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 @@ -16,10 +16,11 @@ from numbers import Integral from qiskit.quantum_info.operators.mixins import MultiplyMixin +from qiskit.utils.deprecation import deprecate_function class StarAlgebraMixin(MultiplyMixin, ABC): - """The star algebra mixin class. + """Deprecation: The star algebra mixin class. Star algebra is an algebra with an adjoint. This class overrides: @@ -39,6 +40,13 @@ class StarAlgebraMixin(MultiplyMixin, ABC): - :meth:`adjoint(self)` """ + @deprecate_function( + "The StarAlgebraMixin opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) + def __init__(self) -> None: + pass + # Scalar multiplication @abstractmethod diff --git a/qiskit/opflow/mixins/tensor.py b/qiskit/opflow/mixins/tensor.py index dfec66d5674d..6bc8ec9fffab 100644 --- a/qiskit/opflow/mixins/tensor.py +++ b/qiskit/opflow/mixins/tensor.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2021. +# (C) Copyright IBM 2021, 2022. # # 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 @@ -14,10 +14,11 @@ from abc import ABC, abstractmethod from numbers import Integral +from qiskit.utils.deprecation import deprecate_function class TensorMixin(ABC): - """The mixin class for tensor operations. + """Deprecation: The mixin class for tensor operations. This class overrides: - ``^``, ``__xor__``, `__rxor__` -> :meth:`tensor` between two operators and @@ -27,6 +28,13 @@ class TensorMixin(ABC): - :meth:``tensorpower(self, other: int)`` """ + @deprecate_function( + "The TensorMixin opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) + def __init__(self) -> None: + pass + def __xor__(self, other): if isinstance(other, Integral): return self.tensorpower(other) diff --git a/qiskit/opflow/operator_base.py b/qiskit/opflow/operator_base.py index 719a8fe99f5a..ff929d90eb22 100644 --- a/qiskit/opflow/operator_base.py +++ b/qiskit/opflow/operator_base.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020, 2021. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -13,6 +13,7 @@ """ OperatorBase Class """ import itertools +import warnings from abc import ABC, abstractmethod from copy import deepcopy from typing import Dict, List, Optional, Set, Tuple, Union, cast @@ -25,10 +26,11 @@ from qiskit.opflow.mixins import StarAlgebraMixin, TensorMixin from qiskit.quantum_info import Statevector from qiskit.utils import algorithm_globals +from qiskit.utils.deprecation import deprecate_function class OperatorBase(StarAlgebraMixin, TensorMixin, ABC): - """A base class for all Operators: PrimitiveOps, StateFns, ListOps, etc. Operators are + """Deprecation: A base class for all Operators: PrimitiveOps, StateFns, ListOps, etc. Operators are defined as functions which take one complex binary function to another. These complex binary functions are represented by StateFns, which are themselves a special class of Operators taking only the ``Zero`` StateFn to the complex binary function they represent. @@ -44,7 +46,14 @@ class OperatorBase(StarAlgebraMixin, TensorMixin, ABC): _count = itertools.count() + @deprecate_function( + "The OperatorBase opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) def __init__(self) -> None: + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + super().__init__() self._instance_id = next(self._count) @property diff --git a/qiskit/opflow/operator_globals.py b/qiskit/opflow/operator_globals.py index 7fb3796ea8a9..31503b671b6c 100644 --- a/qiskit/opflow/operator_globals.py +++ b/qiskit/opflow/operator_globals.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -20,6 +20,7 @@ from qiskit.opflow.primitive_ops.pauli_op import PauliOp from qiskit.opflow.primitive_ops.circuit_op import CircuitOp from qiskit.opflow.state_fns.dict_state_fn import DictStateFn +from qiskit.utils.deprecation import deprecate_function # Digits of precision when returning values from eval functions. Without rounding, 1e-17 or 1e-32 # values often show up in place of 0, etc. @@ -32,8 +33,12 @@ # Immutable convenience objects +@deprecate_function( + "The make_immutable opflow function is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " +) def make_immutable(obj): - """Delete the __setattr__ property to make the object mostly immutable.""" + r"""Deprecate\: Delete the __setattr__ property to make the object mostly immutable.""" # TODO figure out how to get correct error message # def throw_immutability_exception(self, *args): diff --git a/qiskit/opflow/primitive_ops/__init__.py b/qiskit/opflow/primitive_ops/__init__.py index 1af655893599..d5c43ae69313 100644 --- a/qiskit/opflow/primitive_ops/__init__.py +++ b/qiskit/opflow/primitive_ops/__init__.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -16,7 +16,7 @@ .. currentmodule:: qiskit.opflow.primitive_ops -Operators are defined to be functions which take State functions to State functions. +Deprecation: Operators are defined to be functions which take State functions to State functions. PrimitiveOps are the classes for representing basic Operators, backed by computational Operator primitives from Terra. These classes (and inheritors) primarily serve to allow the diff --git a/qiskit/opflow/primitive_ops/circuit_op.py b/qiskit/opflow/primitive_ops/circuit_op.py index 42a9d2657366..3d18783d06ee 100644 --- a/qiskit/opflow/primitive_ops/circuit_op.py +++ b/qiskit/opflow/primitive_ops/circuit_op.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -13,7 +13,7 @@ """CircuitOp Class """ from typing import Dict, List, Optional, Set, Union, cast - +import warnings import numpy as np import qiskit @@ -24,13 +24,18 @@ from qiskit.opflow.operator_base import OperatorBase from qiskit.opflow.primitive_ops.primitive_op import PrimitiveOp from qiskit.quantum_info import Statevector +from qiskit.utils.deprecation import deprecate_function class CircuitOp(PrimitiveOp): - """Class for Operators backed by Terra's ``QuantumCircuit`` module.""" + """Deprecation: Class for Operators backed by Terra's ``QuantumCircuit`` module.""" primitive: QuantumCircuit + @deprecate_function( + "The CircuitOp opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) def __init__( self, primitive: Union[Instruction, QuantumCircuit], @@ -59,7 +64,9 @@ def __init__( if len(primitive.clbits) != 0: raise TypeError("CircuitOp does not support QuantumCircuits with ClassicalRegisters.") - super().__init__(primitive, coeff) + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + super().__init__(primitive, coeff) self._coeff = coeff def primitive_strings(self) -> Set[str]: diff --git a/qiskit/opflow/primitive_ops/matrix_op.py b/qiskit/opflow/primitive_ops/matrix_op.py index 5993bfaba19c..d23e4a99f49e 100644 --- a/qiskit/opflow/primitive_ops/matrix_op.py +++ b/qiskit/opflow/primitive_ops/matrix_op.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -13,7 +13,7 @@ """MatrixOp Class """ from typing import Dict, List, Optional, Set, Union, cast, get_type_hints - +import warnings import numpy as np from scipy.sparse import spmatrix @@ -28,13 +28,19 @@ from qiskit.opflow.primitive_ops.primitive_op import PrimitiveOp from qiskit.quantum_info import Operator, Statevector from qiskit.utils import arithmetic +from qiskit.utils.deprecation import deprecate_function class MatrixOp(PrimitiveOp): - """Class for Operators represented by matrices, backed by Terra's ``Operator`` module.""" + """Deprecation: Class for Operators represented by matrices, + backed by Terra's ``Operator`` module.""" primitive: Operator + @deprecate_function( + "The MatrixOp opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) def __init__( self, primitive: Union[list, np.ndarray, spmatrix, Operator], @@ -67,7 +73,9 @@ def __init__( if primitive.input_dims() != primitive.output_dims(): raise ValueError("Cannot handle non-square matrices yet.") - super().__init__(primitive, coeff=coeff) + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + super().__init__(primitive, coeff=coeff) def primitive_strings(self) -> Set[str]: return {"Matrix"} diff --git a/qiskit/opflow/primitive_ops/pauli_op.py b/qiskit/opflow/primitive_ops/pauli_op.py index 7b5e57a4b4e0..f63f31a37461 100644 --- a/qiskit/opflow/primitive_ops/pauli_op.py +++ b/qiskit/opflow/primitive_ops/pauli_op.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -14,7 +14,7 @@ from math import pi from typing import Dict, List, Optional, Set, Union, cast - +import warnings import numpy as np from scipy.sparse import spmatrix @@ -28,13 +28,18 @@ from qiskit.opflow.operator_base import OperatorBase from qiskit.opflow.primitive_ops.primitive_op import PrimitiveOp from qiskit.quantum_info import Pauli, SparsePauliOp, Statevector +from qiskit.utils.deprecation import deprecate_function class PauliOp(PrimitiveOp): - """Class for Operators backed by Terra's ``Pauli`` module.""" + """Deprecation: Class for Operators backed by Terra's ``Pauli`` module.""" primitive: Pauli + @deprecate_function( + "The PauliOp opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) def __init__(self, primitive: Pauli, coeff: Union[complex, ParameterExpression] = 1.0) -> None: """ Args: @@ -46,7 +51,9 @@ def __init__(self, primitive: Pauli, coeff: Union[complex, ParameterExpression] """ if not isinstance(primitive, Pauli): raise TypeError(f"PauliOp can only be instantiated with Paulis, not {type(primitive)}") - super().__init__(primitive, coeff=coeff) + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + super().__init__(primitive, coeff=coeff) def primitive_strings(self) -> Set[str]: return {"Pauli"} diff --git a/qiskit/opflow/primitive_ops/pauli_sum_op.py b/qiskit/opflow/primitive_ops/pauli_sum_op.py index d0c55ee391d4..0aacf383adf1 100644 --- a/qiskit/opflow/primitive_ops/pauli_sum_op.py +++ b/qiskit/opflow/primitive_ops/pauli_sum_op.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -14,7 +14,7 @@ from collections import defaultdict from typing import Dict, List, Optional, Set, Tuple, Union, cast - +import warnings import numpy as np from scipy.sparse import spmatrix @@ -27,13 +27,18 @@ from qiskit.opflow.primitive_ops.primitive_op import PrimitiveOp from qiskit.quantum_info import Pauli, SparsePauliOp, Statevector from qiskit.quantum_info.operators.custom_iterator import CustomIterator +from qiskit.utils.deprecation import deprecate_function class PauliSumOp(PrimitiveOp): - """Class for Operators backed by Terra's ``SparsePauliOp`` class.""" + """Deprecation: Class for Operators backed by Terra's ``SparsePauliOp`` class.""" primitive: SparsePauliOp + @deprecate_function( + "The PauliSumOp opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) def __init__( self, primitive: SparsePauliOp, @@ -53,8 +58,9 @@ def __init__( raise TypeError( f"PauliSumOp can only be instantiated with SparsePauliOp, not {type(primitive)}" ) - - super().__init__(primitive, coeff=coeff) + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + super().__init__(primitive, coeff=coeff) self._grouping_type = grouping_type def primitive_strings(self) -> Set[str]: diff --git a/qiskit/opflow/primitive_ops/primitive_op.py b/qiskit/opflow/primitive_ops/primitive_op.py index 00ad2d13046b..424d98567699 100644 --- a/qiskit/opflow/primitive_ops/primitive_op.py +++ b/qiskit/opflow/primitive_ops/primitive_op.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -12,6 +12,7 @@ """ PrimitiveOp Class """ +import warnings from typing import Dict, List, Optional, Set, Union, cast import numpy as np @@ -22,11 +23,12 @@ from qiskit.circuit import Instruction, ParameterExpression from qiskit.opflow.operator_base import OperatorBase from qiskit.quantum_info import Operator, Pauli, SparsePauliOp, Statevector +from qiskit.utils.deprecation import deprecate_function class PrimitiveOp(OperatorBase): r""" - A class for representing basic Operators, backed by Operator primitives from + Deprecation: A class for representing basic Operators, backed by Operator primitives from Terra. This class (and inheritors) primarily serves to allow the underlying primitives to "flow" - i.e. interoperability and adherence to the Operator formalism - while the core computational logic mostly remains in the underlying primitives. @@ -92,6 +94,10 @@ def __new__( "factory constructor".format(type(primitive)) ) + @deprecate_function( + "The PrimitiveOp opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) def __init__( self, primitive: Union[QuantumCircuit, Operator, Pauli, SparsePauliOp, OperatorBase], @@ -102,7 +108,9 @@ def __init__( primitive: The operator primitive being wrapped. coeff: A coefficient multiplying the primitive. """ - super().__init__() + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + super().__init__() self._primitive = primitive self._coeff = coeff diff --git a/qiskit/opflow/primitive_ops/tapered_pauli_sum_op.py b/qiskit/opflow/primitive_ops/tapered_pauli_sum_op.py index 97cc441b5b49..d840b33e0583 100644 --- a/qiskit/opflow/primitive_ops/tapered_pauli_sum_op.py +++ b/qiskit/opflow/primitive_ops/tapered_pauli_sum_op.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2021. +# (C) Copyright IBM 2021, 2022. # # 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 @@ -14,6 +14,7 @@ import itertools import logging +import warnings from copy import deepcopy from typing import Dict, List, Optional, Union, cast @@ -27,13 +28,18 @@ from qiskit.opflow.primitive_ops.pauli_sum_op import PauliSumOp from qiskit.opflow.utils import commutator from qiskit.quantum_info import Pauli, SparsePauliOp +from qiskit.utils.deprecation import deprecate_function logger = logging.getLogger(__name__) class TaperedPauliSumOp(PauliSumOp): - """Class for PauliSumOp after tapering""" + """Deprecation: Class for PauliSumOp after tapering""" + @deprecate_function( + "The TaperedPauliSumOp opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) def __init__( self, primitive: SparsePauliOp, @@ -49,7 +55,9 @@ def __init__( Raises: TypeError: invalid parameters. """ - super().__init__(primitive, coeff) + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + super().__init__(primitive, coeff) if not isinstance(z2_symmetries, Z2Symmetries): raise TypeError( f"Argument parameter z2_symmetries must be Z2Symmetries, not {type(z2_symmetries)}" diff --git a/qiskit/opflow/state_fns/__init__.py b/qiskit/opflow/state_fns/__init__.py index 6d71298df145..6c99e0c808cd 100644 --- a/qiskit/opflow/state_fns/__init__.py +++ b/qiskit/opflow/state_fns/__init__.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -14,9 +14,9 @@ State Functions (:mod:`qiskit.opflow.state_fns`) ================================================ -State functions are defined to be complex functions over a single binary string (as -compared to an operator, which is defined as a function over two binary strings, or a -function taking a binary function to another binary function). This function may be +Deprecation: State functions are defined to be complex functions over a single binary +string (as compared to an operator, which is defined as a function over two binary strings, +or a function taking a binary function to another binary function). This function may be called by the eval() method. Measurements are defined to be functionals over StateFns, taking them to real values. diff --git a/qiskit/opflow/state_fns/circuit_state_fn.py b/qiskit/opflow/state_fns/circuit_state_fn.py index 7d5b3a2957de..b8e0e74df9e6 100644 --- a/qiskit/opflow/state_fns/circuit_state_fn.py +++ b/qiskit/opflow/state_fns/circuit_state_fn.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -33,16 +33,21 @@ from qiskit.opflow.state_fns.state_fn import StateFn from qiskit.opflow.state_fns.vector_state_fn import VectorStateFn from qiskit.quantum_info import Statevector +from qiskit.utils.deprecation import deprecate_function class CircuitStateFn(StateFn): r""" - A class for state functions and measurements which are defined by the action of a + Deprecation: A class for state functions and measurements which are defined by the action of a QuantumCircuit starting from \|0⟩, and stored using Terra's ``QuantumCircuit`` class. """ primitive: QuantumCircuit # TODO allow normalization somehow? + @deprecate_function( + "The CircuitStateFn opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) def __init__( self, primitive: Union[QuantumCircuit, Instruction] = None, diff --git a/qiskit/opflow/state_fns/cvar_measurement.py b/qiskit/opflow/state_fns/cvar_measurement.py index dda966dbf0d9..da1637641780 100644 --- a/qiskit/opflow/state_fns/cvar_measurement.py +++ b/qiskit/opflow/state_fns/cvar_measurement.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -28,10 +28,11 @@ from qiskit.opflow.state_fns.state_fn import StateFn from qiskit.opflow.state_fns.vector_state_fn import VectorStateFn from qiskit.quantum_info import Statevector +from qiskit.utils.deprecation import deprecate_function class CVaRMeasurement(OperatorStateFn): - r"""A specialized measurement class to compute CVaR expectation values. + r"""Deprecation: A specialized measurement class to compute CVaR expectation values. See https://arxiv.org/pdf/1907.04769.pdf for further details. Used in :class:`~qiskit.opflow.CVaRExpectation`, see there for more details. @@ -40,6 +41,10 @@ class CVaRMeasurement(OperatorStateFn): primitive: OperatorBase # TODO allow normalization somehow? + @deprecate_function( + "The CVaRMeasurement opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) def __init__( self, primitive: OperatorBase = None, diff --git a/qiskit/opflow/state_fns/dict_state_fn.py b/qiskit/opflow/state_fns/dict_state_fn.py index bfe2c6e4c68b..6025990433af 100644 --- a/qiskit/opflow/state_fns/dict_state_fn.py +++ b/qiskit/opflow/state_fns/dict_state_fn.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020, 2021. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -27,16 +27,21 @@ from qiskit.quantum_info import Statevector from qiskit.result import Result from qiskit.utils import algorithm_globals +from qiskit.utils.deprecation import deprecate_function class DictStateFn(StateFn): - """A class for state functions and measurements which are defined by a lookup table, + """Deprecation: A class for state functions and measurements which are defined by a lookup table, stored in a dict. """ primitive: Dict[str, complex] # TODO allow normalization somehow? + @deprecate_function( + "The DictStateFn opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) def __init__( self, primitive: Union[str, dict, Result] = None, diff --git a/qiskit/opflow/state_fns/operator_state_fn.py b/qiskit/opflow/state_fns/operator_state_fn.py index 8d343faadbcf..f4c07d57d0a1 100644 --- a/qiskit/opflow/state_fns/operator_state_fn.py +++ b/qiskit/opflow/state_fns/operator_state_fn.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -26,16 +26,21 @@ from qiskit.opflow.state_fns.state_fn import StateFn from qiskit.opflow.state_fns.circuit_state_fn import CircuitStateFn from qiskit.quantum_info import Statevector +from qiskit.utils.deprecation import deprecate_function class OperatorStateFn(StateFn): r""" - A class for state functions and measurements which are defined by a density Operator, + Deprecation: A class for state functions and measurements which are defined by a density Operator, stored using an ``OperatorBase``. """ primitive: OperatorBase # TODO allow normalization somehow? + @deprecate_function( + "The OperatorStateFn opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) def __init__( self, primitive: OperatorBase, diff --git a/qiskit/opflow/state_fns/sparse_vector_state_fn.py b/qiskit/opflow/state_fns/sparse_vector_state_fn.py index 935241a2e197..369ee9a91775 100644 --- a/qiskit/opflow/state_fns/sparse_vector_state_fn.py +++ b/qiskit/opflow/state_fns/sparse_vector_state_fn.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020, 2021. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -26,10 +26,11 @@ from qiskit.opflow.state_fns.vector_state_fn import VectorStateFn from qiskit.quantum_info import Statevector from qiskit.utils import algorithm_globals +from qiskit.utils.deprecation import deprecate_function class SparseVectorStateFn(StateFn): - """A class for sparse state functions and measurements in vector representation. + """Deprecation: A class for sparse state functions and measurements in vector representation. This class uses ``scipy.sparse.spmatrix`` for the internal representation. """ @@ -37,6 +38,10 @@ class SparseVectorStateFn(StateFn): primitive: scipy.sparse.spmatrix # TODO allow normalization somehow? + @deprecate_function( + "The SparseVectorStateFn opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) def __init__( self, primitive: scipy.sparse.spmatrix, diff --git a/qiskit/opflow/state_fns/state_fn.py b/qiskit/opflow/state_fns/state_fn.py index d4e689d6b42e..77eff6a150a8 100644 --- a/qiskit/opflow/state_fns/state_fn.py +++ b/qiskit/opflow/state_fns/state_fn.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -12,6 +12,7 @@ """ StateFn Class """ +import warnings from typing import Callable, Dict, List, Optional, Set, Tuple, Union import numpy as np @@ -21,11 +22,12 @@ from qiskit.opflow.operator_base import OperatorBase from qiskit.quantum_info import Statevector from qiskit.result import Result +from qiskit.utils.deprecation import deprecate_function class StateFn(OperatorBase): r""" - A class for representing state functions and measurements. + Deprecation: A class for representing state functions and measurements. State functions are defined to be complex functions over a single binary string (as compared to an operator, which is defined as a function over two binary strings, or a @@ -112,6 +114,10 @@ def __new__( ) # TODO allow normalization somehow? + @deprecate_function( + "The StateFn opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) def __init__( self, primitive: Union[ @@ -134,7 +140,9 @@ def __init__( coeff: A coefficient by which the state function is multiplied. is_measurement: Whether the StateFn is a measurement operator """ - super().__init__() + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + super().__init__() self._primitive = primitive self._is_measurement = is_measurement self._coeff = coeff diff --git a/qiskit/opflow/state_fns/vector_state_fn.py b/qiskit/opflow/state_fns/vector_state_fn.py index c70a0487b123..69b84f5e740f 100644 --- a/qiskit/opflow/state_fns/vector_state_fn.py +++ b/qiskit/opflow/state_fns/vector_state_fn.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020, 2021. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -26,16 +26,21 @@ from qiskit.opflow.state_fns.state_fn import StateFn from qiskit.quantum_info import Statevector from qiskit.utils import algorithm_globals, arithmetic +from qiskit.utils.deprecation import deprecate_function class VectorStateFn(StateFn): - """A class for state functions and measurements which are defined in vector + """Deprecation: A class for state functions and measurements which are defined in vector representation, and stored using Terra's ``Statevector`` class. """ primitive: Statevector # TODO allow normalization somehow? + @deprecate_function( + "The VectorStateFn opflow class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) def __init__( self, primitive: Union[list, np.ndarray, Statevector] = None, diff --git a/qiskit/opflow/utils.py b/qiskit/opflow/utils.py index 439b44ea4661..fc1fbf472cef 100644 --- a/qiskit/opflow/utils.py +++ b/qiskit/opflow/utils.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2022. # # 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 @@ -13,11 +13,16 @@ """ Utility functions for OperatorFlow """ from qiskit.opflow.operator_base import OperatorBase +from qiskit.utils.deprecation import deprecate_function +@deprecate_function( + "The commutator opflow function is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " +) def commutator(op_a: OperatorBase, op_b: OperatorBase) -> OperatorBase: r""" - Compute commutator of `op_a` and `op_b`. + Deprecation: Compute commutator of `op_a` and `op_b`. .. math:: @@ -32,9 +37,13 @@ def commutator(op_a: OperatorBase, op_b: OperatorBase) -> OperatorBase: return (op_a @ op_b - op_b @ op_a).reduce() +@deprecate_function( + "The anti_commutator opflow function is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " +) def anti_commutator(op_a: OperatorBase, op_b: OperatorBase) -> OperatorBase: r""" - Compute anti-commutator of `op_a` and `op_b`. + Deprecation: Compute anti-commutator of `op_a` and `op_b`. .. math:: @@ -49,6 +58,10 @@ def anti_commutator(op_a: OperatorBase, op_b: OperatorBase) -> OperatorBase: return (op_a @ op_b + op_b @ op_a).reduce() +@deprecate_function( + "The double_commutator opflow function is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " +) def double_commutator( op_a: OperatorBase, op_b: OperatorBase, @@ -56,7 +69,7 @@ def double_commutator( sign: bool = False, ) -> OperatorBase: r""" - Compute symmetric double commutator of `op_a`, `op_b` and `op_c`. + Deprecation: Compute symmetric double commutator of `op_a`, `op_b` and `op_c`. See McWeeny chapter 13.6 Equation of motion methods (page 479) If `sign` is `False`, it returns diff --git a/qiskit/test/base.py b/qiskit/test/base.py index 7a3b8146aedc..54537c0e9311 100644 --- a/qiskit/test/base.py +++ b/qiskit/test/base.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2017, 2018. +# (C) Copyright IBM 2017, 2022. # # 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 @@ -227,6 +227,16 @@ def setUpClass(cls): for msg in allow_DeprecationWarning_message: warnings.filterwarnings("default", category=DeprecationWarning, message=msg) + # ignore opflow, QuantumInstance and deprecated function msgs + warnings.filterwarnings("ignore", category=DeprecationWarning, message=r".*opflow.*") + warnings.filterwarnings( + "ignore", category=DeprecationWarning, message=r".*QuantumInstance.*" + ) + warnings.filterwarnings( + "ignore", category=DeprecationWarning, message=r".*find_regs_by_name.*" + ) + warnings.filterwarnings("ignore", category=DeprecationWarning, message=r".*run_circuits.*") + class FullQiskitTestCase(QiskitTestCase): """Terra-specific further additions for test cases, if ``testtools`` is available. diff --git a/qiskit/utils/quantum_instance.py b/qiskit/utils/quantum_instance.py index 4268678f3677..8fbd7efa42fd 100644 --- a/qiskit/utils/quantum_instance.py +++ b/qiskit/utils/quantum_instance.py @@ -38,6 +38,7 @@ CompleteMeasFitter, TensoredMeasFitter, ) +from qiskit.utils.deprecation import deprecate_function logger = logging.getLogger(__name__) @@ -124,7 +125,7 @@ def type_from_instance(meas_instance): class QuantumInstance: - """Quantum Backend including execution setting.""" + """Deprecation: Quantum Backend including execution setting.""" _BACKEND_CONFIG = ["basis_gates", "coupling_map"] _COMPILE_CONFIG = ["initial_layout", "seed_transpiler", "optimization_level"] @@ -143,6 +144,10 @@ class QuantumInstance: "statevector_hpc_gate_opt", ] + _BACKEND_OPTIONS_QASM_ONLY + @deprecate_function( + "The QuantumInstance class is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " + ) def __init__( self, backend, diff --git a/qiskit/utils/run_circuits.py b/qiskit/utils/run_circuits.py index 27d3e5e3e27c..f86433c481b3 100644 --- a/qiskit/utils/run_circuits.py +++ b/qiskit/utils/run_circuits.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2018, 2021. +# (C) Copyright IBM 2018, 2022. # # 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 @@ -23,6 +23,7 @@ from qiskit.providers import Backend, JobStatus, JobError, Job from qiskit.providers.jobstatus import JOB_FINAL_STATES from qiskit.result import Result +from qiskit.utils.deprecation import deprecate_function from ..exceptions import QiskitError, MissingOptionalLibraryError from .backend_utils import ( is_aer_provider, @@ -39,10 +40,14 @@ logger = logging.getLogger(__name__) +@deprecate_function( + "The find_regs_by_name function is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " +) def find_regs_by_name( circuit: QuantumCircuit, name: str, qreg: bool = True ) -> Optional[Union[QuantumRegister, ClassicalRegister]]: - """Find the registers in the circuits. + """Deprecation: Find the registers in the circuits. Args: circuit: the quantum circuit. @@ -101,6 +106,10 @@ def _safe_get_job_status(job: Job, job_id: str, max_job_retries: int, wait: floa return job_status +@deprecate_function( + "The run_circuits function is deprecated as of Qiskit Terra 0.23.0 " + "and will be removed no sooner than 3 months after the release date. " +) def run_circuits( circuits: Union[QuantumCircuit, List[QuantumCircuit]], backend: Backend, @@ -112,7 +121,7 @@ def run_circuits( max_job_retries: int = 50, ) -> Result: """ - An execution wrapper with Qiskit-Terra, with job auto recover capability. + Deprecation: An execution wrapper with Qiskit-Terra, with job auto recover capability. The auto-recovery feature is only applied for non-simulator backend. This wrapper will try to get the result no matter how long it takes. diff --git a/releasenotes/notes/deprecate-opflow-qi-32f7e27884deea3f.yaml b/releasenotes/notes/deprecate-opflow-qi-32f7e27884deea3f.yaml new file mode 100644 index 000000000000..f9d9bce666be --- /dev/null +++ b/releasenotes/notes/deprecate-opflow-qi-32f7e27884deea3f.yaml @@ -0,0 +1,7 @@ +--- +deprecations: + - | + The module :mod:`qiskit.opflow`, class :class:`qiskit.utils.QuantumInstance` and methods + :meth:`~qiskit.utils.run_circuits.find_regs_by_name`, + :meth:`~qiskit.utils.run_circuits.run_circuits` + have been deprecated and will be removed in a future release.