language.trace
def trace(thunk: typing.Any, strict: bool = False) -> typing.AnyExecute a thunk inside a tracing scope and return the captured config tree.
Within the scope every :func:`configurable`-decorated callable emits a
``DictConfig`` node instead of running its body. The thunk's return value
becomes the root of the captured tree.
The scope is delimited by the thunk (a zero-argument callable) rather
than a ``with`` block so enable/disable can never straddle uncontrolled
evaluation — the ``try/finally`` bracket is leak-safe even on exceptions,
and nesting composes via :class:`~contextvars.ContextVar` tokens::
cfg = L.trace(lambda: Model(encoder=Encoder(depth=24), dim=768))
model = L.instantiate(cfg)
Parameters
| Name | Type | Description |
|---|---|---|
| thunk | callable | A zero-argument callable whose body describes the configuration. Side effects inside the thunk run during tracing — keep bodies pure-ish. |
| strict = ``False`` | bool | When ``True`` (or ``False``, in the current implementation), raises if the root result is not a config node or OmegaConf primitive. A future release will add ``L.just``-wrapping for the ``strict=False`` path once the classifier's third tier is stable. |
Returns
DictConfig — Statically typed as ``R`` (the thunk's static return type) — the lie-typing contract keeps nested composition tractable. At runtime always a ``DictConfig`` (or OmegaConf primitive, for a no-op/identity thunk).
Source: laco/language.py:1205