brainstate.catch_new_states#
- brainstate.catch_new_states(state_tag=None, state_to_exclude=Nothing())[source]#
A context manager that catches and tracks new states created within its scope.
This function creates a new Catcher object and adds it to the TRACE_CONTEXT’s new_state_catcher list. It allows for tracking and managing new states created within the context.
- Parameters:
state_tag (
str) – A string tag to associate with the caught states. Defaults to None.state_to_exclude (
type|str|Callable[[Tuple[Key,...],Any],bool] |bool|Any|None|Tuple[Filter,...] |List[Filter]) – A filter object to specify which states should be excluded from catching. Defaults to Nothing(), which excludes no states.
Example:
with catch_new_states("my_tag") as catcher: # Create new states here # They will be caught and tagged with "my_tag" # Access caught states through catcher object