Serial¶
- class Serial(connection: Connection, neuron: Neuron, transform: OneToOne[Tensor] | None = None, connection_name: str = 'serial', neuron_name: str = 'serial')[source]¶
Bases:
LayerLayer with a single connection and single neuron group.
This wraps
Layerto provide simplified accessors and a simplifiedforward()method for layers with one connection and one neuron group.- Parameters:
connection (Connection) – module which receives input to the layer.
neuron (Neuron) – module which generates output from the layer.
transform (OneToOne[torch.Tensor] | None, optional) – function to apply to connection output before passing into neurons. Defaults to
None.connection_name (str, optional) – name for the connection in the layer. Defaults to
"serial".neuron_name (str, optional) – name for the neuron in the layer. Defaults to
"serial".
Note
When
transformis not specified, the identity function is used. Keyword arguments passed into__call__, other than those captured inforward()will be passed in.Note
The
Layerobject underlying aSerialobject hasconnectionandneuronregistered with names"serial". Convenience properties can be used to avoid accessing manually.- add_cell(*args, **kwargs) None[source]¶
Creates and adds a cell if it doesn’t exist.
If a cell already exists with the given connection and neuron, this will return the existing cell rather than create a new one.
- Parameters:
- Raises:
AttributeError –
connectiondoes not specify a connection.AttributeError –
neurondoes not specify a neuron.
- Returns:
cell specified by the connection and neuron.
- Return type:
- add_connection(*args, **kwargs) None[source]¶
Adds a new connection.
- Parameters:
name (str) – name of the connection to add.
connection (Connection) – connection to add.
- Raises:
RuntimeError –
namealready specifies a connection- Returns:
added connection.
- Return type:
- add_neuron(*args, **kwargs) None[source]¶
Adds a new neuron.
- Parameters:
- Raises:
RuntimeError –
namealready specifies a neuron- Returns:
added neuron.
- Return type:
- property connection: Connection¶
Registered connection.
- Returns:
registered connection.
- Return type:
- del_cell(*args, **kwargs) None[source]¶
Deletes a created cell if it exists.
Even if a cell hasn’t been created with the given pair, if the pair is valid, this will not raise an error.
- Parameters:
- Raises:
AttributeError –
connectiondoes not specify a connection.AttributeError –
neurondoes not specify a neuron.
- del_connection(*args, **kwargs) None[source]¶
Deletes an existing connection.
- Parameters:
name (str) – name of the connection to delete.
- Raises:
AttributeError –
namedoes not specify a connection.
- del_neuron(*args, **kwargs) None[source]¶
Deletes an existing neuron.
- Parameters:
name (str) – name of the neuron to delete.
- Raises:
ValueError –
namedoes not specify a neuron.
- forward(*inputs: Tensor, connection_kwargs: dict[str, Any] | None = None, neuron_kwargs: dict[str, Any] | None = None, capture_intermediate: bool = False, **kwargs) Tensor | tuple[Tensor, Tensor][source]¶
Computes a forward pass.
- Parameters:
*inputs (torch.Tensor) – values passed to the connection.
connection_kwargs (dict[str, dict[str, Any]] | None, optional) – keyword arguments for the connection’s forward call. Defaults to
None.neuron_kwargs (dict[str, dict[str, Any]] | None, optional) – keyword arguments for the neuron’s forward call. Defaults to
None.capture_intermediate (bool, optional) – if output from the connections should also be returned. Defaults to
False.**kwargs (Any) – keyword arguments passed to
wiring().
- Returns:
output from the neurons, if
capture_intermediate, this is the first element of a tuple, the second being the output from the connection.- Return type:
- property synapse: Synapse¶
Registered synapse.
- Returns:
registered connection’s synapse.
- Return type:
- property updater: Updater¶
Registered updater.
- Returns:
registered connection’s updater.
- Return type:
- wiring(inputs: dict[str, Tensor], **kwargs) dict[str, Tensor][source]¶
Connection logic between connection outputs and neuron inputs.
This implements the forward logic of the serial topology. The
transformis applied to the result of the connection before being passed to the neuron. If not specified, it is assumed to be identity.- Parameters:
inputs (dict[str, torch.Tensor]) – dictionary of input names to tensors.
- Returns:
dictionary of output names to tensors.
- Return type: