Visualization¶
scaly.viz records what the compiler does to chosen functions: the expression graph, the program
after each optimization pass, and the generated C. It is opt-in. Importing scaly does not import
it, and nothing is recorded for a function that was not marked.
import scaly as sc
from scaly.codegen import render_c_module
from scaly.viz import visualize
@sc.function(sc.arg("x", 3), outputs=sc.arg("energy"))
def energy(x: sc.Expr) -> sc.Expr:
return sc.sumsqr(x)
visualize(energy, label="Energy model")
render_c_module(energy)
Every render of a marked function, whether ahead of time or through the JIT, adds one recording.
Run uv run scaly_viz --browser to browse them. visualize is the same function as
visualize_function.
Registering a declaration does not trace it. Functions with open shapes or no declarations record each instance when it renders, including instances created before registration. Registering a concrete instance records only that instance and takes precedence over an open declaration's registration. Removing either registration leaves the other in place. A fully specified declaration and its sole instance share one registration, so either can unregister it.
Recording¶
visualize_function ¶
Mark fun for visualization on future AOT/JIT renders.
A declaration records all its current and future instances without tracing at registration.
A concrete instance records only itself and takes precedence over an open declaration.
Fully specified declarations share registration with their sole instance.
The function itself is returned so callers can write f = visualize_function(f).
Source code in src/scaly/viz/recording.py
unvisualize_function ¶
Remove fun's registration. Other declarations or instances remain registered.
A fully specified declaration and its sole instance share one registration.
Source code in src/scaly/viz/recording.py
capture ¶
Record renders of fun only inside a with block, which yields fun.
Source code in src/scaly/viz/recording.py
Reading recordings¶
recordings ¶
Return the recordings made in this process, oldest first.
Each is a JSON-ready dict with the display name, the function name, any render error
and the steps: the expression graph, each program-dialect pass and the generated C.
Source code in src/scaly/viz/recording.py
load_recordings ¶
Read the recordings saved at path, by default recording_path(), including those from other processes.
Source code in src/scaly/viz/recording.py
clear_recordings ¶
Forget the recordings made in this process, and with disk=True delete the recording file too.
Source code in src/scaly/viz/recording.py
recording_dir ¶
Return the directory recordings are written to: SCALY_VIZ_DIR, else $XDG_CACHE_HOME/scaly/viz, else ~/.cache/scaly/viz.
Source code in src/scaly/viz/recording.py
recording_path ¶
Browsing¶
serve ¶
serve(*, host: str = '127.0.0.1', port: int = 8000, path: str | Path | None = None, open_browser: bool = False) -> None
Serve the recordings at path, by default recording_path(), until interrupted. The scaly_viz command runs this.