From 00d8c11bf377a285b68b91e1a18924ff02bfc622 Mon Sep 17 00:00:00 2001 From: Antal Szava Date: Fri, 10 Dec 2021 17:11:52 -0500 Subject: [PATCH 1/3] tracker test --- pennylane_qiskit/qiskit_device.py | 5 +++++ tests/test_integration.py | 22 ++++++++++++++++++++++ tests/test_qiskit_device.py | 3 ++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/pennylane_qiskit/qiskit_device.py b/pennylane_qiskit/qiskit_device.py index 1dea51405..8fd9e2cfb 100644 --- a/pennylane_qiskit/qiskit_device.py +++ b/pennylane_qiskit/qiskit_device.py @@ -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) diff --git a/tests/test_integration.py b/tests/test_integration.py index 23116eae4..13ed90354 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -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 diff --git a/tests/test_qiskit_device.py b/tests/test_qiskit_device.py index 2c80f77bd..6c6fa7b51 100644 --- a/tests/test_qiskit_device.py +++ b/tests/test_qiskit_device.py @@ -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() From 9035672c56e02d293bfbe3eaa23fc367004751c7 Mon Sep 17 00:00:00 2001 From: Antal Szava Date: Fri, 10 Dec 2021 17:12:56 -0500 Subject: [PATCH 2/3] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c70817f7..b729a7f77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 From 204c73e6ad8c8709ff16bd0b8ed62ae8669bf8cf Mon Sep 17 00:00:00 2001 From: antalszava Date: Fri, 10 Dec 2021 17:37:08 -0500 Subject: [PATCH 3/3] Update tests/test_integration.py Co-authored-by: Romain --- tests/test_integration.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_integration.py b/tests/test_integration.py index 13ed90354..343f6a21a 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -573,7 +573,6 @@ def circuit(x, y): 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):