NSCallback¶
- class jaxrens.sampling.run_loop.NSCallback(*args, **kwargs)[source]¶
Bases:
ProtocolThe hooks an NS loop callback may implement.
Called at the outer loop boundary (Python level, outside JIT/pmap):
on_startonce after init,on_iterationper iteration via_dispatch_callbacksbelow, andon_finishonce at the end. Implementations live injaxrens.cli.monitor.Every hook is optional. Each dispatch site guards with
hasattr, so a callback implements whichever subset it needs — most implementon_iterationandon_finishonly. That is why the runtime signatures below annotatecallbacksaslist[Any]rather thanlist[NSCallback]:jaxrens.samplingis instrumented by jaxtyping/beartype (see--jaxtyping-packagesin pyproject.toml), which isinstance-checks every annotation, andisinstanceagainst 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.