Skip to content

Commit

Permalink
Remove deprecated opflow module, QuantumInstance and related `uti…
Browse files Browse the repository at this point in the history
…ls` (#11111)

* Remove code, tests, fix tests

* Remove opflow from docs

* Remove opflow references

* Fix lint, fix docs

* Fix test

* Remove redundant test

* Add release note

* Remove redirects

* Update docs index

* Fix conflict

* Fix docs

* Apply suggestions from Jake's code review

Co-authored-by: Jake Lishman <[email protected]>

---------

Co-authored-by: Jake Lishman <[email protected]>
  • Loading branch information
ElePT and jakelishman authored Nov 24, 2023
1 parent b2a1f75 commit 20839da
Show file tree
Hide file tree
Showing 122 changed files with 113 additions and 24,862 deletions.
9 changes: 0 additions & 9 deletions docs/api_redirects.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
qiskit.algorithms.AlgorithmError algorithms
qiskit.algorithms.eval_observables algorithms
qiskit.algorithms.estimate_observables algorithms

qiskit.assembler.assemble_circuits assembler
qiskit.assembler.assemble_schedules assembler
qiskit.assembler.disassemble assembler
Expand Down Expand Up @@ -97,11 +93,6 @@ qiskit.converters.dagdependency_to_dag converters

qiskit.dagcircuit.DAGCircuitError dagcircuit

qiskit.opflow.commutator opflow
qiskit.opflow.anti_commutator opflow
qiskit.opflow.double_commutator opflow
qiskit.opflow.OpflowError opflow

qiskit.providers.QiskitBackendNotFoundError providers
qiskit.providers.BackendPropertyError providers
qiskit.providers.JobError providers
Expand Down
13 changes: 0 additions & 13 deletions docs/apidoc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,4 @@ API Reference
transpiler_synthesis_plugins
transpiler_builtin_plugins
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

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.

4 changes: 2 additions & 2 deletions docs/migration_guides/opflow_migration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ The functional equivalency can be roughly summarized as follows:

* - Opflow Module
- Alternative
* - Operators (:class:`~qiskit.opflow.OperatorBase`, :ref:`operator_globals`,
* - Operators (:class:`~qiskit.opflow.OperatorBase`, ``operator_globals``,
:mod:`~qiskit.opflow.primitive_ops`, :mod:`~qiskit.opflow.list_ops`)
- ``qiskit.quantum_info`` :ref:`Operators <quantum_info_operators>`

Expand Down Expand Up @@ -134,7 +134,7 @@ Operator Globals
*Back to* `Contents`_

Opflow provided shortcuts to define common single qubit states, operators, and non-parametrized gates in the
:ref:`operator_globals` module.
``operator_globals`` module.

These were mainly used for didactic purposes or quick prototyping, and can easily be replaced by their corresponding
:mod:`~qiskit.quantum_info` class: :class:`~qiskit.quantum_info.Pauli`, :class:`~qiskit.quantum_info.Clifford` or
Expand Down
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.
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

0 comments on commit 20839da

Please sign in to comment.