-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature-pass-static-argnums-to-qnode (#932)
**Context:** Static argnum is not correctly passed through QNode. Currently if we use `@qjit(static_argnums=(1,))` decorator right before `@qml.qnode(dev)`, the static argument will still be traced within the QNode. **Description of the Change:** Passed the static_argnums from the compile options through qnode __call__() method and then using it in deduce_avals to avoid tracing the static arguments. Also improved the verification and preparation of static_argnums. **Benefits:** Added ability to use static arguments inside qnodes **Possible Drawbacks:** It can potentially cause confusion for jax users since passing `static_argnums` through nested calls to `jax.jit()` is not supported in jax. e.g. ``` @partial(jax.jit, static_argnums=(1,)) @jax.jit def foo(x, c): print("Inside QNode:", c) return x + c ``` ``` >>> foo(0.5, 0.5) >>> Inside QNode: Traced<ShapedArray(float64[], weak_type=True)>with<DynamicJaxprTrace(level=2/0)> ``` which means that parameter c inside foo is still traced. **Related GitHub Issues:** #902 [sc-67808] --------- Co-authored-by: erick-xanadu <[email protected]> Co-authored-by: David Ittah <[email protected]>
- Loading branch information
1 parent
83745f5
commit 39f81b9
Showing
8 changed files
with
180 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters