NSCallback

class jaxrens.sampling.run_loop.NSCallback(*args, **kwargs)[source]

Bases: Protocol

The hooks an NS loop callback may implement.

Called at the outer loop boundary (Python level, outside JIT/pmap): on_start once after init, on_iteration per iteration via _dispatch_callbacks below, and on_finish once at the end. Implementations live in jaxrens.cli.monitor.

Every hook is optional. Each dispatch site guards with hasattr, so a callback implements whichever subset it needs — most implement on_iteration and on_finish only. That is why the runtime signatures below annotate callbacks as list[Any] rather than list[NSCallback]: jaxrens.sampling is instrumented by jaxtyping/beartype (see --jaxtyping-packages in pyproject.toml), which isinstance-checks every annotation, and isinstance against a Protocol requires all members to be present. A Protocol cannot express optional members, so annotating with this one rejected every callback in the codebase — see the note in _dispatch_callbacks.

Use it for explicit opt-in checks and for static type checkers; treat it as the documented shape, not as an enforced one.