-
Notifications
You must be signed in to change notification settings - Fork 606
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 QNode
for PyTree support
#6378
base: master
Are you sure you want to change the base?
Conversation
pennylane/workflow/qnode.py
Outdated
if isinstance(self._qfunc_output, qml.numpy.tensor): | ||
measurement_processes = tuple( | ||
self.tape.measurements, | ||
) | ||
elif isinstance(self._qfunc_output, dict): | ||
measurement_processes = tuple(self._qfunc_output.values()) | ||
elif not isinstance(self._qfunc_output, Sequence): | ||
measurement_processes = (self._qfunc_output,) |
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.
Perhaps here we can switch this to measurement_processes = qml.pytrees.flatten(self._qfunc_output)[0]
.
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.
Potentially we could switch to storing self._pytree_structure
instead of self._qfunc_output
. Basically we just need to store information somehow to remember how to postprocess the results.
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.
Yes, that could be an improvement. However, the typing of qfunc_output
would also need to be stored as well since it is used to type convert results. 😓
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.
Note that while the main example was a dictinary, we should be able to handle any pytree of measurements. So another example might be:
return ([mp1, mp2], [mp3, mp4], {"a": mp5, "b": [mp6, mp7]})
as a convoluted example.
QNode
for PyTree supportQNode
for PyTree support
QNode
for PyTree supportQNode
for PyTree support
QNode
for PyTree supportQNode
for PyTree support
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #6378 +/- ##
=======================================
Coverage 99.46% 99.46%
=======================================
Files 454 454
Lines 42649 42657 +8
=======================================
+ Hits 42420 42428 +8
Misses 229 229 ☔ View full report in Codecov by Sentry. 🚨 Try these New Features:
|
Also just making a comment here. If we are having obscure edge cases that are difficult to fit into nice logic here and are causing problems, we can consider making a breaking change, if that means more consistent, logical behavior in the |
Co-authored-by: Christina Lee <[email protected]>
Co-authored-by: Christina Lee <[email protected]>
Co-authored-by: Christina Lee <[email protected]>
Co-authored-by: Christina Lee <[email protected]>
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.
❤️
Context:
Catalyst currently supports the handling of PyTrees as measurement outputs,
Pennylane currently doesn't have support for this but can be added using the existing
qml.pytrees
.Description of the Change:
Makes use of the existing
qml.pytrees.flatten
andqml.pytrees.unflatten
functions and updates how theresults
andqfunc_output
is handled/validated.Example
Benefits:
QNode
now has PyTree support! 😄Possible Drawbacks: None
[sc-66732]