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.SingleCompartmentandbraincell.Cell, so the correct hidden-state class cannot be chosen statically at the creation site. Instead the host publishes its identity for the duration ofinit_state/reset_state, and the factories read it from this context.A
contextvarsvariable — not a module-level global — is used so that nesting, exceptions, and threads all restore the previous value correctly.- Parameters:
enabled (
bool) –Trueinside abraincell.Cell,Falseinside abraincell.SingleCompartment. Both hosts set it explicitly, so abraincell.Networkholding a mix of the two is correct regardless of construction order.- Yields:
bool – The value now in effect, for convenience.
See also
stateAllocate an integrable hidden state under this scope.
hidden_stateAllocate 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'