Params#

class braincell.mech.Params(data=None, /, **kwargs)[source]#

Frozen, hashable, order-preserving mechanism parameter mapping.

Parameters:
  • data (object) – Initial key-value pairs. When None (the default), the mapping starts empty.

  • **kwargs (Any) – Additional parameters provided as keyword arguments. These override entries of the same name in data.

Notes

  • Iteration order matches declaration order: entries in data come first (in their original order), followed by entries in kwargs (in the order they were passed).

  • Equality is dict-like — two instances with the same key-value pairs compare equal regardless of iteration order.

  • Hashing is consistent with equality: instances that compare equal share the same hash, so Params is safe to use as a dict key or set element.

Examples

>>> import brainunit as u
>>> from braincell.mech import Params
>>> p = Params(g_max=0.1 * u.mS / u.cm ** 2, E=-70 * u.mV)
>>> p["g_max"]
0.1 * mS / cm ** 2
>>> list(p)
['g_max', 'E']
>>> p == Params(E=-70 * u.mV, g_max=0.1 * u.mS / u.cm ** 2)
True
classmethod coerce(value)[source]#

Convert value to a Params instance.

Parameters:

value (object) – Source data.

Returns:

If value is already a Params, it is returned unchanged. Otherwise, a new instance is constructed.

Return type:

Params

get(key, default=None)[source]#
Return type:

Any

items() a set-like object providing a view on D's items[source]#
keys() a set-like object providing a view on D's keys[source]#
values() an object providing a view on D's values[source]#
with_updates(**kwargs)[source]#

Return a copy with kwargs merged in.

Parameters:

**kwargs (Any) – Parameters to add or replace. Keys already present in self keep their original position in iteration order; new keys are appended at the end.

Returns:

A new Params instance. self is unchanged.

Return type:

Params

without(*keys)[source]#

Return a copy with the given keys removed.

Unknown keys are silently ignored.

Parameters:

*keys (str) – Keys to drop.

Returns:

A new Params instance.

Return type:

Params