Skip to content

Commit

Permalink
Add private primitive attributes removed by qiskit (#2048)
Browse files Browse the repository at this point in the history
* Add private primitive attributes removed by qiskit

* wrong url

* call private submit method

* Make submission compatible with qiskit <=0.45

* Skip Operator test is qiskit >=1.0

* grr lint
  • Loading branch information
ihincks authored Feb 2, 2024
1 parent 9a69eb4 commit 9f45068
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
8 changes: 7 additions & 1 deletion qiskit_aer/primitives/estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ def __init__(
If approximation is True, this parameter is ignored and assumed to be False.
"""
super().__init__(options=run_options)
# These three private attributes used to be created by super, but were deprecated in Qiskit
# 0.46. See https://github.com/Qiskit/qiskit/pull/11051
self._circuits = []
self._parameters = []
self._observables = []

backend_options = {} if backend_options is None else backend_options
method = (
Expand Down Expand Up @@ -204,7 +209,8 @@ def _run(
parameter_values,
**run_options,
)
job.submit()
# The public submit method was removed in Qiskit 0.46
(job.submit if hasattr(job, "submit") else job._submit)() # pylint: disable=no-member
return job

def _compute(self, circuits, observables, parameter_values, run_options):
Expand Down
8 changes: 7 additions & 1 deletion qiskit_aer/primitives/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ def __init__(
skip_transpilation: if True, transpilation is skipped.
"""
super().__init__(options=run_options)
# These two private attributes used to be created by super, but were deprecated in Qiskit
# 0.46. See https://github.com/Qiskit/qiskit/pull/11051
self._circuits = []
self._parameters = []

self._backend = AerSimulator()
backend_options = {} if backend_options is None else backend_options
self._backend.set_options(**backend_options)
Expand Down Expand Up @@ -157,7 +162,8 @@ def _run(
self._circuits.append(circuit)
self._parameters.append(circuit.parameters)
job = PrimitiveJob(self._call, circuit_indices, parameter_values, **run_options)
job.submit()
# The public submit method was removed in Qiskit 0.46
(job.submit if hasattr(job, "submit") else job._submit)() # pylint: disable=no-member
return job

@staticmethod
Expand Down
5 changes: 5 additions & 0 deletions test/terra/primitives/test_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import numpy as np
from ddt import data, ddt
import qiskit
from qiskit.circuit import Parameter, QuantumCircuit
from qiskit.circuit.library import RealAmplitudes
from qiskit.exceptions import QiskitError
Expand Down Expand Up @@ -84,6 +85,10 @@ def test_estimator(self, abelian_grouping):
np.testing.assert_allclose(result.values, [-0.4], rtol=0.02)

@data(True, False)
@unittest.skipUnless(
qiskit.__version__.startswith("0."),
reason="Operator support in primitives was removed following Qiskit 0.46",
)
def test_init_observable_from_operator(self, abelian_grouping):
"""test for evaluate without parameters"""
circuit = self.ansatz.assign_parameters([0, 1, 1, 2, 3, 5])
Expand Down

0 comments on commit 9f45068

Please sign in to comment.