Context#
- class braintools.cogtask.Context(key=None)[source]#
Mutable trial-level state container shared across phases.
The Context object is the backbone of inter-phase communication. It holds: - Trial-level state that persists across phases (e.g., ground_truth, stimulus_value) - Time tracking (current timestep, phase boundaries) - Input/output buffers for trial data - RNG for reproducible randomness
Examples
>>> ctx = Context(seed=42) >>> ctx['ground_truth'] = 1 >>> ctx['stimulus_direction'] = 0.5 * np.pi >>> print(ctx['ground_truth']) 1
>>> # In a phase: >>> ctx.inputs[ctx.phase_start:ctx.phase_end, :] = stimulus_encoding
- Parameters:
key (
Array|None) – JAX PRNGKey for random number generation. If None, creates one with seed.
Note
The time step (dt) is obtained from brainstate.environ.get_dt().