-
Notifications
You must be signed in to change notification settings - Fork 575
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
Fix bug in tracking the number of device executions #1046
Conversation
Hello. You may have forgotten to update the changelog!
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All comments are minor :)
# actually run so she has full control. This could be done by changing the class | ||
# of the user's device before and after executing the tape. | ||
if self.device != self._original_device: | ||
self._original_device._num_executions += 1 # pylint: disable=protected-access |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might sound crazy, but will self.qtape.execute(device=self.device)
always result in just 1 additional execution?
Or is this a case where there could be more than 1 under the scenes?
I suppose I am being crazy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering too. In future this may very well happen, but I think it does not happen at the moment. More reason to find a better fix one day.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case you could do
diff_executions = self.device.num_executions
res = self.qtape.execute(device=self.device)
diff_executions = self.device.num_executions - diff_executions
if self.device is not self._original_device:
self._original_device._num_executions += diff_executions
return qml.expval(qml.PauliZ(0)) | ||
|
||
dev = qml.device("default.qubit", wires=2) | ||
qn = QNode(func, dev, interface="autograd") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add diff_method="backprop"
here to be explicit, in case we ever change the logic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But if we change the logic and don't switch the device any more, we actually don't only want to test "backprop" either. Could do a fixture with all diff methods?
Co-authored-by: Josh Izaac <josh146@gmail.com>
Co-authored-by: Josh Izaac <josh146@gmail.com>
Codecov Report
@@ Coverage Diff @@
## master #1046 +/- ##
=======================================
Coverage 97.94% 97.94%
=======================================
Files 153 153
Lines 11481 11483 +2
=======================================
+ Hits 11245 11247 +2
Misses 236 236
Continue to review full report at Codecov.
|
Context
With PR #1008 we are creating situations in which the tape is executed on a different device than the user has given to the qnode. This is a design issue we should access in the long term. In the short term it introduces a bug because the
num_executions
attribute is no longer tracked correctly on the user's device. This PR fixes the issue by manually adding1
todevice.num_executions
if we are swapping out devices.It also adds some tests that would have caught the bug.
PS: Ignore the branch name!