question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve QNode keyword input validation

See original GitHub issue

Feature 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:open
  • Created a year ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
antalszavacommented, Aug 9, 2022

Hi @nahumsa, great! 😃

I think that sounds good. The main subtlety here is that kwargs passed to qml.qnode would be passed as gradient_kwargs to qml.execute. So it first has to be considered if the possible options for gradient_kwargs can 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.

0reactions
nahumsacommented, Aug 25, 2022

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_kwargs variable when running the default interface (which I think is autograd) is modified to an empty dict because of the pennylane.interfaces.autograd._execute

https://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 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found