Skip to content

Commit

Permalink
Remove Sampler.close, assert DeprecationWarning of opflow, and update…
Browse files Browse the repository at this point in the history
… dependency (Qiskit#1804)

Since qiskit-terra 0.24, `Sampler` does not have `close()` but Aer's `Sampler` still have the method. This commit takes the method as well as upgrade of Python versions in tutorial tests from 3.7 to 3.8.

* rm close
* assert DeprecationWarning
* update dependency
  • Loading branch information
ikkoham authored and hhorii committed May 15, 2023
1 parent 7c8c254 commit 583985e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
needs: [docs]
strategy:
matrix:
python-version: [3.7]
python-version: [3.8]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand Down
7 changes: 0 additions & 7 deletions qiskit_aer/primitives/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def __init__(
skip_transpilation: if True, transpilation is skipped.
"""
super().__init__(options=run_options)
self._is_closed = False
self._backend = AerSimulator()
backend_options = {} if backend_options is None else backend_options
self._backend.set_options(**backend_options)
Expand All @@ -82,9 +81,6 @@ def _call(
parameter_values: Sequence[Sequence[float]],
**run_options,
) -> SamplerResult:
if self._is_closed:
raise QiskitError("The primitive has been closed.")

seed = run_options.pop("seed", None)
if seed is not None:
run_options.setdefault("seed_simulator", seed)
Expand Down Expand Up @@ -158,9 +154,6 @@ def _run(
job.submit()
return job

def close(self):
self._is_closed = True

@staticmethod
def _preprocess_circuit(circuit: QuantumCircuit):
circuit = init_circuit(circuit)
Expand Down
19 changes: 10 additions & 9 deletions test/terra/primitives/test_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,16 @@ def setUp(self):
def test_estimator(self, abelian_grouping):
"""test for a simple use case"""
lst = [("XX", 1), ("YY", 2), ("ZZ", 3)]
with self.subTest("PauliSumOp"):
observable = PauliSumOp.from_list(lst)
ansatz = RealAmplitudes(num_qubits=2, reps=2)
est = Estimator(abelian_grouping=abelian_grouping)
result = est.run(
ansatz, observable, parameter_values=[[0, 1, 1, 2, 3, 5]], seed=15
).result()
self.assertIsInstance(result, EstimatorResult)
np.testing.assert_allclose(result.values, [1.728515625])
with self.assertWarns(DeprecationWarning):
with self.subTest("PauliSumOp"):
observable = PauliSumOp.from_list(lst)
ansatz = RealAmplitudes(num_qubits=2, reps=2)
est = Estimator(abelian_grouping=abelian_grouping)
result = est.run(
ansatz, observable, parameter_values=[[0, 1, 1, 2, 3, 5]], seed=15
).result()
self.assertIsInstance(result, EstimatorResult)
np.testing.assert_allclose(result.values, [1.728515625])

with self.subTest("SparsePauliOp"):
observable = SparsePauliOp.from_list(lst)
Expand Down

0 comments on commit 583985e

Please sign in to comment.