ParamDesc#

class brainstate.mixin.ParamDesc[source]#

Mixin for describing initialization parameters.

This mixin enables a class to have a desc classmethod, which produces an instance of ParamDescriber. This is useful for creating parameter templates that can be reused to instantiate multiple objects with the same configuration.

non_hashable_params#

Names of parameters that are not hashable and should be handled specially.

Type:

sequence of str, optional

Notes

This mixin can be applied to any Python class, not just brainstate-specific classes.

Examples

Basic usage of ParamDesc:

>>> import brainstate
>>>
>>> class NeuronModel(brainstate.mixin.ParamDesc):
...     def __init__(self, size, tau=10.0, threshold=1.0):
...         self.size = size
...         self.tau = tau
...         self.threshold = threshold
>>>
>>> # Create a parameter descriptor
>>> neuron_desc = NeuronModel.desc(size=100, tau=20.0)
>>>
>>> # Use the descriptor to create instances
>>> neuron1 = neuron_desc(threshold=0.8)  # Creates with threshold=0.8
>>> neuron2 = neuron_desc(threshold=1.2)  # Creates with threshold=1.2
>>>
>>> # Both neurons share size=100, tau=20.0 but have different thresholds

Creating reusable templates:

>>> # Define a template for excitatory neurons
>>> exc_neuron_template = NeuronModel.desc(size=1000, tau=10.0, threshold=1.0)
>>>
>>> # Define a template for inhibitory neurons
>>> inh_neuron_template = NeuronModel.desc(size=250, tau=5.0, threshold=0.5)
>>>
>>> # Create multiple instances from templates
>>> exc_population = [exc_neuron_template() for _ in range(5)]
>>> inh_population = [inh_neuron_template() for _ in range(2)]
classmethod desc(*args, **kwargs)[source]#

Create a parameter describer for this class.

Parameters:
  • *args – Positional arguments to be used in future instantiations.

  • **kwargs – Keyword arguments to be used in future instantiations.

Returns:

A descriptor that can be used to create instances with these parameters.

Return type:

ParamDescriber