Skip to content

Commit

Permalink
undeprecate utils
Browse files Browse the repository at this point in the history
  • Loading branch information
1ucian0 committed Jul 25, 2024
1 parent 4759838 commit 3a10a0c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 46 deletions.
16 changes: 0 additions & 16 deletions qiskit/primitives/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,8 @@
from qiskit.quantum_info import PauliList, SparsePauliOp, Statevector
from qiskit.quantum_info.operators.base_operator import BaseOperator
from qiskit.quantum_info.operators.symplectic.base_pauli import BasePauli
from qiskit.utils.deprecation import deprecate_func


@deprecate_func(
since="1.2",
additional_msg="To initialize a circuit from a ``Statevector`` instance, "
+ "use ``QuantumCircuit.initialize`` instead.",
)
def init_circuit(state: QuantumCircuit | Statevector) -> QuantumCircuit:
"""Initialize state by converting the input to a quantum circuit.
Expand All @@ -51,10 +45,6 @@ def init_circuit(state: QuantumCircuit | Statevector) -> QuantumCircuit:
return qc


@deprecate_func(
since="1.2",
additional_msg="Use the constructor of ``SparsePauliOp`` instead.",
)
def init_observable(observable: BaseOperator | str) -> SparsePauliOp:
"""Initialize observable by converting the input to a :class:`~qiskit.quantum_info.SparsePauliOp`.
Expand All @@ -78,12 +68,6 @@ def init_observable(observable: BaseOperator | str) -> SparsePauliOp:
return SparsePauliOp(observable)


@deprecate_func(
since="1.2",
additional_msg="Use ``QuantumCircuit.layout`` and ``SparsePauliOp.apply_layout`` "
+ "to adjust an operator for a layout. Otherwise, use ``mthree.utils.final_measurement_mapping``. "
+ "See https://qiskit-extensions.github.io/mthree/apidocs/utils.html for details.",
)
def final_measurement_mapping(circuit: QuantumCircuit) -> dict[int, int]:
"""Return the final measurement mapping for the circuit.
Expand Down
25 changes: 6 additions & 19 deletions releasenotes/notes/deprecate-non-versioned-primitives.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,9 @@ deprecations_primitives:
The following classes are deprecated:
* :class:`.BaseEstimator` as :class:`.BaseEstimatorV1` alias. However, :class:`.BaseEstimatorV2` is recommended instead.
* :class:`.BaseSampler` as :class:`.BaseSamplerV1` alias. However, :class:`.BaseSamplerV2` is recommended instead.
* :class:`.Estimator` as :class:`.EstimatorV1` alias. However, :class:`.EstimatorV2` is recommended instead.
* :class:`.Sampler` as :class:`.SamplerV1` alias. However, :class:`.SamplerV2` is recommended instead.
* :class:`.BackendEstimator` as :class:`.BackendEstimatorV1` alias. However, :class:`.BackendEstimatorV2` is recommended instead.
* :class:`.BackendSampler` as :class:`.BackendSamplerV1` alias. However, :class:`.BackendSamplerV2` is recommended instead.
In addition, the following utility functions are deprecated:
* :func:`.init_circuit`, to initialize a circuit from a :class:`.Statevector`,
use :meth:`.QuantumCircuit.initialize` instead,
* :func:`.init_observable`, use the constructor of :class:`.SparsePauliOp` instead,
* :func:`.final_measurement_mapping`, use :meth:`.QuantumCircuit.layout` and
:meth:`.SparsePauliOp.apply_layout` to adjust an operator for a layout.
Otherwise, use ``mthree.utils.final_measurement_mapping``.
See `Mthree Utility functions <https://qiskit-extensions.github.io/mthree/apidocs/utils.html>`__
for details.
* :class:`.BaseEstimator` as :class:`.BaseEstimatorV1` alias. However, :class:`.BaseEstimatorV2` is recommended instead.
* :class:`.BaseSampler` as :class:`.BaseSamplerV1` alias. However, :class:`.BaseSamplerV2` is recommended instead.
* :class:`.Estimator` as :class:`.EstimatorV1` alias. However, :class:`.EstimatorV2` is recommended instead.
* :class:`.Sampler` as :class:`.SamplerV1` alias. However, :class:`.SamplerV2` is recommended instead.
* :class:`.BackendEstimator` as :class:`.BackendEstimatorV1` alias. However, :class:`.BackendEstimatorV2` is recommended instead.
* :class:`.BackendSampler` as :class:`.BackendSamplerV1` alias. However, :class:`.BackendSamplerV2` is recommended instead.
19 changes: 8 additions & 11 deletions test/python/primitives/test_backend_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,9 @@ def test_estimator_run(self, backend):

# Specify the circuit and observable by indices.
# calculate [ <psi1(theta1)|H1|psi1(theta1)> ]
with self.assertWarns(DeprecationWarning):
job = estimator.run([psi1], [hamiltonian1], [theta1])
result = job.result()
self.assertIsInstance(result, EstimatorResult)
job = estimator.run([psi1], [hamiltonian1], [theta1])
result = job.result()
self.assertIsInstance(result, EstimatorResult)
np.testing.assert_allclose(result.values, [1.5555572817900956], rtol=0.5, atol=0.2)

# Objects can be passed instead of indices.
Expand Down Expand Up @@ -135,9 +134,9 @@ def test_estimator_run_no_params(self, backend):
circuit = self.ansatz.assign_parameters([0, 1, 1, 2, 3, 5])
with self.assertWarns(DeprecationWarning):
est = BackendEstimator(backend=backend)
est.set_options(seed_simulator=123)
result = est.run([circuit], [self.observable]).result()
self.assertIsInstance(result, EstimatorResult)
est.set_options(seed_simulator=123)
result = est.run([circuit], [self.observable]).result()
self.assertIsInstance(result, EstimatorResult)
np.testing.assert_allclose(result.values, [-1.284366511861733], rtol=0.05)

@combine(backend=BACKENDS, creg=[True, False])
Expand Down Expand Up @@ -321,8 +320,7 @@ def max_circuits(self):
with self.assertWarns(DeprecationWarning):
estimator = BackendEstimator(backend=backend)
with patch.object(backend, "run") as run_mock:
with self.assertWarns(DeprecationWarning):
estimator.run([qc] * k, [op] * k, params_list).result()
estimator.run([qc] * k, [op] * k, params_list).result()
self.assertEqual(run_mock.call_count, 10)

def test_job_size_limit_v1(self):
Expand All @@ -340,8 +338,7 @@ def test_job_size_limit_v1(self):
estimator = BackendEstimator(backend=backend)
estimator.set_options(seed_simulator=123)
with patch.object(backend, "run") as run_mock:
with self.assertWarns(DeprecationWarning):
estimator.run([qc] * k, [op] * k, params_list).result()
estimator.run([qc] * k, [op] * k, params_list).result()
self.assertEqual(run_mock.call_count, 10)

def test_no_max_circuits(self):
Expand Down

0 comments on commit 3a10a0c

Please sign in to comment.