Skip to content

Commit 4f309b4

Browse files
authored
Remove use of opflow in Estimator (#1996)
1 parent a36812f commit 4f309b4

File tree

3 files changed

+11
-18
lines changed

3 files changed

+11
-18
lines changed

qiskit_aer/primitives/estimator.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This code is part of Qiskit.
22
#
3-
# (C) Copyright IBM 2022.
3+
# (C) Copyright IBM 2022, 2023.
44
#
55
# This code is licensed under the Apache License, Version 2.0. You may
66
# obtain a copy of this license in the LICENSE.txt file in the root directory
@@ -23,7 +23,6 @@
2323
import numpy as np
2424
from qiskit.circuit import ParameterExpression, QuantumCircuit
2525
from qiskit.compiler import transpile
26-
from qiskit.opflow import PauliSumOp
2726
from qiskit.primitives import BaseEstimator, EstimatorResult
2827
from qiskit.primitives.primitive_job import PrimitiveJob
2928
from qiskit.primitives.utils import _circuit_key, _observable_key, init_observable
@@ -174,7 +173,7 @@ def _call(
174173
def _run(
175174
self,
176175
circuits: Sequence[QuantumCircuit],
177-
observables: Sequence[BaseOperator | PauliSumOp],
176+
observables: Sequence[BaseOperator],
178177
parameter_values: Sequence[Sequence[float]],
179178
**run_options,
180179
) -> PrimitiveJob:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
upgrade:
3+
- |
4+
The :meth:`qiskit_aer.primitives.Estimator.run` method no longer supports
5+
``observables`` input arguments of type ``PauliSumOp``. The ``PauliSumOp``
6+
class was deprecated in Qiskit 0.44 and will be removed in Qiskit 1.0.
7+
Alternative types that you can use instead of ``PauliSumOp`` are
8+
:class:`qiskit.quantum_info.SparsePauliOp` or :class:`qiskit.quantum_info.Pauli`.

test/terra/primitives/test_estimator.py

+1-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This code is part of Qiskit.
22
#
3-
# (C) Copyright IBM 2022.
3+
# (C) Copyright IBM 2022, 2023.
44
#
55
# This code is licensed under the Apache License, Version 2.0. You may
66
# obtain a copy of this license in the LICENSE.txt file in the root directory
@@ -23,7 +23,6 @@
2323
from qiskit.circuit import Parameter, QuantumCircuit
2424
from qiskit.circuit.library import RealAmplitudes
2525
from qiskit.exceptions import QiskitError
26-
from qiskit.opflow import PauliSumOp
2726
from qiskit.primitives import EstimatorResult
2827
from qiskit.quantum_info import Operator, SparsePauliOp
2928

@@ -53,19 +52,6 @@ def setUp(self):
5352
def test_estimator(self, abelian_grouping):
5453
"""test for a simple use case"""
5554
lst = [("XX", 1), ("YY", 2), ("ZZ", 3)]
56-
with self.assertWarns(DeprecationWarning):
57-
with self.subTest("PauliSumOp"):
58-
observable = PauliSumOp.from_list(lst)
59-
ansatz = RealAmplitudes(num_qubits=2, reps=2)
60-
est = Estimator(
61-
backend_options={"method": "statevector"}, abelian_grouping=abelian_grouping
62-
)
63-
result = est.run(
64-
ansatz, observable, parameter_values=[[0, 1, 1, 2, 3, 5]], seed=15
65-
).result()
66-
self.assertIsInstance(result, EstimatorResult)
67-
np.testing.assert_allclose(result.values, [1.728515625])
68-
6955
with self.subTest("SparsePauliOp"):
7056
observable = SparsePauliOp.from_list(lst)
7157
ansatz = RealAmplitudes(num_qubits=2, reps=2)

0 commit comments

Comments
 (0)