Improve QNode keyword input validation
See original GitHub issueFeature details
Any keyword argument can be passed to a QNode or its qnode decorator without errors arising.
This can result in unexpected behaviour if users make a typo when attempting to use a valid option.
E.g., the following example uses the Autograd interface although inteface="jax" is being passed (because inteface is not an accepted kwarg):
import pennylane as qml
dev = qml.device('default.qubit', wires=3)
@qml.qnode(dev, inteface="jax")
def circuit():
return qml.expval(qml.PauliZ(0))
>>> circuit()
tensor(1., requires_grad=True)
Implementation
No response
How important would you say this feature is?
2: Somewhat important. Needed this quarter.
Additional information
No response
Issue Analytics
- State:
- Created a year ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Validate all the things: improve your security with input ...
Input validation is a programming technique that ensures only properly formatted data may enter a software system component. If there is one ...
Read more >Improve mongoose validation error handling - Stack Overflow
Whenever I enter a field against the validation rules, I get a very long error message, which is obvious. But now, I want...
Read more >How to make input validation simple and clean in your ...
In this tutorial, you'll learn how to validate input in an Express.js app using an open source and popular module called express-validator.
Read more >Get started with validation in Node.js - Simon Plenderleith
The first step in putting together request validation for your Node.js application is finding a way to create flexible validation rules.
Read more >8 input validation - Automate the Boring Stuff with Python
Input validation code checks that values entered by the user, ... fails to enter valid input, these keyword arguments will cause the function...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Hi @nahumsa, great! 😃
I think that sounds good. The main subtlety here is that kwargs passed to
qml.qnodewould be passed asgradient_kwargstoqml.execute. So it first has to be considered if the possible options forgradient_kwargscan be collected in advance or if not, if we can somehow create patterns and/or query options from the ML framework determined by a specific interface.I have noticed that on
pennylane.interfaces.execution.cache_execute:https://github.com/PennyLaneAI/pennylane/blob/1e3a73107d1a897ba04910492c1c698d41e8787e/pennylane/interfaces/execution.py#L126-L128
The
gradient_kwargsvariable when running the default interface (which I think isautograd) is modified to an empty dict because of thepennylane.interfaces.autograd._executehttps://github.com/PennyLaneAI/pennylane/blob/1e3a73107d1a897ba04910492c1c698d41e8787e/pennylane/interfaces/autograd.py#L109-L110
Any thoughts about this?
P.S.: I’m trying to understand more about the codebase, sorry if the commentary wasn’t that useful 😃