-
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
Correct batch transform signatures in documentation #1733
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1733 +/- ##
=======================================
Coverage 99.21% 99.21%
=======================================
Files 204 204
Lines 15425 15433 +8
=======================================
+ Hits 15304 15312 +8
Misses 121 121
Continue to review full report at Codecov.
|
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.
No major comments from my side, good catch!
Both, the changelog and the __new__
method could have a warning regarding the unlikely case of a user having SPHINX_BUILD="1"
in their environment.
* The `qml.batch_transform` decorator is now ignored during Sphinx builds, allowing | ||
the correct signature to display in the built documentation. | ||
[(#1733)](https://github.com/PennyLaneAI/pennylane/pull/1733) |
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.
Could add a word of warning how the detection of a sphinx build is done technically, so that users can quickly identify in case they run into the (unlikely) case of SPHINX_BUILD="1"
in their environment?
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.
@dwierichs good idea! I added a warning here: 881b453
tape2 = tape.copy() | ||
return [tape1, tape2], None | ||
|
||
assert isinstance(my_transform, qml.batch_transform) |
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.
Very nice to test both cases!
Context: Currently, batch transformations created with the
@qml.batch_transform
decorator do not show the correct signature in the docs:This is due to a drawback of
functools.wraps
--- it only wraps the docstring, not the signature.Description of the Change: The
@qml.batch_decorator
is modified to simply return the input function, with no decoration, if it detects a Sphinx build (SPHINX_BUILD = "1"
).Benefits:
The correct signature is now shown in the docs:
Possible Drawbacks:
If a user for some reason has
SPHINX_BUILD = "1"
in their environment, batch transforms will fail to work on QNodes. To help avoid this, a warning is raised in this situation.Related GitHub Issues: