neuromap.network¶
neuromap.network
¶
High-level Network builder for Neuromap neuromorphic chips.
A :class:Network is the central object in the Neuromap SDK. It wraps
a :class:~neuromap._internal.dynamic_snn.DynamicSNN model with the
:class:~neuromap.chip.ChipSpec that describes the target hardware,
providing convenience methods for inference, streaming, persistence and
introspection.
Example::
from neuromap import Network, chips
net = Network(chips.NEUROSOC_V1)
print(net.summary())
Network
¶
Chip-aware SNN wrapper.
A :class:Network owns a :class:DynamicSNN model and carries the
:class:ChipSpec (or equivalent topology metadata) used to build it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chip
|
ChipSpec
|
The chip specification whose topology and neuron parameters will be used to construct the underlying SNN. |
required |
use_decoder
|
bool
|
Append a trainable linear decoder on the output layer. Useful for continuous regression tasks. |
True
|
membrane_readout
|
bool
|
If |
False
|
chip
property
¶
The chip specification backing this network.
model
property
¶
The underlying PyTorch :class:DynamicSNN module.
layers
property
¶
Layer sizes as a list.
input_size
property
¶
Number of input features.
output_size
property
¶
Number of output features.
device
property
¶
Device of the first model parameter (or cpu if empty).
from_topology(layers, *, weight_bits=4, neuron_params=None, name='custom', use_decoder=True, membrane_readout=False)
classmethod
¶
Build a :class:Network from an explicit layer topology.
This is the escape-hatch for simulation-only experiments that are not constrained to a specific physical chip.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layers
|
list[int] | tuple[int, ...]
|
Sequence of layer sizes (e.g. |
required |
weight_bits
|
int
|
Bit-width for quantization metadata. |
4
|
neuron_params
|
Mapping[str, Any] | None
|
Optional dict of LIF neuron parameters. |
None
|
name
|
str
|
Name for the synthetic chip spec. |
'custom'
|
use_decoder
|
bool
|
Whether to include the linear decoder. |
True
|
membrane_readout
|
bool
|
Use membrane potential readout on the last layer. |
False
|
Returns:
| Type | Description |
|---|---|
Network
|
A new :class: |
to(device)
¶
Move the model to device and return self.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
str | device
|
Target device (e.g. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
This |
Network
|
class: |
infer(x, *, state=None, return_state=False)
¶
Run rate-coded inference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Input tensor |
required |
state
|
Mapping[str, Mapping[str, Any]] | None
|
Optional carry-over state for streaming. |
None
|
return_state
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
Tensor | tuple[Tensor, dict[str, Any]]
|
Output tensor |
Tensor | tuple[Tensor, dict[str, Any]]
|
|
infer_sequence(x)
¶
Run per-frame sequence inference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Input tensor |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Output tensor |
infer_stream(x_chunk, state=None)
¶
Stateful streaming inference - process one chunk at a time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x_chunk
|
Tensor
|
Input chunk |
required |
state
|
Mapping[str, Mapping[str, Any]] | None
|
State from the previous call, or |
None
|
Returns:
| Type | Description |
|---|---|
tuple[Tensor, dict[str, Any]]
|
Tuple of |
summary()
¶
Return a human-readable summary of the network.
save(path)
¶
Save the network (model weights + chip spec) to a .pt file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Destination file path. |
required |
load(path, *, device='cpu')
classmethod
¶
Load a network previously saved with :meth:save.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to the |
required |
device
|
str | device
|
Device to load the model onto. |
'cpu'
|
Returns:
| Type | Description |
|---|---|
Network
|
A restored :class: |