From da1623ea0c7ecaf33b7580364df0e6d79827bfac Mon Sep 17 00:00:00 2001 From: Ikko Hamamura Date: Wed, 10 May 2023 13:41:13 +0900 Subject: [PATCH] Remove Sampler.close, assert DeprecationWarning of opflow, and update dependency (#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 --- .github/workflows/docs.yml | 2 +- qiskit_aer/primitives/sampler.py | 7 ------- test/terra/primitives/test_estimator.py | 19 ++++++++++--------- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 253c99fd88..da877479ac 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -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 }} diff --git a/qiskit_aer/primitives/sampler.py b/qiskit_aer/primitives/sampler.py index e1b75cef39..286d7df0fe 100644 --- a/qiskit_aer/primitives/sampler.py +++ b/qiskit_aer/primitives/sampler.py @@ -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) @@ -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) @@ -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) diff --git a/test/terra/primitives/test_estimator.py b/test/terra/primitives/test_estimator.py index ff1a4edef0..6cf9e37537 100644 --- a/test/terra/primitives/test_estimator.py +++ b/test/terra/primitives/test_estimator.py @@ -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)