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

Add construct_batch and transform_program functions to workflow module #5084

Merged
merged 32 commits into from
Jan 31, 2024

Conversation

albi3ro
Copy link
Contributor

@albi3ro albi3ro commented Jan 19, 2024

See #5058 for a prototype of the end state.

This PR adds two functions qml.workflow.construct_batch and qml.workflow.transform_program.

transform_program(qnode, level) takes a qnode and a "level" and returns a transform program. The level keyword argument will be used through construct_batch, draw, draw_mpl, and specs and indicates a selection from the full transform program.

construct_batch(qnode, level)(*args, **kwargs) takes a qnode and a level and returns a callable with the same signature as the qnode. It then applies the transform program corresponding to level.

Additional minor changes and helpers:

  • qml.transforms.core.expand_fn_transform: In order to place qml.Device.expand_fn into the transform program easily, I added a quick function to convert from a tape->tape function to a transform.

  • TransformContainer.__repr__: This just makes my life easier when working with transforms.

  • Default the is_informative keyword argument to False instead of None when creating a transform. This way a transform created with TransformContainer has the same default value of is_informative. This was causing me headaches when comparing transforms in testing.

  • Slicing into a TransformProgram with a slice object returns another TransformProgram instead of a list. Ex prog[0:4]

  • Defined __contains__ for TransformProgram. This just made my life easier when playing around and testing things out. example: qml.compile in my_program.

  • Added some documentation on defined dunder methods in TransformProgram

Copy link
Contributor

@trbromley trbromley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @albi3ro! This looks great. I think it's still WIP so I'll come back to look at this later.

doc/releases/changelog-dev.md Show resolved Hide resolved
doc/releases/changelog-dev.md Outdated Show resolved Hide resolved
pennylane/transforms/core/transform.py Show resolved Hide resolved
pennylane/transforms/core/transform.py Outdated Show resolved Hide resolved
pennylane/transforms/core/transform.py Outdated Show resolved Hide resolved
pennylane/transforms/core/transform.py Outdated Show resolved Hide resolved
pennylane/transforms/core/transform.py Outdated Show resolved Hide resolved
albi3ro and others added 8 commits January 22, 2024 17:30
erge branch 'construct-batch' of https://github.com/PennyLaneAI/pennylane into construct-batch
Co-authored-by: Thomas R. Bromley <49409390+trbromley@users.noreply.github.com>
Co-authored-by: Thomas R. Bromley <49409390+trbromley@users.noreply.github.com>
Co-authored-by: Thomas R. Bromley <49409390+trbromley@users.noreply.github.com>
Copy link

codecov bot commented Jan 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (f19d976) 99.69% compared to head (b6ab690) 99.68%.
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5084      +/-   ##
==========================================
- Coverage   99.69%   99.68%   -0.01%     
==========================================
  Files         393      394       +1     
  Lines       35912    35710     -202     
==========================================
- Hits        35801    35598     -203     
- Misses        111      112       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@lillian542 lillian542 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me - transform_program and construct_batch both look super useful 🚀

pennylane/devices/default_qubit.py Outdated Show resolved Hide resolved
pennylane/workflow/construct_batch.py Outdated Show resolved Hide resolved
pennylane/workflow/construct_batch.py Outdated Show resolved Hide resolved
Copy link
Contributor

@timmysilv timmysilv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really excited to have this in 🍾 most of my comments are about style or docs, lmk what you think

pennylane/transforms/core/transform.py Outdated Show resolved Hide resolved
pennylane/workflow/construct_batch.py Outdated Show resolved Hide resolved
pennylane/workflow/construct_batch.py Outdated Show resolved Hide resolved
pennylane/workflow/construct_batch.py Outdated Show resolved Hide resolved
pennylane/workflow/construct_batch.py Outdated Show resolved Hide resolved
pennylane/workflow/construct_batch.py Outdated Show resolved Hide resolved
pennylane/workflow/construct_batch.py Outdated Show resolved Hide resolved
pennylane/workflow/construct_batch.py Outdated Show resolved Hide resolved
pennylane/workflow/construct_batch.py Outdated Show resolved Hide resolved
@timmysilv
Copy link
Contributor

I'd like some finality on what to do with expand_fn_transform before this merges, but otherwise I think it's good to go. I'm fine to not make a public solution to the single-tape transform in this PR, but if that's the case, I would prefer that we keep this one private until we have a proposed UI for it

Copy link
Contributor

@timmysilv timmysilv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love it

Copy link
Contributor

@trbromley trbromley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Approved, subject to my comments.

To check I understand, this will be used for the drawing and specs functionality?

pennylane/transforms/core/transform.py Show resolved Hide resolved
pennylane/workflow/construct_batch.py Outdated Show resolved Hide resolved
pennylane/workflow/construct_batch.py Outdated Show resolved Hide resolved
pennylane/workflow/construct_batch.py Outdated Show resolved Hide resolved
pennylane/workflow/construct_batch.py Outdated Show resolved Hide resolved
albi3ro and others added 2 commits January 31, 2024 10:59
Co-authored-by: Thomas R. Bromley <49409390+trbromley@users.noreply.github.com>
@albi3ro
Copy link
Contributor Author

albi3ro commented Jan 31, 2024

Nice! Approved, subject to my comments.

To check I understand, this will be used for the drawing and specs functionality?

Yes this will be for drawing and specs.

@albi3ro albi3ro merged commit b5f302c into master Jan 31, 2024
35 checks passed
@albi3ro albi3ro deleted the construct-batch branch January 31, 2024 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants