Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/braket/pennylane_plugin/braket_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,10 @@ def execute(self, circuit: QuantumTape, compute_gradient=False, **run_kwargs) ->
tracking_data = self._tracking_data(self._task)
self.tracker.update(executions=1, shots=self.shots, **tracking_data)
self.tracker.record()

# increment counter for number of executions of device
self._num_executions += 1

return self._braket_to_pl_result(braket_result, circuit)

def apply(
Expand Down Expand Up @@ -499,6 +503,7 @@ def batch_execute(self, circuits, **run_kwargs):

# Update the tracker before raising an exception further if some circuits do not complete.
finally:
self._num_executions += len(task_batch.tasks)
if self.tracker.active:
for task in task_batch.tasks:
tracking_data = self._tracking_data(task)
Expand Down
15 changes: 15 additions & 0 deletions test/unit_tests/test_braket_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,21 @@ def test_execute_with_gradient(
assert (results[0][1] == expected_pl_result[0][1]).all()


@patch.object(AwsDevice, "run")
def test_number_executions(mock_run):
"""Asserts tracker stores information during execute when active"""
mock_run.side_effect = [TASK, SIM_TASK, SIM_TASK, TASK]
dev = _aws_device(wires=4, foo="bar")

with QuantumTape() as circuit:
qml.Hadamard(wires=0)
qml.probs(wires=(0,))
dev.execute(circuit)
dev.execute(circuit)

assert dev.num_executions == 2


@patch.object(AwsDevice, "run")
def test_execute_tracker(mock_run):
"""Asserts tracker stores information during execute when active"""
Expand Down