From e84c57c96ff993894fbb0007af26dd9f4c1d0658 Mon Sep 17 00:00:00 2001 From: Romain Moyard Date: Tue, 24 Jan 2023 16:25:12 -0500 Subject: [PATCH] Change the place of `num_exec` (#259) * Fix * Fix tests * Add changelog * Wrong PR number --- CHANGELOG.md | 3 +++ pennylane_qiskit/qiskit_device.py | 6 +++--- tests/test_qiskit_device.py | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb85d67ff..b48705be9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,9 @@ ### Bug fixes +* The number of executions of the device is now correct. + [(#259)](https://github.com/PennyLaneAI/pennylane-qiskit/pull/259) + ### Contributors This release contains contributions from (in alphabetical order): diff --git a/pennylane_qiskit/qiskit_device.py b/pennylane_qiskit/qiskit_device.py index 960ccfc71..7808eb368 100644 --- a/pennylane_qiskit/qiskit_device.py +++ b/pennylane_qiskit/qiskit_device.py @@ -466,6 +466,9 @@ def batch_execute(self, circuits): self._current_job = self.backend.run(compiled_circuits, shots=self.shots, **self.run_args) result = self._current_job.result() + # increment counter for number of executions of qubit device + self._num_executions += 1 + # Compute statistics using the state and/or samples results = [] for circuit, circuit_obj in zip(circuits, compiled_circuits): @@ -486,9 +489,6 @@ def batch_execute(self, circuits): res = np.asarray(res) results.append(res) - # increment counter for number of executions of qubit device - self._num_executions += 1 - if self.tracker.active: self.tracker.update(batches=1, batch_len=len(circuits)) self.tracker.record() diff --git a/tests/test_qiskit_device.py b/tests/test_qiskit_device.py index 066100cfd..bd4755196 100644 --- a/tests/test_qiskit_device.py +++ b/tests/test_qiskit_device.py @@ -177,8 +177,8 @@ def test_result_empty_tape(self, device, tol): assert np.allclose(res[0], dev.execute(empty_tape), atol=0) def test_num_executions_recorded(self, device): - """Tests that the number of exeuctions are recorded correctly..""" + """Tests that the number of executions are recorded correctly..""" dev = device(2) tapes = [self.tape1, self.tape2] res = dev.batch_execute(tapes) - assert dev.num_executions == 2 + assert dev.num_executions == 1