catalyst.autograph_strict_conversion

autograph_strict_conversion = False

Specify whether AutoGraph should raise exceptions when conversion fails, rather than falling back to interpreting control flow by Python at compile-time.

Example

In certain cases, AutoGraph will fail to convert control flow (for example, when an object that cannot be converted to a JAX array is indexed in a loop), and will automatically fallback to interpreting the control flow logic at compile-time via Python:

>>> dev = qml.device("lightning.qubit", wires=1)
>>> @qjit(autograph=True)
... @qml.qnode(dev)
... def f():
...     params = ["0", "1", "2"]
...     for x in params:
...         qml.RY(int(x) * jnp.pi / 4, wires=0)
...     return qml.expval(qml.PauliZ(0))
>>> f()
array(-0.70710678)

Setting this variable to True will cause AutoGraph to error rather than fallback when conversion fails:

>>> catalyst.autograph_strict_conversion = True
>>> @qjit(autograph=True)
... @qml.qnode(dev)
... def f():
...     params = ["0", "1", "2"]
...     for x in params:
...         qml.RY(int(x) * jnp.pi / 4, wires=0)
...     return qml.expval(qml.PauliZ(0))
AutoGraphError: Could not convert the iteration target ['0', '1', '2'] to array
while processing the following with AutoGraph:
  File "<ipython-input-44-dbae11e6d745>", line 7, in f
    for x in params:
Type

bool