Skip to content

Commit

Permalink
Change the place of num_exec (#259)
Browse files Browse the repository at this point in the history
* Fix

* Fix tests

* Add changelog

* Wrong PR number
  • Loading branch information
rmoyard authored Jan 24, 2023
1 parent a4eee1c commit e84c57c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions pennylane_qiskit/qiskit_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_qiskit_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e84c57c

Please sign in to comment.