Skip to content

Commit

Permalink
tracker test
Browse files Browse the repository at this point in the history
  • Loading branch information
antalszava committed Dec 10, 2021
1 parent 0998b85 commit 00d8c11
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
5 changes: 5 additions & 0 deletions pennylane_qiskit/qiskit_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,11 @@ def batch_execute(self, circuits):
results = []
for circuit, circuit_obj in zip(circuits, compiled_circuits):

# Update the tracker
if self.tracker.active:
self.tracker.update(executions=1, shots=self.shots)
self.tracker.record()

if self.backend_name in self._state_backends:
self._state = self._get_state(result, experiment=circuit_obj)

Expand Down
22 changes: 22 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,3 +569,25 @@ def circuit(x, y):
# Check that run was called twice: for the partial derivatives and for
# running the circuit
assert spy2.call_count == 2

def test_tracker(self):
"""Tests the device tracker with batch execution."""
dev = qml.device('qiskit.aer', shots=100, wires=3)
x = np.array([0.1, 0.2])

@qml.qnode(dev, diff_method="parameter-shift")
def circuit(x):
qml.RX(x, wires=0)
return qml.expval(qml.PauliZ(0))

x = tensor(0.1, requires_grad=True)

with qml.Tracker(dev) as tracker:
qml.grad(circuit)(x)

expected = {'executions': [1, 1, 1],
'shots': [100, 100, 100],
'batches': [1, 1],
'batch_len': [1, 2]}

assert tracker.history == expected
3 changes: 2 additions & 1 deletion tests/test_qiskit_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ def test_result(self, device, tol):
assert np.allclose(res[1], tape2_expected, atol=0)

def test_result_empty_tape(self, device, tol):
"""Tests that the result has the correct shape and entry types for empty tapes."""
"""Tests that the result has the correct shape and entry types for
empty tapes."""
dev = device(2)

empty_tape = qml.tape.QuantumTape()
Expand Down

0 comments on commit 00d8c11

Please sign in to comment.