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

Deprecate fancy decorator syntax in batch transforms #4457

Merged
merged 17 commits into from
Sep 6, 2023

Conversation

eddddddy
Copy link
Contributor

Context:
Currently we allow the user to do something like

@qml.batch_input(argnum=0)
@qml.qnode(dev)
def circuit(inputs):
    ...

The only reason this works is because of some custom magic in qml.batch_transform that wraps the arguments in a partial call and returns that wrapper.

With the new transform program we want to switch to using the following syntax:

@partial(qml.batch_input, argnum=0)
@qml.qnode(dev)
def circuit(inputs):
    ...

which works identically but is easier to understand directly from the documentation of qml.batch_input.

Description of the Change:

  • Add deprecation warning for the use of the first syntax
  • Allow the first syntax in the new transform API so that existing batch transforms can be ported over without breaking things

Benefits:
Less confusing

Possible Drawbacks:
Slightly more typing for users

Copy link
Contributor

@rmoyard rmoyard left a comment

Choose a reason for hiding this comment

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

💯 Thanks for that. Just a couple of comments

doc/development/deprecations.rst Outdated Show resolved Hide resolved
doc/development/deprecations.rst Outdated Show resolved Hide resolved
doc/releases/changelog-dev.md Outdated Show resolved Hide resolved
@rmoyard rmoyard requested a review from trbromley August 10, 2023 19:02
@codecov
Copy link

codecov bot commented Aug 10, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (39e6577) 99.65% compared to head (d4548af) 99.65%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4457   +/-   ##
=======================================
  Coverage   99.65%   99.65%           
=======================================
  Files         376      376           
  Lines       33135    33142    +7     
=======================================
+ Hits        33022    33029    +7     
  Misses        113      113           
Files Changed Coverage Δ
pennylane/transforms/core/transform_dispatcher.py 100.00% <100.00%> (ø)

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

@eddddddy eddddddy requested a review from a team August 11, 2023 14:37
doc/development/deprecations.rst Outdated Show resolved Hide resolved
doc/development/deprecations.rst Outdated Show resolved Hide resolved
pennylane/transforms/core/transform_dispatcher.py Outdated Show resolved Hide resolved
doc/development/deprecations.rst Outdated Show resolved Hide resolved
Co-authored-by: Christina Lee <christina@xanadu.ai>
Copy link
Contributor

@albi3ro albi3ro left a comment

Choose a reason for hiding this comment

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

@trbromley @rmoyard What do we think of always advertising using keyword arguments instead of using positional arguments?

@partial(qml.transforms.batch_params, all_operations=True)
@qml.qnode()
...

It removes all of this ambiguity around positional arguments.

@rmoyard
Copy link
Contributor

rmoyard commented Aug 11, 2023

No problems with advertising kwargs 👍

@timmysilv
Copy link
Contributor

can you add a test or two that uses the @partial(transform_fn, **kwargs) syntax? i'm just worried that once we drop the warning, we'll delete those tests and lose some coverage. otherwise I think the errors are very clear, and it all looks great!

@mudit2812 mudit2812 enabled auto-merge (squash) September 5, 2023 21:25
@mudit2812 mudit2812 merged commit 8b91739 into master Sep 6, 2023
39 checks passed
@mudit2812 mudit2812 deleted the allow_transform_decorator branch September 6, 2023 16:29
mudit2812 added a commit that referenced this pull request Sep 8, 2023
**Context:**
Currently we allow the user to do something like
```python
@qml.batch_input(argnum=0)
@qml.qnode(dev)
def circuit(inputs):
    ...
```
The only reason this works is because of some custom magic in
`qml.batch_transform` that wraps the arguments in a `partial` call and
returns that wrapper.

With the new transform program we want to switch to using the following
syntax:
```python
@partial(qml.batch_input, argnum=0)
@qml.qnode(dev)
def circuit(inputs):
    ...
```
which works identically but is easier to understand directly from the
documentation of `qml.batch_input`.

**Description of the Change:**
- Add deprecation warning for the use of the first syntax
- Allow the first syntax in the new transform API so that existing batch
transforms can be ported over without breaking things

**Benefits:**
Less confusing

**Possible Drawbacks:**
Slightly more typing for users

---------

Co-authored-by: Romain Moyard <rmoyard@gmail.com>
Co-authored-by: Christina Lee <christina@xanadu.ai>
Co-authored-by: Mudit Pandey <mudit.pandey@xanadu.ai>
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.

None yet

6 participants