Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the tracker used with batch execution #167

Merged
merged 3 commits into from
Dec 12, 2021
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
gradients internally.
[(#156)](https://github.com/PennyLaneAI/pennylane-qiskit/pull/156)
[(#163)](https://github.com/PennyLaneAI/pennylane-qiskit/pull/163)
[(#167)](https://github.com/PennyLaneAI/pennylane-qiskit/pull/167)

### Breaking changes

Expand Down
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
21 changes: 21 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,3 +569,24 @@ 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)

@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