io#

This module contains methods to handle samna devices, IO and other convenience methods.

calculate_neuron_address(x: int, y: int, c: int, feature_map_size: Tuple[int, int, int]) int[source]#

Calculate the neuron address on the devkit. This function is designed for ReadNeuronValue event to help the user check the neuron value of the SNN on the devkit.

Parameters:
  • x (int) – x coordinate of the neuron

  • y (int) – y coordinate of the neuron

  • c (int) – channel index of the neuron

  • feature_map_size (Tuple[int, int, int]) – the size of the feature map [channel, height, width]

Returns:

neuron_address (int)

close_device(device_id: str)[source]#

Close a device by device identifier

Parameters:

device_id (str) – device_name:device_id pair given as a string. dynapcnndevkit:0 or speck:0 or dynapcnndevkit:1

disable_timestamps(device_id: str) None[source]#

Disable timestamps of the samna node

Parameters:

device_id (str) – Name of the device to initialize. Required for different existing APIs for Dynapcnndevkit and Speck chips

discover_device(device_id: str)[source]#

Discover a samna device by device_name:device_id pair

Parameters:

device_id (str) – Device name/identifier (dynapcnndevkit:0 or speck:0 or dvxplorer:1 … ) The convention is similar to that of pytorch GPU identifier ie cuda:0 , cuda:1 etc.

Returns:

device_info (samna.device.DeviceInfo)

enable_timestamps(device_id: str) None[source]#

Disable timestamps of the samna node

Parameters:

device_id (str) – Name of the device to initialize. Required for different existing APIs for Dynapcnndevkit and Speck chips

events_to_raster(event_list: List, layer: int) Tensor[source]#

Convert an eventList read from samna to a tensor raster by filtering only the events specified by layer.

Parameters:
  • event_list (List) – A list comprising of events from samna API

  • layer (int) – The index of layer for which the data needs to be converted

Returns:

raster (torch.Tensor)

events_to_xytp(event_list: List, layer: int) array[source]#

Convert an eventList read from samna to a numpy structured array of x, y, t, channel.

Parameters:
  • event_list (List) – A list comprising of events from samna API

  • layer (int) – The index of layer for which the data needs to be converted

Returns:

xytc (np.array) – A numpy structured array with columns x, y, t, channel.

get_device_map() Dict[source]#
Returns:

  • dict(str (samna.device.DeviceInfo))

  • Returns a dict of device name and device identifier.

is_device_type(dev_info: DeviceInfo, dev_type: str) bool[source]#

Check if a DeviceInfo object is of a given device type dev_type

Parameters:
  • dev_info (samna.device.DeviceInfo) – Device info object

  • dev_type (str) – Device type as a string

  • Returns

  • -------- – bool

launch_visualizer(receiver_endpoint: str, width_proportion: float = 0.6, height_proportion: float = 0.6, disjoint_process: bool = True)[source]#

Launch the samna visualizer in a separate process.

NOTE: MacOS users will want to use disjoint_process as True as a GUI process cannot be launched as a subprocess.

Parameters:
  • receiver_endpoint (str) – the visualiser’s endpoint for receiving events (e.g. “tcp://0.0.0.0:33335”).

  • width_proportion (bool) – the rate between window width and workarea width of main monitor, default 0.75 which means this window has a width which equals to 3/4 width of main monitor’s workarea.

  • height_proportion (bool) – the rate between window height and workarea height of main monitor, default 0.75 which means this window has a height which equals to 3/4 height of main monitor’s workarea.

  • disjoint_process (bool, optional) – If true, will be launched in a disjoint shell process. Defaults to True. If false, this just runs the default samna command.

Returns:

gui_process (Process) – The gui sub-process handle if disjoint_process was False.

neuron_address_to_cxy(address: int, feature_map_size: Tuple[int, int, int]) Tuple[source]#

Calculate the c, x, y, coordinate of a neuron when the address of the NeuronValue event is given :param address: the neuron address of the NeuronValue event :type address: int :param feature_map_size: the size of the feature map [channel, height, width] :type feature_map_size: Tuple[int, int, int]

Returns:

neuron_cxy (Tuple[int, int, int]) – the [channel, x, y] of the neuron

open_device(device_id: str)[source]#

Open device function.

Parameters:

device_id (str) – device_name:device_id pair given as a string

Returns:

device_handle (samna.device.*) – Device handle received from samna.

reset_timestamps(device_id: str) None[source]#

Disable timestamps of the samna node

Parameters:

device_id (str) – Name of the device to initialize. Required for different existing APIs for Dynapcnndevkit and Speck chips