braincell.quad.state_grouping

Contents

braincell.quad.state_grouping#

braincell.quad.state_grouping(enabled=True)#

Scope whether state() / hidden_state() group.

Channel, ion, and synapse code is shared by braincell.SingleCompartment and braincell.Cell, so the correct hidden-state class cannot be chosen statically at the creation site. Instead the host publishes its identity for the duration of init_state / reset_state, and the factories read it from this context.

A contextvars variable — not a module-level global — is used so that nesting, exceptions, and threads all restore the previous value correctly.

Parameters:

enabled (bool) – True inside a braincell.Cell, False inside a braincell.SingleCompartment. Both hosts set it explicitly, so a braincell.Network holding a mix of the two is correct regardless of construction order.

Yields:

bool – The value now in effect, for convenience.

See also

state

Allocate an integrable hidden state under this scope.

hidden_state

Allocate a non-integrable hidden state under this scope.

Examples

>>> import brainunit as u
>>> import numpy as np
>>> import braincell
>>> with braincell.state_grouping(True):
...     st = braincell.state(np.zeros((1, 4)) * u.mV)
>>> type(st).__name__
'DiffEqGroupState'