diff --git a/qiskit/primitives/utils.py b/qiskit/primitives/utils.py index db3fcbd132dc..d94e3355d201 100644 --- a/qiskit/primitives/utils.py +++ b/qiskit/primitives/utils.py @@ -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. @@ -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`. @@ -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. diff --git a/releasenotes/notes/deprecate-non-versioned-primitives.yaml b/releasenotes/notes/deprecate-non-versioned-primitives.yaml index 4cdb8aa6fd77..6d9718278335 100644 --- a/releasenotes/notes/deprecate-non-versioned-primitives.yaml +++ b/releasenotes/notes/deprecate-non-versioned-primitives.yaml @@ -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 `__ - 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. diff --git a/test/python/primitives/test_backend_estimator.py b/test/python/primitives/test_backend_estimator.py index c3deb0735ca1..b8b20f934122 100644 --- a/test/python/primitives/test_backend_estimator.py +++ b/test/python/primitives/test_backend_estimator.py @@ -94,10 +94,9 @@ def test_estimator_run(self, backend): # Specify the circuit and observable by indices. # calculate [ ] - 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. @@ -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]) @@ -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): @@ -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):