qml.compiler.active¶
- active()[source]¶
Check whether the caller is inside a
qjit()
evaluation context.This helper function may be used during implementation to allow differing logic for circuits or operations that are just-in-time compiled versus those that are not.
- Returns
True
if the caller is inside a QJIT evaluation context- Return type
bool
Example
For example, you can use this method in your hybrid program to execute it conditionally whether called inside
qjit()
or not.dev = qml.device("lightning.qubit", wires=2) @qml.qnode(dev) def circuit(phi, theta): if qml.compiler.active(): qml.RX(phi, wires=0) qml.CNOT(wires=[0, 1]) qml.PhaseShift(theta, wires=0) return qml.expval(qml.Z(0))
>>> circuit(np.pi, np.pi / 2) 1.0 >>> qml.qjit(circuit)(np.pi, np.pi / 2) -1.0
code/api/pennylane.compiler.active
Download Python script
Download Notebook
View on GitHub