Skip to content

neuromap (convenience)

High-level helpers for the common workflow, importable directly from the top-level package (import neuromap as nm).

neuromap.convenience

Convenience functions for the simplified Neuromap workflow.

These high-level helpers wrap the core SDK classes to provide a streamlined developer experience for common tasks: encoding sensor data, configuring surrogate gradients, and exporting to hardware.

encode_sensor_data(data, num_steps=100, method='rate', **kwargs)

Encode continuous data into spike trains.

Parameters:

Name Type Description Default
data Tensor

Input tensor. For "rate" and "latency" methods the shape should be (batch, features) (or (time, features) for a single trace). Values should be in [0, 1]; otherwise they are min-max scaled per feature over leading dimensions. For "delta" the shape should be (batch, time_steps, features).

required
num_steps int

Number of time steps (used by "rate" and "latency").

100
method str

Encoding strategy - "rate", "latency", or "delta".

'rate'
**kwargs Any

Extra arguments forwarded to the underlying encoder.

{}

Returns:

Type Description
Tensor

Spike tensor. For "rate" and "latency" the shape is

Tensor

(batch, num_steps, features).

Raises:

Type Description
ValueError

If method is not recognised.

compile_model(network, surrogate='atan')

Inject an snnTorch surrogate gradient into all LIF layers.

This configures the network's neuron layers for training by replacing their surrogate gradient functions.

Parameters:

Name Type Description Default
network Any

A :class:~neuromap.network.Network instance.

required
surrogate str

Surrogate gradient name (see :func:~neuromap._internal.spike.get_surrogate).

'atan'

quantize_and_export_to_spi(network, bit_resolution=4, path=None)

Quantize model weights and export to .nmap format.

Parameters:

Name Type Description Default
network Any

A :class:~neuromap.network.Network instance.

required
bit_resolution int

Bit-width for weight quantization.

4
path str | Path | None

If provided, save the .nmap file to this path and return None. Otherwise return the raw bytes.

None

Returns:

Type Description
bytes | None

The .nmap bytes when path is None, otherwise None.