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 Dec 12, 2022
1 parent 995b4bf commit 6b39927
Show file tree
Hide file tree
Showing 49 changed files with 128 additions and 233 deletions.
12 changes: 7 additions & 5 deletions qiskit/opflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
.. currentmodule:: qiskit.opflow
Deprecation: Operators and State functions are the building blocks of Quantum Algorithms.
.. deprecated:: 0.23.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
30 changes: 16 additions & 14 deletions qiskit/opflow/converters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.23.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
5 changes: 1 addition & 4 deletions qiskit/opflow/converters/abelian_grouper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -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
5 changes: 1 addition & 4 deletions qiskit/opflow/converters/circuit_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@


import logging
import warnings
from functools import partial
from time import time
from typing import Any, Dict, List, Optional, Tuple, Union, cast
Expand Down Expand Up @@ -82,9 +81,7 @@ def __init__(
Raises:
ValueError: Set statevector or param_qobj True when not supported by backend.
"""
with warnings.catch_warnings():
warnings.simplefilter("ignore")
super().__init__()
super().__init__()
self._quantum_instance = (
backend if isinstance(backend, QuantumInstance) else QuantumInstance(backend=backend)
)
Expand Down
5 changes: 1 addition & 4 deletions qiskit/opflow/converters/dict_to_circuit_sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 Down Expand Up @@ -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
5 changes: 1 addition & 4 deletions qiskit/opflow/converters/pauli_basis_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -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
5 changes: 1 addition & 4 deletions qiskit/opflow/converters/two_qubit_reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
""" Z2 Symmetry Tapering Converter Class """

import logging
import warnings
from typing import List, Tuple, Union, cast

from qiskit.opflow.converters.converter_base import ConverterBase
Expand Down Expand Up @@ -47,9 +46,7 @@ def __init__(self, num_particles: Union[int, List[int], Tuple[int, int]]):
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__()
super().__init__()
if isinstance(num_particles, (tuple, list)):
num_alpha = num_particles[0]
num_beta = num_particles[1]
Expand Down
26 changes: 14 additions & 12 deletions qiskit/opflow/evolutions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,20 @@
.. currentmodule:: qiskit.opflow.evolutions
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.
The :class:`EvolvedOp` is simply a placeholder signifying that the Operator inside it should be
converted to its exponential by the Evolution converter. All Operators
(not :mod:`~qiskit.opflow.state_fns`) have
``.exp_i()`` methods which either return the exponential of the Operator directly,
or an :class:`EvolvedOp` containing the Operator.
.. deprecated:: 0.23.0
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.
The :class:`EvolvedOp` is simply a placeholder signifying that the Operator inside it should be
converted to its exponential by the Evolution converter. All Operators
(not :mod:`~qiskit.opflow.state_fns`) have
``.exp_i()`` methods which either return the exponential of the Operator directly,
or an :class:`EvolvedOp` containing the Operator.
Note:
Evolutions work with parameterized Operator coefficients, so
Expand Down
5 changes: 1 addition & 4 deletions qiskit/opflow/evolutions/evolution_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

""" EvolutionBase Class """

import warnings
from abc import ABC, abstractmethod

from qiskit.opflow.operator_base import OperatorBase
Expand All @@ -36,9 +35,7 @@ class EvolutionBase(ConverterBase, ABC):
"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__()
super().__init__()

@abstractmethod
def convert(self, operator: OperatorBase) -> OperatorBase:
Expand Down
5 changes: 1 addition & 4 deletions qiskit/opflow/evolutions/evolved_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

""" EvolutionOp Class """

import warnings
from typing import List, Optional, Set, Union, cast

import numpy as np
Expand Down Expand Up @@ -53,9 +52,7 @@ def __init__(
primitive: The operator being wrapped to signify evolution later.
coeff: A coefficient multiplying the operator
"""
with warnings.catch_warnings():
warnings.simplefilter("ignore")
super().__init__(primitive, coeff=coeff)
super().__init__(primitive, coeff=coeff)

def primitive_strings(self) -> Set[str]:
return self.primitive.primitive_strings()
Expand Down
5 changes: 1 addition & 4 deletions qiskit/opflow/evolutions/matrix_evolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

""" MatrixEvolution Class """

import warnings
import logging

from qiskit.opflow.evolutions.evolution_base import EvolutionBase
Expand All @@ -37,9 +36,7 @@ class MatrixEvolution(EvolutionBase):
"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__()
super().__init__()

def convert(self, operator: OperatorBase) -> OperatorBase:
r"""
Expand Down
5 changes: 1 addition & 4 deletions qiskit/opflow/evolutions/pauli_trotter_evolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

""" PauliTrotterEvolution Class """

import warnings
import logging
from typing import Optional, Union, cast

Expand Down Expand Up @@ -75,9 +74,7 @@ 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__()
super().__init__()
if isinstance(trotter_mode, TrotterizationBase):
self._trotter = trotter_mode
else:
Expand Down
5 changes: 3 additions & 2 deletions qiskit/opflow/evolutions/trotterizations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
# that they have been altered from the originals.

"""
Deprecation: Trotterization methods - Algorithms for
approximating Exponentials of Operator Sums.
.. deprecated:: 0.23.0
Trotterization methods - Algorithms for
approximating Exponentials of Operator Sums.
"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

""" Trotterization Algorithm Base """

import warnings
from abc import abstractmethod

from qiskit.opflow.evolutions.evolution_base import EvolutionBase
Expand All @@ -32,9 +31,7 @@ class TrotterizationBase(EvolutionBase):
"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__()
super().__init__()
self._reps = reps

@property
Expand Down
24 changes: 13 additions & 11 deletions qiskit/opflow/expectations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@
.. currentmodule:: qiskit.opflow.expectations
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
function, but only has access to diagonal measurements on Quantum hardware, we can create a
measurement ~StateFn(o), use a :class:`PauliExpectation` to convert it to a diagonal measurement
and circuit pre-rotations to append to the state, and sample this circuit on Quantum hardware with
a :class:`~qiskit.opflow.converters.CircuitSampler`. All in all, this would be:
``my_sampler.convert(my_expect.convert(~StateFn(o)) @ my_state).eval()``.
.. deprecated:: 0.23.0
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
function, but only has access to diagonal measurements on Quantum hardware, we can create a
measurement ~StateFn(o), use a :class:`PauliExpectation` to convert it to a diagonal measurement
and circuit pre-rotations to append to the state, and sample this circuit on Quantum hardware with
a :class:`~qiskit.opflow.converters.CircuitSampler`. All in all, this would be:
``my_sampler.convert(my_expect.convert(~StateFn(o)) @ my_state).eval()``.
Expectation Base Class
----------------------
Expand Down
5 changes: 1 addition & 4 deletions qiskit/opflow/expectations/aer_pauli_expectation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

""" AerPauliExpectation Class """

import warnings
import logging
from functools import reduce
from operator import add
Expand Down Expand Up @@ -45,9 +44,7 @@ class AerPauliExpectation(ExpectationBase):
"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__()
super().__init__()

def convert(self, operator: OperatorBase) -> OperatorBase:
"""Accept an Operator and return a new Operator with the Pauli measurements replaced by
Expand Down
5 changes: 1 addition & 4 deletions qiskit/opflow/expectations/cvar_expectation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

"""The CVaR (Conditional Value at Risk) expectation class."""

import warnings
from typing import Optional, Union

from qiskit.opflow.expectations.aer_pauli_expectation import AerPauliExpectation
Expand Down Expand Up @@ -70,9 +69,7 @@ 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__()
super().__init__()
self.alpha = alpha
if isinstance(expectation, AerPauliExpectation):
raise NotImplementedError("AerPauliExpecation currently not supported.")
Expand Down
Loading

0 comments on commit 6b39927

Please sign in to comment.