Add setup_inputs to transform
#8732
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context:
Currently, our signature and docstring for transforms comes from the tape transform. If we don't have a tape transform, and just have a
pass_namedefinition, we don't have a place to pull the signature and docstring from.Also, our argument validation is lazy and only performed when actually applying the transform to a tape. This delays potentially useful error messages.
Description of the Change:
Adds an optional
setup_inputsargument to transforms. Thissetup_inputsfunction is called before any type of dispatch, including onto a qnode, quantum function, or anything else. This allows us to standardize and validate any inputs. We can also sort arguments into being positional or keyword, which will be important for capturing and lowering the transform.Benefits:
Improved argument validation, preprocessing, docstrings, and signature.
Possible Drawbacks:
transformis getting very cluttered with components.Related GitHub Issues:
Example:
For current transforms, we can apply them to a qnode with incorrect arguments with no problem:
Errors will only be raised when the qnode is actually executed.
We can create new version of it with a
setup_inputs:And now we get an error when it is applied to a
QNode: