Core¶
Tracing turns an ordinary Python function into an executable IR.
- autoform.trace(func, /, *, static=False)[source]¶
Build an IR by tracing a function’s execution.
- Parameters:
func (Callable[[Unpack[A]], R]) – A callable that uses autoform primitives (format, concat, lm_call, etc.).
static (Tree[bool]) – Bool pytree matching the positional input structure. Mark a leaf
Trueto keep that value fixed at trace time. Mark a leafFalseto keep it as a normal runtime input. This is useful for ordinary Python control flow such asifstatements. Later calls must pass the same values for leaves marked static.
- Returns:
A tracer callable that takes positional arguments and returns an IR.
- Return type:
When a flag is marked static, tracing follows only the branch selected by that flag at trace time.
Example
>>> import autoform as af >>> def label(is_error): ... if is_error: ... return "error" ... return "ok" >>> ir = af.trace(label, static=True)(True) >>> ir.call(True) 'error'