-
Notifications
You must be signed in to change notification settings - Fork 558
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
Add native tools for flattening and unflattening pytrees #5701
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #5701 +/- ##
==========================================
- Coverage 99.68% 99.67% -0.01%
==========================================
Files 416 416
Lines 39049 38814 -235
==========================================
- Hits 38925 38689 -236
- Misses 124 125 +1 ☔ View full report in Codecov by Sentry. |
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.
Overall looks great! this will be much easier to integrate than the Jax library
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.
Looks great! Couple of suggestions.
Co-authored-by: Thomas R. Bromley <49409390+trbromley@users.noreply.github.com> Co-authored-by: Jack Brown <jack@xanadu.ai> Co-authored-by: Mudit Pandey <mudit.pandey@xanadu.ai>
Co-authored-by: Jack Brown <jack@xanadu.ai>
Co-authored-by: Jack Brown <jack@xanadu.ai>
Co-authored-by: Jack Brown <jack@xanadu.ai>
Context:
Pytrees are nested data structures. Pytree tools can make it easier to handle said data structure.
Jax, optree, and other packages provide tools for handling pytrees already. To take advantage of those tools in core pennylane, we would need to make one of those packages a dependency. Instead of adding an extra dependency, we can have our own stripped-down version of pytree tools.
Description of the Change:
This PR adds
tree_flatten
,tree_unflatten
,Structure
, andLeaf
to the pytrees module. It also updatesqml.pytrees.register_pytree
to register the type with pennylane's pytree setup as well.Benefits:
Use in datasets module to serialize and de-serialize pennylane objects.
Potential future use in
bind_new_parameters
.Easy extraction and reset of parameters.
Possible Drawbacks:
Not as performant as the C++ bound versions used by jax and optree.
Related GitHub Issues:
[sc-46349]