catalyst.autograph_source¶
- autograph_source(fn)[source]¶
Utility function to retrieve the source code of a function converted by AutoGraph.
Warning
Nested functions (those not directly decorated with
@qjit
) are only lazily converted by AutoGraph. Make sure that the function has been traced at least once before accessing its transformed source code, for example by specifying the signature of the compiled program or by running it at least once.- Parameters
fn (Callable) – the original function object that was converted
- Returns
the source code of the converted function
- Return type
str
- Raises
AutoGraphError – If the given function was not converted by AutoGraph, an error will be raised.
Example
def decide(x): if x < 5: y = 15 else: y = 1 return y @qjit(autograph=True) def func(x: int): y = decide(x) return y ** 2
>>> print(autograph_source(decide)) def decide_1(x): with ag__.FunctionScope('decide', 'fscope', ag__.STD) as fscope: def get_state(): return (y,) def set_state(vars_): nonlocal y (y,) = vars_ def if_body(): nonlocal y y = 15 def else_body(): nonlocal y y = 1 y = ag__.Undefined('y') ag__.if_stmt(x < 5, if_body, else_body, get_state, set_state, ('y',), 1) return y
code/api/catalyst.autograph_source
Download Python script
Download Notebook
View on GitHub