Skip to content

Commit

Permalink
Add .. deprecated:: to init modules
Browse files Browse the repository at this point in the history
  • Loading branch information
manoelmarques committed Jan 8, 2023
1 parent 1bcb65d commit e1c28d2
Show file tree
Hide file tree
Showing 110 changed files with 1,524 additions and 995 deletions.
9 changes: 2 additions & 7 deletions qiskit/algorithms/evolvers/trotterization/trotter_qrte.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,18 @@ class TrotterQRTE(RealEvolver):
Examples::
import warnings
from qiskit.opflow import X, Z, Zero
from qiskit.algorithms import EvolutionProblem, TrotterQRTE
from qiskit import BasicAer
from qiskit.utils import QuantumInstance
with warnings.catch_warnings():
warnings.simplefilter("ignore")
operator = X + Z
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")
with warnings.catch_warnings():
warnings.simplefilter("ignore")
quantum_instance = QuantumInstance(backend=backend)
quantum_instance = QuantumInstance(backend=backend)
trotter_qrte = TrotterQRTE(quantum_instance=quantum_instance)
evolved_state = trotter_qrte.evolve(evolution_problem).evolved_state
"""
Expand Down
11 changes: 3 additions & 8 deletions qiskit/algorithms/linear_solvers/observables/absolute_average.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2020, 2022.
# (C) Copyright IBM 2020, 2023.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand Down Expand Up @@ -31,16 +31,13 @@ class AbsoluteAverage(LinearSystemObservable):
Examples::
import warnings
import numpy as np
from qiskit import QuantumCircuit
from qiskit.algorithms.linear_solvers.observables.absolute_average import \
AbsoluteAverage
from qiskit.opflow import StateFn
with warnings.catch_warnings():
warnings.simplefilter('ignore')
observable = AbsoluteAverage()
observable = AbsoluteAverage()
vector = [1.0, -2.1, 3.2, -4.3]
init_state = vector / np.linalg.norm(vector)
Expand All @@ -52,9 +49,7 @@ class AbsoluteAverage(LinearSystemObservable):
# Observable operator
observable_op = observable.observable(num_qubits)
with warnings.catch_warnings():
warnings.simplefilter('ignore')
state_vec = (~StateFn(observable_op) @ StateFn(qc)).eval()
state_vec = (~StateFn(observable_op) @ StateFn(qc)).eval()
# Obtain result
result = observable.post_processing(state_vec, num_qubits)
Expand Down
17 changes: 6 additions & 11 deletions qiskit/algorithms/linear_solvers/observables/matrix_functional.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2020, 2022.
# (C) Copyright IBM 2020, 2023.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand Down Expand Up @@ -30,7 +30,6 @@ class MatrixFunctional(LinearSystemObservable):
Examples::
import warnings
import numpy as np
from qiskit import QuantumCircuit
from qiskit.algorithms.linear_solvers.observables.matrix_functional import \
Expand All @@ -41,9 +40,7 @@ class MatrixFunctional(LinearSystemObservable):
tpass = RemoveResetInZeroState()
vector = [1.0, -2.1, 3.2, -4.3]
with warnings.catch_warnings():
warnings.simplefilter('ignore')
observable = MatrixFunctional(1, -1 / 3)
observable = MatrixFunctional(1, -1 / 3)
init_state = vector / np.linalg.norm(vector)
num_qubits = int(np.log2(len(vector)))
Expand All @@ -61,12 +58,10 @@ class MatrixFunctional(LinearSystemObservable):
observable_ops = observable.observable(num_qubits)
state_vecs = []
# First is the norm
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()]
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)
Expand Down
14 changes: 8 additions & 6 deletions qiskit/opflow/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2019, 2022.
# (C) Copyright IBM 2019, 2023.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand All @@ -17,7 +17,9 @@
.. currentmodule:: qiskit.opflow
Deprecation: Operators and State functions are the building blocks of Quantum Algorithms.
.. deprecated:: 0.24.0
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
Expand Down Expand Up @@ -77,7 +79,7 @@
Operator Base Class
===================
Deprecation: The OperatorBase serves as the base class for all Operators, State functions
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.
Expand All @@ -91,7 +93,7 @@
Operator Globals
================
Deprecation: The :mod:`operator_globals` is a set of immutable Operator instances that are
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:
Expand All @@ -109,7 +111,7 @@
Operators
---------
Deprecation: The Operators submodules include the PrimitiveOp, ListOp, and StateFn class
The Operators submodules include the PrimitiveOp, ListOp, and StateFn class
groups which represent the primary Operator modules.
.. autosummary::
Expand All @@ -123,7 +125,7 @@
Converters
----------
Deprecation: The Converter submodules include objects which manipulate Operators,
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
Expand Down
32 changes: 17 additions & 15 deletions qiskit/opflow/converters/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2020, 2022.
# (C) Copyright IBM 2020, 2023.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand All @@ -16,20 +16,22 @@
.. currentmodule:: qiskit.opflow.converters
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
:class:`~qiskit.opflow.list_ops.SummedOp` of
:class:`~qiskit.opflow.primitive_ops.PauliOp`'s representing the
circuit unitary. Converters may not have polynomial space or time scaling in their operations.
On the contrary, many converters, such as a
:class:`~qiskit.opflow.expectations.MatrixExpectation` or
:class:`~qiskit.opflow.evolutions.MatrixEvolution`,
which convert :class:`~qiskit.opflow.primitive_ops.PauliOp`'s to
:class:`~qiskit.opflow.primitive_ops.MatrixOp`'s internally, will require time or space
exponential in the number of qubits unless a clever trick is known
(such as the use of sparse matrices).
.. deprecated:: 0.24.0
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
:class:`~qiskit.opflow.list_ops.SummedOp` of
:class:`~qiskit.opflow.primitive_ops.PauliOp`'s representing the
circuit unitary. Converters may not have polynomial space or time scaling in their operations.
On the contrary, many converters, such as a
:class:`~qiskit.opflow.expectations.MatrixExpectation` or
:class:`~qiskit.opflow.evolutions.MatrixEvolution`,
which convert :class:`~qiskit.opflow.primitive_ops.PauliOp`'s to
:class:`~qiskit.opflow.primitive_ops.MatrixOp`'s internally, will require time or space
exponential in the number of qubits unless a clever trick is known
(such as the use of sparse matrices).
Note:
Not all converters are in this module, as :mod:`~qiskit.opflow.expectations`
Expand Down
9 changes: 3 additions & 6 deletions qiskit/opflow/converters/abelian_grouper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2020, 2022.
# (C) Copyright IBM 2020, 2023.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand All @@ -13,7 +13,6 @@
"""AbelianGrouper Class"""

from collections import defaultdict
import warnings
from typing import List, Tuple, Union, cast

import numpy as np
Expand Down Expand Up @@ -44,7 +43,7 @@ class AbelianGrouper(ConverterBase):
"""

@deprecate_function(
"The AbelianGrouper opflow class is deprecated as of Qiskit Terra 0.23.0 "
"The AbelianGrouper opflow class is deprecated as of Qiskit Terra 0.24.0 "
"and will be removed no sooner than 3 months after the release date. "
)
def __init__(self, traverse: bool = True) -> None:
Expand All @@ -53,9 +52,7 @@ def __init__(self, traverse: bool = True) -> None:
traverse: Whether to convert only the Operator passed to ``convert``, or traverse
down that Operator.
"""
with warnings.catch_warnings():
warnings.simplefilter("ignore")
super().__init__()
super().__init__()
self._traverse = traverse

def convert(self, operator: OperatorBase) -> OperatorBase:
Expand Down
20 changes: 11 additions & 9 deletions qiskit/opflow/converters/circuit_sampler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2020, 2022.
# (C) Copyright IBM 2020, 2023.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand Down Expand Up @@ -54,7 +54,7 @@ class CircuitSampler(ConverterBase):
"""

@deprecate_function(
"The CircuitSampler opflow class is deprecated as of Qiskit Terra 0.23.0 "
"The CircuitSampler opflow class is deprecated as of Qiskit Terra 0.24.0 "
"and will be removed no sooner than 3 months after the release date. "
)
def __init__(
Expand Down Expand Up @@ -82,15 +82,17 @@ def __init__(
Raises:
ValueError: Set statevector or param_qobj True when not supported by backend.
"""
super().__init__()
with warnings.catch_warnings():
warnings.simplefilter("ignore")
super().__init__()
self._quantum_instance = (
backend if isinstance(backend, QuantumInstance) else QuantumInstance(backend=backend)
)
self._statevector = (
statevector if statevector is not None else self.quantum_instance.is_statevector
)
self._quantum_instance = (
backend
if isinstance(backend, QuantumInstance)
else QuantumInstance(backend=backend)
)
self._statevector = (
statevector if statevector is not None else self.quantum_instance.is_statevector
)
self._param_qobj = param_qobj
self._attach_results = attach_results

Expand Down
4 changes: 2 additions & 2 deletions qiskit/opflow/converters/converter_base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2020, 2022.
# (C) Copyright IBM 2020, 2023.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand Down Expand Up @@ -31,7 +31,7 @@ class ConverterBase(ABC):
matrices)."""

@deprecate_function(
"The ConverterBase opflow class is deprecated as of Qiskit Terra 0.23.0 "
"The ConverterBase opflow class is deprecated as of Qiskit Terra 0.24.0 "
"and will be removed no sooner than 3 months after the release date. "
)
def __init__(self) -> None:
Expand Down
9 changes: 3 additions & 6 deletions qiskit/opflow/converters/dict_to_circuit_sum.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2020, 2022.
# (C) Copyright IBM 2020, 2023.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand All @@ -12,7 +12,6 @@

"""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
Expand All @@ -31,7 +30,7 @@ class DictToCircuitSum(ConverterBase):
"""

@deprecate_function(
"The DictToCircuitSum opflow class is deprecated as of Qiskit Terra 0.23.0 "
"The DictToCircuitSum opflow class is deprecated as of Qiskit Terra 0.24.0 "
"and will be removed no sooner than 3 months after the release date. "
)
def __init__(
Expand All @@ -44,9 +43,7 @@ def __init__(
convert_dicts: Whether to convert VectorStateFn.
convert_vectors: Whether to convert DictStateFns.
"""
with warnings.catch_warnings():
warnings.simplefilter("ignore")
super().__init__()
super().__init__()
self._traverse = traverse
self._convert_dicts = convert_dicts
self._convert_vectors = convert_vectors
Expand Down
9 changes: 3 additions & 6 deletions qiskit/opflow/converters/pauli_basis_change.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2020, 2022.
# (C) Copyright IBM 2020, 2023.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand All @@ -12,7 +12,6 @@

""" PauliBasisChange Class """

import warnings
from functools import partial, reduce
from typing import Callable, List, Optional, Tuple, Union, cast

Expand Down Expand Up @@ -58,7 +57,7 @@ class PauliBasisChange(ConverterBase):
"""

@deprecate_function(
"The PauliBasisChange opflow class is deprecated as of Qiskit Terra 0.23.0 "
"The PauliBasisChange opflow class is deprecated as of Qiskit Terra 0.24.0 "
"and will be removed no sooner than 3 months after the release date. "
)
def __init__(
Expand Down Expand Up @@ -89,9 +88,7 @@ def __init__(
beginning and ending operators are equivalent.
"""
with warnings.catch_warnings():
warnings.simplefilter("ignore")
super().__init__()
super().__init__()
if destination_basis is not None:
self.destination = destination_basis # type: ignore
else:
Expand Down
Loading

0 comments on commit e1c28d2

Please sign in to comment.