Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated opflow module, QuantumInstance and related utils #11111

Merged
merged 16 commits into from
Nov 24, 2023
13 changes: 0 additions & 13 deletions docs/apidoc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,3 @@ API Reference
utils
utils_mitigation
exceptions

Deprecated Modules
==================

.. warning::

These modules are going to be removed in Qiskit 1.0. Consider pinning ``qiskit~=0.45`` in your dependencies if you need them.

.. toctree::
:maxdepth: 1

algorithms
opflow
6 changes: 0 additions & 6 deletions docs/apidoc/opflow.rst

This file was deleted.

6 changes: 0 additions & 6 deletions docs/apidoc/utils_mitigation.rst

This file was deleted.

35 changes: 5 additions & 30 deletions qiskit/circuit/library/evolved_operator_ansatz.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from qiskit.circuit.parameter import Parameter
from qiskit.circuit.quantumregister import QuantumRegister
from qiskit.circuit.quantumcircuit import QuantumCircuit
from qiskit.exceptions import QiskitError
from qiskit.quantum_info import Operator, Pauli, SparsePauliOp
from qiskit.synthesis.evolution import LieTrotter

Expand All @@ -44,15 +43,14 @@ def __init__(
):
"""
Args:
operators (BaseOperator | OperatorBase | QuantumCircuit | list | None): The operators
operators (BaseOperator | QuantumCircuit | list | None): The operators
to evolve. If a circuit is passed, we assume it implements an already evolved
operator and thus the circuit is not evolved again. Can be a single operator
(circuit) or a list of operators (and circuits).
reps: The number of times to repeat the evolved operators.
evolution (EvolutionBase | EvolutionSynthesis | None):
A specification of which evolution synthesis to use for the
:class:`.PauliEvolutionGate`, if the operator is from :mod:`qiskit.quantum_info`
or an opflow converter object if the operator is from :mod:`qiskit.opflow`.
:class:`.PauliEvolutionGate`.
Defaults to first order Trotterization.
insert_barriers: Whether to insert barriers in between each evolution.
name: The name of the circuit.
Expand Down Expand Up @@ -113,13 +111,8 @@ def evolution(self):
"""The evolution converter used to compute the evolution.

Returns:
EvolutionBase or EvolutionSynthesis: The evolution converter used to compute the evolution.
EvolutionSynthesis: The evolution converter used to compute the evolution.
"""
if self._evolution is None:
# pylint: disable=cyclic-import
from qiskit.opflow import PauliTrotterEvolution

return PauliTrotterEvolution()

return self._evolution

Expand All @@ -128,8 +121,7 @@ def evolution(self, evol) -> None:
"""Sets the evolution converter used to compute the evolution.

Args:
evol (EvolutionBase | EvolutionSynthesis): An evolution synthesis object or
opflow converter object to construct the evolution.
evol (EvolutionSynthesis): An evolution synthesis object
"""
self._invalidate()
self._evolution = evol
Expand All @@ -147,7 +139,7 @@ def operators(self):
def operators(self, operators=None) -> None:
"""Set the operators to be evolved.

operators (Optional[Union[OperatorBase, QuantumCircuit, list]): The operators to evolve.
operators (Optional[Union[QuantumCircuit, list]): The operators to evolve.
ElePT marked this conversation as resolved.
Show resolved Hide resolved
If a circuit is passed, we assume it implements an already evolved operator and thus
the circuit is not evolved again. Can be a single operator (circuit) or a list of
operators (and circuits).
Expand All @@ -174,21 +166,10 @@ def preferred_init_points(self):
return np.zeros(self.reps * len(self.operators), dtype=float)

def _evolve_operator(self, operator, time):
from qiskit.opflow import OperatorBase, EvolutionBase

# pylint: disable=cyclic-import
from qiskit.circuit.library.hamiltonian_gate import HamiltonianGate

if isinstance(operator, OperatorBase):
if not isinstance(self.evolution, EvolutionBase):
raise QiskitError(
"If qiskit.opflow operators are evolved the evolution must be a "
f"qiskit.opflow.EvolutionBase, not a {type(self.evolution)}."
)

evolved = self.evolution.convert((time * operator).exp_i())
return evolved.reduce().to_circuit()

# if the operator is specified as matrix use exact matrix exponentiation
if isinstance(operator, Operator):
gate = HamiltonianGate(operator, time)
Expand Down Expand Up @@ -254,17 +235,11 @@ def _validate_prefix(parameter_prefix, operators):


def _is_pauli_identity(operator):
from qiskit.opflow import PauliOp, PauliSumOp

if isinstance(operator, PauliSumOp):
operator = operator.to_pauli_op()
if isinstance(operator, SparsePauliOp):
if len(operator.paulis) == 1:
operator = operator.paulis[0] # check if the single Pauli is identity below
else:
return False
if isinstance(operator, PauliOp):
operator = operator.primitive
if isinstance(operator, Pauli):
return not np.any(np.logical_or(operator.x, operator.z))
return False
24 changes: 7 additions & 17 deletions qiskit/circuit/library/pauli_evolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ class PauliEvolutionGate(Gate):

from qiskit.circuit import QuantumCircuit
from qiskit.circuit.library import PauliEvolutionGate
from qiskit.opflow import I, Z, X
from qiskit.quantum_info import SparsePauliOp

X = SparsePauliOp("X")
Z = SparsePauliOp("Z")

# build the evolution gate
operator = (Z ^ Z) - 0.1 * (X ^ I)
Expand Down Expand Up @@ -86,7 +89,7 @@ def __init__(
) -> None:
"""
Args:
operator (Pauli | PauliOp | SparsePauliOp | PauliSumOp | list):
operator (Pauli | SparsePauliOp | list):
The operator to evolve. Can also be provided as list of non-commuting
operators where the elements are sums of commuting operators.
For example: ``[XY + YX, ZZ + ZI + IZ, YY]``.
Expand Down Expand Up @@ -147,22 +150,9 @@ def validate_parameter(


def _to_sparse_pauli_op(operator):
"""Cast the operator to a SparsePauliOp.
"""Cast the operator to a SparsePauliOp."""

For Opflow objects, return a global coefficient that must be multiplied to the evolution time.
Since this coefficient might contain unbound parameters it cannot be absorbed into the
coefficients of the SparsePauliOp.
"""
# pylint: disable=cyclic-import
from qiskit.opflow import PauliSumOp, PauliOp

if isinstance(operator, PauliSumOp):
sparse_pauli = operator.primitive
sparse_pauli._coeffs *= operator.coeff
elif isinstance(operator, PauliOp):
sparse_pauli = SparsePauliOp(operator.primitive)
sparse_pauli._coeffs *= operator.coeff
elif isinstance(operator, Pauli):
if isinstance(operator, Pauli):
sparse_pauli = SparsePauliOp(operator)
elif isinstance(operator, SparsePauliOp):
sparse_pauli = operator
Expand Down
Loading
Loading