qp.compiler.active_compiler

active_compiler()[source]

Check which compiler is activated inside a qjit() evaluation context.

This helper function may be used during implementation to allow differing logic for transformations or operations that are just-in-time compiled, versus those that are not.

Returns:

Name of the active compiler inside a qjit() evaluation context. If there is no active compiler, None will be returned.

Return type:

Optional[str]

Example

This method can be used to execute logical branches that are conditioned on whether hybrid compilation with a specific compiler is occurring.

dev = qp.device("lightning.qubit", wires=2)

@qp.qnode(dev)
def circuit(phi, theta):
    if qp.compiler.active_compiler() == "catalyst":
        qp.RX(phi, wires=0)
    qp.CNOT(wires=[0, 1])
    qp.PhaseShift(theta, wires=0)
    return qp.expval(qp.Z(0))
>>> circuit(np.pi, np.pi / 2)
1.0
>>> qp.qjit(circuit)(np.pi, np.pi / 2)
-1.0