diff --git a/qiskit/primitives/utils.py b/qiskit/primitives/utils.py index 75d25abbbe30..be4b932ec768 100644 --- a/qiskit/primitives/utils.py +++ b/qiskit/primitives/utils.py @@ -14,7 +14,6 @@ """ from __future__ import annotations -import warnings from collections.abc import Iterable import numpy as np @@ -25,6 +24,7 @@ from qiskit.quantum_info import SparsePauliOp, Statevector, PauliList from qiskit.quantum_info.operators.base_operator import BaseOperator from qiskit.quantum_info.operators.symplectic.base_pauli import BasePauli +from qiskit.exceptions import QiskitError def init_circuit(state: QuantumCircuit | Statevector) -> QuantumCircuit: @@ -54,6 +54,8 @@ def init_observable(observable: BaseOperator | str) -> SparsePauliOp: Returns: The observable as :class:`~qiskit.quantum_info.SparsePauliOp`. + Raises: + QiskitError: when observable type cannot be converted to SparsePauliOp. """ if isinstance(observable, SparsePauliOp): @@ -62,14 +64,7 @@ def init_observable(observable: BaseOperator | str) -> SparsePauliOp: return SparsePauliOp.from_operator(observable) else: if isinstance(observable, PauliList): - warnings.warn( - "Implicit conversion from a PauliList to a SparsePauliOp with coeffs=1 in" - " estimator observable arguments is deprecated as of Qiskit 0.46 and will be" - " in Qiskit 1.0. You should explicitly convert to a SparsePauli op using" - " SparsePauliOp(pauli_list) to avoid this warning.", - DeprecationWarning, - stacklevel=2, - ) + raise QiskitError(f"observable type not supported: {type(observable)}") return SparsePauliOp(observable) diff --git a/releasenotes/notes/dep-estimator-paulilist-ef2bb2865b66f012.yaml b/releasenotes/notes/dep-estimator-paulilist-ef2bb2865b66f012.yaml index 4fad2f28e073..adbf1f5f9da0 100644 --- a/releasenotes/notes/dep-estimator-paulilist-ef2bb2865b66f012.yaml +++ b/releasenotes/notes/dep-estimator-paulilist-ef2bb2865b66f012.yaml @@ -1,7 +1,7 @@ --- -deprecations: +upgrade: - | - Deprecates using a :class:`~.PauliList` as an observable that is implicitly - converted to a :class:`~.SparsePauliOp` with coefficients 1 when calling - :meth:`.Estimator.run`. Users should instead explicitly convert the argument - using ``SparsePauliOp(pauli_list)`` first. + Using a :class:`~.PauliList` as an observable + when calling + :meth:`.Estimator.run` is not further supported. Users should instead explicitly convert the argument + using ``SparsePauliOp(pauli_list)`` first (see :class:`~.SparsePauliOp`). diff --git a/test/python/primitives/test_estimator.py b/test/python/primitives/test_estimator.py index 8606819e524b..2ee108a03a6d 100644 --- a/test/python/primitives/test_estimator.py +++ b/test/python/primitives/test_estimator.py @@ -375,7 +375,7 @@ def test_validate_observables(self, obsevables, expected): @unpack def test_validate_observables_deprecated(self, obsevables, expected): """Test obsevables standardization.""" - with self.assertRaises(DeprecationWarning): + with self.assertRaises(QiskitError): self.assertEqual(validation._validate_observables(obsevables), expected) @data(None, "ERROR")