Skip to content

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 True, the last SNN layer outputs continuous pre-spike membrane potentials instead of binary spikes. Essential for regression tasks (e.g. denoising) where the network must produce continuous-valued output.

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. [32, 16, 8]).

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:Network instance.

to(device)

Move the model to device and return self.

Parameters:

Name Type Description Default
device str | device

Target device (e.g. "cpu" or "cuda").

required

Returns:

Name Type Description
This Network

class:Network instance for chaining.

infer(x, *, state=None, return_state=False)

Run rate-coded inference.

Parameters:

Name Type Description Default
x Tensor

Input tensor (batch, time_steps, input_size).

required
state Mapping[str, Mapping[str, Any]] | None

Optional carry-over state for streaming.

None
return_state bool

If True, also return the next state dict.

False

Returns:

Type Description
Tensor | tuple[Tensor, dict[str, Any]]

Output tensor (batch, output_size), or a tuple

Tensor | tuple[Tensor, dict[str, Any]]

(output, next_state) when return_state is set.

infer_sequence(x)

Run per-frame sequence inference.

Parameters:

Name Type Description Default
x Tensor

Input tensor (batch, frames, input_size).

required

Returns:

Type Description
Tensor

Output tensor (batch, frames, output_size).

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 (batch, time_steps, input_size).

required
state Mapping[str, Mapping[str, Any]] | None

State from the previous call, or None for the first chunk.

None

Returns:

Type Description
tuple[Tensor, dict[str, Any]]

Tuple of (output, next_state).

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 .pt checkpoint.

required
device str | device

Device to load the model onto.

'cpu'

Returns:

Type Description
Network

A restored :class:Network instance.