engine.component
Components handle universal parameters and logic common to neurons, synapses, and their derivatives.
- class engine.component.Component(identifier: str = None, configuration: dict = None, device: str = 'cpu', **kwargs)
Model component base class.
Defines instance attributes and methods shared by all model components. Its primary purpose is to implement generic operations on loggable and configurable attributes.
- Parameters:
identifier (str, optional) – Human-readable identifier for the component instance.
configuration (dict, optional) – Configuration dictionary used during parameter initialization.
device (str, optional) – Specifies a hardware device on which to process this object’s tensors, e.g. “cuda:0”. Must be a valid torch.device() string value. Defaults to “cpu”.
kwargs – Additional instance attributes that the user may set.
See also
- configure(configuration: dict[str, Any] = None, log_destination: str = '')
Applies a configuration to this object by adding the keys of configuration as instance attributes, initializing their values, and updating the _config_props_ tuple to reflect the new keys.
Also updates _loggable_props_ for this object if the configuration includes the key “loggable”.
- Parameters:
configuration (dict or str, optional) – Parameters to be applied to this component, given as a dictionary. If None, this method can be used strictly for saving the configuration to YAML without changing it.
log_destination (str, optional) – Path to a destination YAML file where the configuration will be saved. If not provided, the configuration is not saved to file.
Note
This method is generic and can be used without alterations by all derivative classes.
The sub-dictionary model may include the special sweep key, which specifies settings for the heterogeneous initialization of certain parameters in the form of a dictionary.
- forward(data: Tensor) dict
Processes an input, updates the state of this component, and advances the simulation by one step.
- Parameters:
data (Tensor) – Input to be processed (e.g., added to a neuron’s numeric state tensor voltage).
- Returns:
A dictionary whose keys are loggable attributes and whose values are their states as of this time step. For potential use by a
SimpleSimulator
or any otherPipeline
script handling runtime operations.- Return type:
dict
- Raises:
NotImplementedError – The forward method must be implemented by each derived class.
- heterogenize(num_combinations: int, unravel: bool = True)
Edits configurable tensor attributes based on a sweep search dictionary if one was provided by the user within this object’s configuration dictionary.
Note
If a sweep key is not present in configuration, this method will pass silently, retaining the existing configurable values. It can be invoked safely from generic methods (e.g.,
build()
).- Parameters:
num_combinations (int) – Total number of combinations to return.
unravel (bool) –
When the property is a 2D tensor, dictates whether combination values should be assigned to individual elements (True) or overwrite entire rows (False).
The former behavior is appropriate for synapse attributes. It is achieved using numpy.unravel_index, which maps flattened-like indices to their nD equivalents given the shape of the array.
The latter behavior is called for when values are themselves 1D vectors (e.g., oscillator frequencies).
Warning
This method mutates the underlying component object. To simply view the combinations, initialize a
Sweep
object with your desired search space dictionary and number of combinations.
- loggable_state() dict
Returns a dictionary of this object’s loggable properties and their states as of this simulation step.
- Returns:
Dictionary containing loggable property names and their values.
- Return type:
dict