FunctionClamp

Contents

FunctionClamp#

class braincell.FunctionClamp(fn)[source]#

Arbitrary-callable current clamp.

Parameters:

fn (Callable) – A function f(t) -> Quantity[nA] called each step with the absolute simulation time. Use explicit conditions inside fn for windowed current injection.

Notes

Equality and hashing follow identity on fn (frozen dataclass auto-generated dunder methods compare lambdas by ==, which falls back to identity). Two FunctionClamp instances built from two separate lambda definitions with identical bodies are considered distinct.

The runtime layer fingerprints fn by bytecode + closure cells so structurally identical lambdas can merge into one layout. Closure cells holding opaque, non-hashable objects fall back to id(value) and therefore defeat dedup. Such lambdas trigger a one-shot RuntimeWarning — hoist to module level with a named function

to recover dedup.