Commit 1690f8c
Remove "experimental_capture" kwarg from "qjit" (#1657)
**Context:** When dealing with transforms, the `experimental_capture`
keyword from `qjit` fails at capturing them because they are defined
before the capture functionality has been activated. To circumvent this,
program capture has to be enabled manually beforehand, which defies the
purpose of the mentioned keyword. We propose using only the PL program
capture enabling/disabling mechanism across the whole ecosystem to
prevent such cases to happen.
**Description of the Change:** Removed the `experimental_capture`
keyword from its `qjit` function in favor of a
unified program capture behavior.
[(#1657)](#1657)
Program capture has to be enabled before the definition of the function
to be qjitted.
For AOT compilation, program capture can be disabled right after the
qjit usage and before execution.
```python
import pennylane as qml
from catalyst import qjit
dev = qml.device("lightning.qubit", wires=1)
qml.capture.enable()
@qjit()
@qml.qnode(dev)
def circuit(x: float):
qml.Hadamard(0)
qml.CNOT([0, 1])
return qml.expval(qml.Z(0))
qml.capture.disable()
circuit(0.1)
```
But for JIT compilation, program capture cannot be disabled before
execution,
otherwise the capture will not take place:
```python
import pennylane as qml
from catalyst import qjit
dev = qml.device("lightning.qubit", wires=1)
qml.capture.enable()
@qjit()
@qml.qnode(dev)
def circuit(x):
qml.Hadamard(0)
qml.CNOT([0, 1])
return qml.expval(qml.Z(0))
circuit(0.1)
qml.capture.disable()
```
**Benefits:**
- Unified program capture behavior.
- No longer necessary to use a wrapper function around a circuit with
transforms:
Before:
```python
@qjit(experimental_capture=True)
def wrapper():
@qml.transforms.merge_amplitude_embedding
@qml.qnode(qml.device(backend, wires=2))
def captured_circuit():
qml.AmplitudeEmbedding(jnp.array([0.0, 1.0]), wires=0)
qml.AmplitudeEmbedding(jnp.array([0.0, 1.0]), wires=1)
return qml.expval(qml.PauliZ(0))
```
After:
```python
qml.capture.enable()
@qjit()
@qml.transforms.merge_amplitude_embedding
@qml.qnode(qml.device(backend, wires=2))
def captured_circuit():
qml.AmplitudeEmbedding(jnp.array([0.0, 1.0]), wires=0)
qml.AmplitudeEmbedding(jnp.array([0.0, 1.0]), wires=1)
return qml.expval(qml.PauliZ(0))
```
**Possible Drawbacks:** Users might find it difficult to understand
where exactly program capture should be enabled/disabled.
[sc-89121]
---------
Co-authored-by: Isaac De Vlugt <34751083+isaacdevlugt@users.noreply.github.com>1 parent dc51613 commit 1690f8c
File tree
5 files changed
+836
-276
lines changed- doc/releases
- frontend
- catalyst
- test/pytest
5 files changed
+836
-276
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
18 | 45 | | |
19 | 46 | | |
20 | 47 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| |||
739 | 739 | | |
740 | 740 | | |
741 | 741 | | |
742 | | - | |
743 | | - | |
744 | | - | |
745 | | - | |
746 | | - | |
747 | | - | |
748 | 742 | | |
749 | | - | |
750 | | - | |
751 | | - | |
752 | | - | |
753 | | - | |
754 | | - | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
755 | 746 | | |
756 | 747 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
94 | | - | |
95 | 94 | | |
96 | 95 | | |
97 | 96 | | |
| |||
151 | 150 | | |
152 | 151 | | |
153 | 152 | | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | 153 | | |
158 | 154 | | |
159 | 155 | | |
| |||
715 | 711 | | |
716 | 712 | | |
717 | 713 | | |
718 | | - | |
| 714 | + | |
719 | 715 | | |
720 | 716 | | |
721 | 717 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | 71 | | |
75 | 72 | | |
76 | 73 | | |
| |||
94 | 91 | | |
95 | 92 | | |
96 | 93 | | |
97 | | - | |
98 | 94 | | |
99 | 95 | | |
100 | 96 | | |
| |||
0 commit comments