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 PauliList support as observable type for Estimator.run #11521

Merged
merged 4 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions qiskit/primitives/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"""
from __future__ import annotations

import warnings
from collections.abc import Iterable

import numpy as np
Expand All @@ -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:
Expand Down Expand Up @@ -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):
Expand All @@ -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)


Expand Down
10 changes: 5 additions & 5 deletions releasenotes/notes/dep-estimator-paulilist-ef2bb2865b66f012.yaml
Original file line number Diff line number Diff line change
@@ -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`).
2 changes: 1 addition & 1 deletion test/python/primitives/test_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,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")
Expand Down