API Reference: hxtorch

hxtorch from Python

hxtorch.perceptron.nn.Conv1d : public hxtorch.perceptron.nn.ConvNd , public torch.nn.Conv1d

Applies a 1D convolution over an input signal composed of several input planes.

Subclassed by hxtorch.perceptron.nn.ExpandedConv1d

Public Functions

__init__(self, Integral in_channels, Integral out_channels, Union[Integral, Tuple[Integral]] kernel_size, Integral stride=1, Union[Integral, Tuple[Integral, Integral]] padding=0, Union[Integral, Tuple] dilation=1, Integral groups=1, bool bias=True, str padding_mode='zeros', Optional[Integral] num_sends=None, Integral wait_between_events=defaults.wait_between_events, bool mock=False, *Optional[Callable[[torch.Tensor], torch.Tensor]] input_transform=None, Optional[Callable[[torch.Tensor], torch.Tensor]] weight_transform=clamp_weight_)

:param in_channels: Number of channels in the input :param out_channels: Number of channels produced by the convolution :param kernel_size: Size of the convolving kernel :param stride: Stride of the convolution :param padding: Zero-padding added to both sides of the input :param padding_mode: ‘zeros’, ‘reflect’, ‘replicate’ or ‘circular’ :param dilation: Spacing between kernel elements :param groups: Number of blocked connections from input channels to output channels :param bias: If True, adds a learnable bias to the output :param num_sends: Number of sends of the input.

Values greater than 1 result in higher output to the neurons and increases the s/n ratio. For None this is automatically adjusted during initialization. :param wait_between_events: Wait time between two successive vector inputs, in FPGA clock cycles. Shorter wait time can lead to saturation of the synaptic input. :param mock: Enable mock mode. :param input_transform: Function that receives the input and returns a tensor to be used as input to the chip. :param weight_transform: Function that receives the weight and returns a tensor to be used as weight matrix on the chip.

Protected Attributes

_conv
hxtorch.perceptron.nn.Conv2d : public hxtorch.perceptron.nn.ConvNd , public torch.nn.Conv2d

Applies a 2D convolution over an input image composed of several input planes.

Public Functions

__init__(self, Integral in_channels, Integral out_channels, Union[Integral, Tuple[Integral, Integral]] kernel_size, Integral stride=1, Union[Integral, Tuple[Integral, Integral]] padding=0, Integral dilation=1, Integral groups=1, bool bias=True, str padding_mode='zeros', Optional[Integral] num_sends=None, Integral wait_between_events=defaults.wait_between_events, bool mock=False, *Optional[Callable[[torch.Tensor], torch.Tensor]] input_transform=None, Optional[Callable[[torch.Tensor], torch.Tensor]] weight_transform=clamp_weight_)

:param in_channels: Number of channels in the input :param out_channels: Number of channels produced by the convolution :param kernel_size: Size of the convolving kernel :param stride: Stride of the convolution :param padding: Zero-padding added to both sides of the input :param padding_mode: ‘zeros’, ‘reflect’, ‘replicate’ or ‘circular’ :param dilation: Spacing between kernel elements :param groups: Number of blocked connections from input channels to output channels :param bias: If True, adds a learnable bias to the output :param num_sends: Number of sends of the input.

Values greater than 1 result in higher output to the neurons and increases the s/n ratio. For None this is automatically adjusted during initialization. :param mock: Enable mock mode. :param wait_between_events: Wait time between two successive vector inputs, in FPGA clock cycles. Shorter wait time can lead to saturation of the synaptic input. :param input_transform: Function that receives the input and returns a tensor to be used as input to the chip. :param weight_transform: Function that receives the weight and returns a tensor to be used as weight matrix on the chip.

Protected Attributes

_conv
hxtorch.perceptron.nn.ConvertingReLU : public hxtorch.perceptron.nn.ReLU

Applies a rectified linear unit to the input, shifts and clips to the input range of the chip.

Public Functions

__init__(self, Integral shift=2, bool mock=False)

:param shift: Number of bits the result is shifted by :param mock: Enable mock mode

forward(self, torch.Tensor input)

Public Members

shift
hxtorch.perceptron.nn.ConvNd : public hxtorch.perceptron.nn.MACLayer , public torch.nn.modules.conv._ConvNd

Base class for n-dimensional convolution.

Subclassed by hxtorch.perceptron.nn.Conv1d, hxtorch.perceptron.nn.Conv2d

Public Functions

forward(self, input)

Public Members

padding_mode

Protected Functions

_conv(self, torch.Tensor input, torch.Tensor weight, torch.Tensor bias, Tuple[Integral, ...] stride, **kwargs)

Implementation of convolution function.

hxtorch.perceptron.nn.ExpandedConv1d : public hxtorch.perceptron.nn.Conv1d

Unrolls the weight matrix for execution on hardware.

This maximizes the use of the synapses array.

Caveat: Fixed-pattern noise cannot be individually compensated for during training, because the same weights are used at different locations!

Public Functions

__init__(self, int in_channels, int out_channels, Union[int, Tuple[int]] kernel_size, int stride=1, Union[int, Tuple[int, int]] padding=0, Union[int, Tuple] dilation=1, int groups=1, bool bias=True, str padding_mode='zeros', Optional[int] num_sends=None, int wait_between_events=defaults.wait_between_events, bool mock=False, *Optional[Callable[[torch.Tensor], torch.Tensor]] input_transform=None, Optional[Callable[[torch.Tensor], torch.Tensor]] weight_transform=clamp_weight_, Optional[int] num_expansions=None)

:param in_channels: Number of channels in the input :param out_channels: Number of channels produced by the convolution :param kernel_size: Size of the convolving kernel :param stride: Stride of the convolution :param padding: Zero-padding added to both sides of the input :param padding_mode: ‘zeros’, ‘reflect’, ‘replicate’ or ‘circular’ :param dilation: Spacing between kernel elements :param groups: Number of blocked connections from input channels to output channels :param bias: If True, adds a learnable bias to the output :param num_sends: Number of sends of the input.

Values greater than 1 result in higher output to the neurons and increases the s/n ratio. For None this is automatically adjusted during initialization. :param wait_between_events: Wait time between two successive vector inputs, in FPGA clock cycles. Shorter wait time can lead to saturation of the synaptic input. :param mock: Enable mock mode. :param input_transform: Function that receives the input and returns a tensor to be used as input to the chip. :param weight_transform: Function that receives the weight and returns a tensor to be used as weight matrix on the chip. :param num_expansions: Number of enrolled kernels in a single operation

extra_repr(self)

Public Members

num_expansions

Protected Functions

_conv(self, *args, **kwargs)
class hxtorch.perceptron.nn.Layer

Base class of all layers in :mod:hxtorch.nn.

Subclassed by hxtorch.perceptron.nn.MACLayer, hxtorch.perceptron.nn.ReLU

Public Functions

__init__(self, bool mock=False)

:param mock: Enable mock mode.

__repr__(self)

Public Members

mock
hxtorch.perceptron.nn.Linear : public hxtorch.perceptron.nn.MACLayer , public torch.nn.Linear

Applies a linear transformation to the incoming data on Hicann-X.

Public Functions

__init__(self, Integral in_features, Integral out_features, bool bias=True, Optional[Integral] num_sends=None, Integral wait_between_events=defaults.wait_between_events, bool mock=False, *Integral avg=1, Optional[Callable[[torch.Tensor], torch.Tensor]] input_transform=None, Optional[Callable[[torch.Tensor], torch.Tensor]] weight_transform=clamp_weight_)

:param in_features: Size of each input sample :param out_features: Size of each output sample :param bias: If set to True, the layer will learn an additive bias.

:param num_sends: Number of sends of the input. Values greater than 1 result in higher output to the neurons and increases the s/n ratio. For None this is automatically adjusted during initialization. :param wait_between_events: Wait time between two successive vector inputs, in FPGA clock cycles. Shorter wait time can lead to saturation of the synaptic input. :param mock: Enable mock mode. :param avg: Number of neurons to average over. This option is targeted at reducing statistical noise. Beware: We average over different fixed-pattern instances, but they are all configured at the same weight, so they are not trained individually. This could potentially have negative implications. :param input_transform: Function that receives the input and returns a tensor to be used as input to the chip. :param weight_transform: Function that receives the weight and returns a tensor to be used as weight matrix on the chip.

forward(self, input)

Public Members

avg

Protected Attributes

_matmul
hxtorch.perceptron.nn.MACLayer : public hxtorch.perceptron.nn.Layer

Layer that performs a multiply accumulate operation.

Subclassed by hxtorch.perceptron.nn.ConvNd, hxtorch.perceptron.nn.Linear

Public Functions

__init__(self, Optional[Integral] num_sends=None, Integral wait_between_events=defaults.wait_between_events, bool mock=False, *Optional[Callable[[torch.Tensor], torch.Tensor]] input_transform=None, Optional[Callable[[torch.Tensor], torch.Tensor]] weight_transform=clamp_weight_)

:param num_sends: Number of sends of the input.

Values greater than 1 result in higher output to the neurons and increases the s/n ratio. For None this is automatically adjusted during initialization. :param wait_between_events: Wait time between two successive vector inputs, in FPGA clock cycles. Shorter wait time can lead to saturation of the synaptic input. :param mock: Enable mock mode. :param input_transform: Function that receives the input and returns a tensor to be used as input to the chip. :param weight_transform: Function that receives the weight and returns a tensor to be used as weight matrix on the chip.

reset_parameters(self, Real weight_mean=0., Integral relu_shift=1)

Reset parameters to reasonable initialization values.

Method based on Delving deep into rectifiers: Surpassing human-level performance on ImageNet classification - He, K. et al. (2015)

:param weight_mean: Mean value of the weight distribution :param relu_shift: Bit shift assumed in subsequent ConvertingReLU

Public Members

input_transform
num_sends
wait_between_events
weight_transform
hxtorch.perceptron.nn.ReLU : public hxtorch.perceptron.nn.Layer , public torch.nn.ReLU

Applies a rectified linear unit to the input.

Subclassed by hxtorch.perceptron.nn.ConvertingReLU

Public Functions

__init__(self, bool mock=False)

:param mock: Enable mock mode

forward(self, torch.Tensor input)
hxtorch.spiking.backend.module_manager.BaseModuleManager : public ABC

Abstract base class for module manager.

Subclassed by hxtorch.spiking.backend.module_manager.ModuleManager

Public Functions

__init__(self)
__str__(self)

Add proper object string.

add_node(self, Module module, Source sources, Target target)

Adds a new module to the manager.

This method adds a node to the internal graph to represent the module. It assigned edges to this node holding the data in sources, resp. target. :param module: Module to represented in to the graph. :param sources: The sources to the node representing module. :param targets: The targets of the node representing module.

add_wrapper(self, Wrapper wrapper)

Adds a new wrapper to the manager.

This must be called after all modules wrapped by this wrapper are represented in the graph. internal graph to represent the module. It assigned edges to this node holding the data in sources, resp. target. :param module: Module to represented in to the graph.

clear(self)

Clear the internal graph and remove the module -> node and wrapper -> node mapping.

done(self)

Create a list of elements of form (module, sources, targets), which can be looped in the correct order.

:return: Returns the a list of nodes to be executed.

Public Members

graph
hxtorch.spiking.backend.module_manager.ModuleManager : public hxtorch.spiking.backend.module_manager.BaseModuleManager

Object representing all nodes in a graph-like data structure.

Public Functions

__init__(self)

Initialize a Modules object.

This object holds a list of nodes.

__str__(self)

Append string.

add_node(self, Module module, Source sources, Target target)

Adds a new module to the manager.

This method adds a node to the internal graph to represent the module. It assigned edges to this node holding the data in sources, resp. target. :param module: Module to represented in to the graph. :param sources: The sources to the node representing module. :param targets: The targets of the node representing module.

add_wrapper(self, Wrapper wrapper)

Adds a new wrapper to the manager.

This must be called after all modules wrapped by this wrapper are represented in the graph. internal graph to represent the module. It assigned edges to this node holding the data in sources, resp. target. :param module: Module to represented in to the graph.

changed_since_last_run(self)

Check if any module is marked dirty.

:return: Returns true if at least one module has been marked dirty.

clear(self)

Override clear to also clear open sources and open targets.

This method resets the Manager without removing implicitly created input modules such that they can be reused.

done(self)

Create a list of elements of form (module, sources, targets), which can be looped in the correct order.

:param instance: The instance to work on. :return: Returns the ordered modules in the form (module, sources, targets).

find_edges(self, Any handle)

Find all edges with data associated with handle.

:param handle: The edge data to match against. :return: Returns a list of all edges in the graph which hold the same data handle.

get_id_by_module(self, Module module)

Finds the ID of the node which corresponds to module module.

If no ID is found, None is returned. :param module: The module to find the node ID for. :returns: Returns the node ID or None if no ID is found.

get_id_by_wrapper(self, Wrapper wrapper)

Finds the ID of the wrapper which corresponds to wrapper wrapper.

If no ID is found, None is returned. :param wrapper: The wrapper module to find the node ID for. :returns: Returns the node ID or None if no ID is found.

get_module_by_id(self, int node_id)

Finds the module of the node with ID node_id and returns it.

If multiple modules assigned to this ID are found, only the first one is returned. However, this should never be the case and if so, it is a bug. :param node_id: The ID of the node to find the module for. :returns: Returns the corresponding module.

get_node_id(self)

Get the ID of the next node to add.

:returns: Returns the next usable ID of a node to add.

get_wrapper_by_id(self, int wrapper_id)

Finds the wrapper of the node with ID wrapper_id and returns it.

If multiple wrapper assigned to this ID are found, only the first one is returned. However, this should never be the case and if so, it is a bug. :param wrapper_id: The ID of the node to find the module for. :returns: Returns the corresponding wrapper.

get_wrapper_id(self)

Get the ID of the next wrapper to add.

:returns: Returns the next usable ID of a wrapper to add.

has_module(self, Module module)

Checks whether the module module is already registered within the graph.

:param module: The module to check its existence for. :return: Returns a bool indicating whether the module exists or not.

input_data(self)

Finds all edge data associated to edges with a source node in _open_sources, those nodes are roots.

:return: Returns a list of all input data.

pre_process(self, instance)

Handle all preprocessing needed prior to hardware execution.

This includes input module injection as well as setting the dropout masks.

reset_changed_since_last_run(self)

Restes all registered modules changed_since_last_run flags.

source_populations(self, Module module)

Find the source populations of module module, i.e.

modules which are of type self._population_types. :param module: The module to find the source population. :return: Returns a list of source populations of module.

target_populations(self, Module module)

Find the target populations of module module, i.e.

modules which are of type self._population_types. :param module: The module to find the target populations for. :return: Returns a list of target populations of module.

Public Static Attributes

input_type = spiking_module.InputNeuron
population_types = (spiking_module.InputNeuron, spiking_module.Neuron,spiking_module.ReadoutNeuron)

Protected Functions

_get_populations(self, Module module, bool target=False)

Find the target, resp.

source populations of module module, i.e. modules which are of type self._population_types. :param module: The module to find the source population (target=False) or the target populations for(target=True) :param target: A bool indicating whether the search is performed for source or target populations. :return: Returns a list of source, resp. target populations of module.

_handle_dropout_mask(self)

Method to back-assign spiking mask from Dropout layers to the previous Neuron layer in order to configure the neurons appropriately on hardware.

Note: BatchDropout layers have to be preceded by a Neuron layer.

_handle_inputs(self, instance)

On hardware, synapse have external populations as sources.

Hence we have to augment Synapses with InputNeurons.

_handle_wrappers(self)

Handle registered wrappers.

This method needs to be called after all modules are registered. It replaces all nodes associated with the nodes in a given wrapper in the graph. All internal target handles are gathered in the wrapper’s node attributes ‘targets’. All external input sources to the wrapper are gathered in the node attributes ‘sources’.

_order(self)

This method checks whether the internal graph representation has no cyclic dependencies.

Cyclic dependencies need to be wrapped manually at the moment. TODO: Introduce implicit module wrapping here. Further, a topological sort is performed in order to return the nodes in an order in which all modules can be executed successively. :return: Returns a list of tuples of shape (module, sources, targets), where sources is a tuple of all input sources and targets is a tuple of all output targets of module module.

Protected Attributes

_graph_hash
hxtorch.spiking.datasets.yinyang.YinYangDataset : public Dataset

YinYang dataset.

Public Functions

__init__(self, float r_small=0.1, float r_big=0.5, int size=1000, int seed=42, Optional[torch.nn.Module] transform=None)

Instantiate the YinYang dataset.

This dataset provides data points on a 2-dimensional plane within a yin-yang sign. Each data point is assigned to one of three classes: The eyes, the yin or the yang. :param r_small: The radius of the eyes in the yin-yang sign. :param r_big: The radius of the whole sign. :param size: The size of the dataset, i.e. number of data points within the sign. :param seed: Random seed. :param transform: An optional transformation applied to the returned samples.

__getitem__(self, int index)

Get an item from the dataset.

:param index: Index of the item in the dataset. :returns: Returns a tuple (sample, target), where sample is an array with values (x, y, 1 - x, 1 - y).

__len__(self)
dist_to_left_dot(self, int x, int y)

Compute the distance to the left dot.

:param x: The x-coordinate. :param y: The y-coordinate. :returns: Returns the distance to the left dot.

dist_to_right_dot(self, int x, int y)

Compute the distance to the right dot.

:param x: The x-coordinate. :param y: The y-coordinate. :returns: Returns the distance to the right dot.

get_sample(self, Optional[int] goal=None)

Sample one data point from the yin-yang sign with goal class goal.

If goal is None any sample of any class is returned. :param goal: The target class of the sample to return. If None is given, any sample regardless of its class is returned. :returns: Returns a tuple (x coordinate, y coordinate, class), where the coordinates are on the xy-plane.

which_class(self, float x, float y)

Assign a sample on the xy-plane with coordinates (x, y) to its class.

:param x: The x-coordinate. :param y: The y-coordinate. :returns: An integer indicating the samples class.

Public Members

class_names
r_big
r_small
rng
transform

Private Members

__cs
__vals
hxtorch.spiking.experiment.BaseExperiment : public ABC

Subclassed by hxtorch.spiking.experiment.Experiment

Public Functions

__init__(self, BaseModuleManager modules, bool mock, float dt)
connect(self, torch.nn.Module module, handle.TensorHandle input_handles, handle.TensorHandle output_handle)
get_hw_results(self, Optional[int] runtime)

Public Members

dt
mock
modules
hxtorch.spiking.experiment.Experiment : public hxtorch.spiking.experiment.BaseExperiment

Experiment class for describing experiments on hardware.

Public Functions

__init__(self, bool mock=False, float dt=1e-6, Optional[Union[Path, str]] calib_path=None, hw_routing_func=grenade.network.routing.PortfolioRouter())

Instantiate a new experiment, representing an experiment on hardware and/or in software.

:param mock: Indicating whether module is executed on hardware (False) or simulated in software (True).

clear(self)

Reset the experiments’s state.

Corresponds to creating a new Experiment instance.

connect(self, torch.nn.Module module, Tuple[handle.TensorHandle] input_handles, handle.TensorHandle output_handle)

Add an module to the experiment and connect it to other experiment modules via input and output handles.

:param module: The HXModule to add to the experiment. :param input_handles: The TensorHandle serving as input to the module (its obsv_state). :param output_handle: The TensorHandle outputted by the module, serving as input to subsequent HXModules.

get_hw_results(self, Optional[int] runtime)

Executes the experiment in mock or on hardware using the information added to the experiment for a time given by runtime and returns a dict of hardware data represented as PyTorch data types.

:param runtime: The runtime of the experiment on hardware in ms.

:returns: Returns the data map as dict, where the keys are the population descriptors and values are tuples of values returned by the corresponding module’s post_process method.

last_run_chip_configs(self)
load_calib(self, Optional[Union[Path, str]] calib_path=None)

Load a calibration from path calib_path and apply to the experiment`s chip object.

If no path is specified a nightly calib is applied. :param calib_path: The path to the calibration. It None, the nightly calib is loaded. :return: Returns the chip object for the given calibration.

register_population(self, spiking_modules.HXModule module)

Register a module as population.

:param module: The module to register as population.

register_projection(self, spiking_modules.HXModule module)

Register a module as projection.

:param module: The module to register as projection.

wrap_modules(self, List[spiking_modules.HXModule] modules, Optional[Callable] func=None)

Wrap a number of given modules into a wrapper to which a single function func can be assigned.

In the PyTorch graph the individual module functions are then bypassed and only the wrapper’s function is considered when building the PyTorch graph. This functionality is of interest if several modules have cyclic dependencies and need to be represented by one PyTorch function. :param modules: A list of module to be wrapped. These modules need to constitute a closed sub-graph with no modules in between that are not element of the wrapper. :func: The function to assign to the wrapper. TODO: Add info about this functions signature.

Public Members

cadc_recording
grenade_network
grenade_network_graph
has_madc_recording
hw_routing_func
id_counter
injection_inside_realtime
injection_inside_realtime_begin
injection_inside_realtime_end
injection_post_realtime
injection_pre_realtime
injection_pre_static_config
inter_batch_entry_wait

Protected Functions

_configure_populations(self)

Configure the population on hardware.

_generate_hooks(self)

Handle injected config (not supported yet)

_generate_inputs(self, grenade.network.NetworkGraph network_graph)

Generate external input events from the routed network graph representation.

_generate_network_graphs(self)

Generate grenade network graph from the populations and projections in modules.

:return: Returns the grenade network graph.

_get_population_observables(self, grenade.network.NetworkGraph network_graph, grenade.signal_flow.OutputData result_map, runtime)

Takes the grenade network graph and the result map returned by grenade after experiment execution and returns a data map where for each population descriptor of registered populations the population-specific hardware observables are represented as Optional[torch.Tensor]s.

Note: This function calls the modules post_process method. :param network_graph: The logical grenade network graph describing the logic of th experiment. :param result_map: The result map returned by grenade holding all recorded hardware observables. :param runtime: The runtime of the experiment executed on hardware in ms. :returns: Returns the data map as dict, where the keys are the population descriptors and values are tuples of values returned by the corresponding module’s post_process method.

_prepare_static_config(self)

Prepares all the static chip config.

Accesses the chip object initialized by hxtorch.hardware_init and appends corresponding configurations to. Additionally this method defines the pre_static_config builder injected to grenade at run.

Protected Attributes

_batch_size
_chip
_last_run_chip_configs
_populations
_projections
_static_config_prepared
hxtorch.spiking.functional.iaf.CUBAIAFParams : public NamedTuple

Parameters for IAF integration and backward path.

Public Static Attributes

alpha = 50.0
method = "superspike"
tau_mem_inv = .Tensor
tau_ref = torch.tensor(0.)
tau_syn_inv = .Tensor
v_reset = torch.tensor(0.)
v_th = torch.tensor(1.)
hxtorch.spiking.functional.iaf.IAF : public torch.autograd.Function

IAF forward mock and backward.

Public Static Functions

backward(ctx, torch.Tensor grad_output)

Implements LIF backward.

forward(ctx, torch.Tensor input)

Gets overridden.

hxtorch.spiking.functional.li.CUBALIParams : public NamedTuple

Parameters for CUBA LI integration and backward path.

Public Static Attributes

tau_mem_inv = .Tensor
tau_syn_inv = .Tensor
v_leak = torch.tensor(0.)
hxtorch.spiking.functional.li.LI : public torch.autograd.Function

LI forward mock and backward.

Public Static Functions

backward(ctx, torch.Tensor grad_output)

Implements LIF backward.

forward(ctx, torch.Tensor input)

Gets overridden.

hxtorch.spiking.functional.lif.CUBALIFParams : public NamedTuple

Parameters for CUBA LIF integration and backward path.

Public Static Attributes

alpha = 50.0
method = "superspike"
tau_mem_inv = .Tensor
tau_ref = torch.tensor(0.)
tau_syn_inv = .Tensor
v_leak = torch.tensor(0.)
v_reset = torch.tensor(0.)
v_th = torch.tensor(1.)
hxtorch.spiking.functional.lif.LIF : public torch.autograd.Function

LIF forward mock and backward.

Public Static Functions

backward(ctx, torch.Tensor grad_output)

Implements LIF backward.

forward(ctx, torch.Tensor input)

Gets overridden.

hxtorch.spiking.functional.linear.Linear : public torch.autograd.Function

Linear autograd example.

Public Static Functions

backward(ctx, torch.Tensor grad_output)

Implement linear backward.

:param grad_output: The backpropagted gradient tensor.

forward(ctx, torch.Tensor input, torch.Tensor weight)

Gets overriden.

hxtorch.spiking.functional.superspike.SuperSpike : public torch.autograd.Function

Define Surrogate Gradient ‘SuperSpike’ (negative side of Fast Sigmoid) See: https://arxiv.org/abs/1705.11146.

Public Static Functions

backward(ctx, torch.Tensor grad_output)

Implements surrogate gradient ‘SuperSpike’ for backward.

:param grad_output: Back-propagated gradient.

:returns: SuperSpike gradient multiplied to back-propagated gradient.

forward(ctx, torch.Tensor input, float alpha)

Forward function, generating spikes at positions > 0.

:param input: Tensor holding v_mem - v_th, of > 0 a spike at the corresponding entry is generated. Saved for backward. :param alpha: Parameter controlling the slope of the surrogate derivative. Saved for backward.

:returns: A boolean tensor holding True at the entries for neurons emitting a spike.

hxtorch.spiking.functional.unterjubel.Unterjubel : public torch.autograd.Function

Unterjubel hardware observables to allow correct gradient flow.

Public Static Functions

backward(torch.Tensor ctx, torch.Tensor grad_output)

Backward the gradient.

:param grad_output: The backwarded gradient.

:returns: Returns simply the back-propagated gradient at first position.

forward(ctx, torch.Tensor input, torch.Tensor input_prime)

Returns input_prime instead of input to inject input_prime but direct the gradient to input.

:param input: Input tensor. :param input_prime: The returned tensor.

:returns: Returns the primed tensor. Thereby, this tensor is forwarded while the gradient is directed to to input.

hxtorch.spiking.handle.HandleMeta : public type

Meta class to create Handle types with properties.

Subclassed by hxtorch.spiking.handle.TensorHandle

Public Functions

__new__(mcs, clsname, bases, dict_)

Create a new instance of the given class.

hxtorch.spiking.handle.NeuronHandle : public hxtorch.spiking.handle.TensorHandle

Specialization for HX neuron observables.

Public Functions

__init__(self, Optional[torch.Tensor] spikes=None, Optional[torch.Tensor] v_cadc=None, Optional[torch.Tensor] current=None, Optional[torch.Tensor] v_madc=None)

Instantiate a neuron handle able to hold spike and membrane tensors.

:param spikes: Optional spike tensor. :param v_cadc: Optional membrane tensor, holding CADC recordings. :param current: Optional current tensor, holding synaptic current. :param v_madc: Optional membrane tensor, holding MADC recordings.

Public Members

current
spikes
v_cadc
v_madc

Protected Static Attributes

_carries = ["spikes", "v_cadc", "current", "v_madc"]
_obsv_state = "spikes"
hxtorch.spiking.handle.ReadoutNeuronHandle : public hxtorch.spiking.handle.TensorHandle

Specialization for HX neuron observables.

Public Functions

__init__(self, Optional[torch.Tensor] v_cadc=None, Optional[torch.Tensor] current=None, Optional[torch.Tensor] v_madc=None)

Instantiate a readout neuron handle able to hold MADC, current, and CADC data.

This handle defines the CADC values as the observable state, this can be changed by deriving this class.

:param v_cadc: Optional membrane tensor, holding CADC recordings. :param current: Optional current tensor, holding synaptic current. :param v_madc: Optional membrane tensor, holding MADC recordings.

Public Members

current
v_cadc
v_madc

Protected Static Attributes

_carries = ["v_cadc", "current", "v_madc"]
_obsv_state = "v_cadc"
hxtorch.spiking.handle.SynapseHandle : public hxtorch.spiking.handle.TensorHandle

Specialization for HX synapses.

Public Functions

__init__(self, Optional[torch.Tensor] graded_spikes=None)

Instantiate a synapse handle able to hold a graded spikes tensors as input to neurons.

:param graded_spikes: Optional tensor holding graded spikes.

Public Members

graded_spikes

Protected Static Attributes

_carries = ["graded_spikes"]
_obsv_state = "graded_spikes"
hxtorch.spiking.handle.TensorHandle : public metaclass , public hxtorch.spiking.handle.HandleMeta

Base class for HX tensor handles.

New tensor handles have to be derived from this class. The name of tensors the tensor handle ‘carries’ has to be indicated in the class member ‘_carries’. For all elements in this list a property is created implicitly.

The observable state of the tensor handle is defined in ‘_obsv_state’ and defines which tensor is passed to the subsequent layer as input. Member ‘_obsv_state’ has to be in ‘_carries’.

Subclassed by hxtorch.spiking.handle.NeuronHandle, hxtorch.spiking.handle.ReadoutNeuronHandle, hxtorch.spiking.handle.SynapseHandle

Public Functions

__init__(self)

Instantiate a new HX handle holding references to torch tensors.

clear(self)

Set all data in handle to ‘None’.

holds(self, str name)

Checks whether the tensor handle already holds a tensor with key name.

:param name: Key of reference to tensor. :return: Returns a bool indicating whether the data present at key name is not None.

observable_state(self)

Getter for observable state.

:return: Returns the tensor associated with ‘_obsv_state’

observable_state_identifier(self)

Getter for observable state identifier.

:return: Returns the identifier string associated with the observable state of the handle.

observable_state_identifier(self, str identifier)

Setter for observable state identifier.

This identifier has to be in _carries.

put(self, *tensors, **kwargs)

Fill the tensor handle with actual data given by tensors or kwargs.

If tensors are given as positional arguments the tensors are assigned in the order given by class member ‘_carries’. Keyword arguments are assigned to the corresponding key. Therefore, the key has to be in ‘_carries.’

:param tensors: Tensors which are assigned to the tensor handle. The given tensors are associated with the elements in ‘_carries’ in successive order.

:keyword param kwargs: Assigns the items in kwargs to the elements in the tensor handle associated with the corresponding kwargs keys.

Public Members

data

Protected Attributes

_obsv_state

Protected Static Attributes

_carries = []
_obsv_state = None
hxtorch.spiking.modules.batch_dropout.BatchDropout : public hxtorch.spiking.modules.types.Population

Batch dropout layer.

Caveat: In-place operations on TensorHandles are not supported. Must be placed after a neuron layer, i.e. Neuron.

Public Functions

__init__(self, int size, float dropout, Experiment experiment, Union[Callable, torch.autograd.Function] func=F.batch_dropout, grenade.common.ExecutionInstanceID execution_instance=grenade.common.ExecutionInstanceID())

Initialize BatchDropout layer.

This layer disables spiking neurons in the previous spiking Neuron layer with a probability of dropout. Note, size has to be equal to the size in the corresponding spiking layer. The spiking mask is maintained for the whole batch.

:param size: Size of the population this dropout layer is applied to. :param dropout: Probability that a neuron in the precessing layer gets disabled during training. :param experiment: Experiment to append layer to. :param func: Callable function implementing the module’s forward functionality or a torch.autograd.Function implementing the module’s forward and backward operation. Defaults to batch_dropout. :param execution_instance: Execution instance to place to.

extra_repr(self)

Add additional information.

mask(self)

Getter for spike mask.

:returns: Returns the current spike mask.

mask(self, torch.Tensor mask)

Setter for the spike mask.

:param mask: Spike mask. Must be of shape (self.size,).

set_mask(self)

Creates a new random dropout mask, applied to the spiking neurons in the previous module.

If module.eval() dropout will be disabled.

:returns: Returns a random boolean spike mask of size self.size.

Public Members

extra_args
mask
size

Public Static Attributes

output_type = NeuronHandle

Protected Attributes

_changed_since_last_run
_dropout
_mask
class hxtorch.spiking.modules.entity_on_execution_instance.EntityOnExecutionInstance

Mixin of execution instance property for use in modules.

Subclassed by hxtorch.spiking.modules.input_neuron.InputNeuron, hxtorch.spiking.modules.types.Population, hxtorch.spiking.modules.types.Projection

Public Functions

__init__(self, grenade.common.ExecutionInstanceID execution_instance)

:param execution_instance: Execution instance to place to.

Public Members

execution_instance
hxtorch.spiking.modules.hx_module.HXModule : public torch.nn.Module

PyTorch module supplying basic functionality for building SNNs on HX.

Subclassed by hxtorch.spiking.modules.hx_module_wrapper.HXModuleWrapper, hxtorch.spiking.modules.input_neuron.InputNeuron, hxtorch.spiking.modules.types.Population, hxtorch.spiking.modules.types.Projection

Public Functions

__init__(self, Experiment experiment, Union[Callable, torch.autograd.Function] func)

:param experiment: Experiment to append layer to.

:param func: Callable function implementing the module’s forward functionality or a torch.autograd.Function implementing the module’s forward and backward operation. TODO: Inform about func args

changed_since_last_run(self)

Getter for changed_since_last_run.

:returns: Boolean indicating wether module changed since last run.

exec_forward(self, Union[Tuple[TensorHandle], TensorHandle] input, TensorHandle output, Dict[grenade.PopulationOnNetwork, Tuple[torch.Tensor]] hw_map)

Inject hardware observables into TensorHandles or execute forward in mock-mode.

extra_repr(self)

Add additional information.

forward(self, *Union[Tuple[TensorHandle], TensorHandle] input)

Forward method registering layer operation in given experiment.

Input and output references will hold corresponding data as soon as ‘hxtorch.run’ in executed.

:param input: Reference to TensorHandle holding data tensors as soon as required.

:returns: Returns a Reference to TensorHandle holding result data associated with this layer after ‘hxtorch.run’ is executed.

func(self)
func(self, Optional[Callable] function)

Assign a PyTorch-differentiable function to the module.

   :param function: The function describing the modules f

post_process(self, Optional[SpikeHandle] hw_spikes, Optional[CADCHandle] hw_cadc, Optional[MADCHandle] hw_madc, float runtime)

This methods needs to be overridden for every derived module that demands hardware observables.

:param hw_spikes: The optional SpikeHandle holding raw spike data from hardware. :param hw_cadc: The optional CADCHandle holding raw CADC measurements from hardware. :param hw_madc: The optional MADCHandle holding raw MADC measurements from hardware. :param runtime: The requested runtime of the experiment on hardware in s. :param dt: The expected temporal resolution in hxtorch. :returns: Hardware data represented as torch.Tensors. Note that torch.Tensors are required here to enable gradient flow.

reset_changed_since_last_run(self)

Reset changed_since_last_run.

Sets the corresponding flag to false.

Public Members

experiment
func

Public Static Attributes

output_type = TensorHandle

Protected Functions

_prepare_func(self, function)

Strips all args and kwargs excluding input and hw_data from self._func.

If self._func does not have an hw_data keyword argument the prepared function will have it. This unifies the signature of all functions used in exec_forward to func(input, hw_data=...). :param function: The function to be used for building the PyTorch graph. :returns: Returns the member ‘func(input, *args, **kwargs, hw_data=…)’ stripped down to ‘func(input, hw_data=…).

_wrap_func(self, function)

Protected Attributes

_changed_since_last_run
_func
_func_is_wrapped
_func_name
_output_handle
hxtorch.spiking.modules.hx_module_wrapper.HXModuleWrapper : public hxtorch.spiking.modules.hx_module.HXModule

Class to wrap HXModules.

Public Functions

__init__(self, Experiment experiment, List[HXModule] modules, Optional[Callable] func)

A module which wraps a number of HXModules defined in modules to which a single PyTorch-differential function func is defined.

For instance, this allows to wrap a Synapse and a Neuron to describe recurrence. :param experiment: The experiment to register this wrapper in. :param modules: A list of modules to be represented by this wrapper. :param func: The function describing the unified functionality of all modules assigned to this wrapper. As for HXModules, this needs to be a PyTorch-differentiable function and can be either an autograd.Function or a function defined by PyTorch operation. The signature of this function is expected as:

  1. All positional arguments of each function in modules appended in the order given in modules.

  2. All keywords arguments of each function in modules. If a keyword occurs multiple times, it is post-fixed _i, where i is an integer incremented with each occurrence.

  3. A keyword argument hw_data if hardware data is expected, which is a tuple holding the data for each module for which data is expected. The order is defined by modules. The function is expected to output a tensor or a tuple of tensors for each module in modules, that can be assigned to the output handle of the corresponding HXModule.

contains(self, List[HXModule] modules)

Checks whether a list of modules modules is registered in the wrapper.

:param modules: The modules for which to check if they are registered. :return: Returns a bool indicating whether modules are a subset.

exec_forward(self, Tuple[TensorHandle] input, Tuple[TensorHandle] output, Dict[grenade.PopulationOnNetwork, Tuple[torch.Tensor]] hw_map)

Execute the the forward function of the wrapper.

This method assigns each output handle in output their corresponding PyTorch tensors and adds the wrapper’s func to the PyTorch graph. :param input: A tuple of the input handles where each handle corresponds to a certain module. The order is defined by modules. Note, a module can have multiple input handles. :param output: A tuple of output handles, each corresponding to one module. The order is defined by modules. :param hw_map: The hardware data map.

extra_repr(self)

Add additional information.

update(self, List[HXModule] modules, Optional[Callable] func=None)

Update the modules and the function in the wrapper.

:param modules: The new modules to assign to the wrapper. :param func: The new function to represent the modules in the wrapper.

update_args(self, List[HXModule] modules)

Gathers the args and kwargs of all modules in modules and renames keyword arguments that occur multiple times.

:param modules: The modules represented by the wrapper.

Public Members

extra_args
extra_kwargs
func
modules
hxtorch.spiking.modules.iaf_neuron.IAFNeuron : public hxtorch.spiking.modules.neuron.Neuron

Integrate-and-fire neuron Caveat: For execution on hardware, this module can only be used in conjunction with a preceding Synapse module.

Public Functions

__init__(self, int size, Experiment experiment, Union[Callable, torch.autograd.Function] func=F.IAF, grenade.common.ExecutionInstanceID execution_instance=grenade.common.ExecutionInstanceID(), Optional[NamedTuple] params=None, bool enable_spike_recording=True, bool enable_cadc_recording=True, bool enable_madc_recording=False, Optional[int] record_neuron_id=None, Optional[List[halco.LogicalNeuronOnDLS]] placement_constraint=None, Union[Dict[halco.AtomicNeuronOnDLS, float], torch.Tensor, float] trace_offset=0., Union[Dict[halco.AtomicNeuronOnDLS, float], torch.Tensor, float] trace_scale=1., int cadc_time_shift=1, bool shift_cadc_to_first=False, str interpolation_mode="linear", Optional[Morphology] neuron_structure=None)

Initialize an IAFNeuron.

This module creates a population of a non- leaking spiking neurons of size size. This module has a internal spiking mask, which allows to disable the event output and spike recordings of specific neurons within the layer. This is particularly useful for dropout.

:param size: Size of the population. :param experiment: Experiment to append layer to. :param func: Callable function implementing the module’s forward functionality or a torch.autograd.Function implementing the module’s forward and backward operation. Defaults to LIF. :param execution_instance: Execution instance to place to. :param params: Neuron Parameters in case of mock neuron integration of for backward path. If func does have a param argument the params object will get injected automatically. :param enable_spike_recording: Boolean flag to enable or disable spike recording. Note, this does not disable the event out put of neurons. The event output has to be disabled via mask. :param enable_cadc_recording: Enables or disables parallel sampling of the populations membrane trace via the CADC. A maximum sample rate of 1.7us is possible. :param enable_madc_recording: Enables or disables the recording of the neurons record_neuron_id membrane trace via the MADC. Only a single neuron can be recorded. This membrane traces is samples with a significant higher resolution as with the CADC. :param record_neuron_id: The in-population neuron index of the neuron to be recorded with the MADC. This has only an effect when enable_madc_recording is enabled. :param placement_constraint: An optional list of logical neurons defining where to place the module`s neurons on hardware. :param trace_offset: The value by which the measured CADC traces are shifted before the scaling is applied. If this offset is given as float the same value is applied to all neuron traces in this population. One can also provide a torch tensor holding one offset for each individual neuron in this population. The corresponding tensor has to be of size size. Further, the offsets can be supplied in a dictionary where the keys are the hardware neuron coordinates and the values are the offsets, i.e. Dict[AtomicNeuronOnDLS, float]. The dictionary has to provide one coordinate for each hardware neuron represented by this population, but might also hold neuron coordinates that do not correspond to this layer. The layer-specific offsets are then picked and applied implicitly. :param trace_scale: The value by which the measured CADC traces are scaled after the offset is applied. If this scale is given as float all neuron traces are scaled with the same value population. One can also provide a torch tensor holding one scale for each individual neuron in this population. The corresponding tensor has to be of size size. Further, the scales can be supplied in a dictionary where the keys are the hardware neuron coordinates and the values are the scales, i.e. Dict[AtomicNeuronOnDLS, float]. The dictionary has to provide one coordinate for each hardware neuron represented by this population, but might also hold neuron coordinates that do not correspond to this layer. The layer- specific scales are then picked and applied implicitly. :param cadc_time_shift: An integer indicating by how many time steps the CADC values are shifted in time. A positive value shifts later CADC samples to earlier times and vice versa for a negative value. :param shift_cadc_to_first: A boolean indicating that the first measured CADC value is used as an offset. Note, this disables the param trace_offset. :param interpolation_mode: The method used to interpolate the measured CADC traces onto the given time grid. :param neuron_structure: Structure of the neuron. If not supplied a single neuron circuit is used.

configure_hw_entity(self, int neuron_id, lola.NeuronBlock neuron_block, halco.LogicalNeuronOnDLS coord)

Disables the neurons leak to behave like a integrate-and-fire neuron.

:param neuron_id: In-population neuron index. :param neuron_block: The neuron block hardware entity. :param coord: Coordinate of neuron on hardware. :returns: Configured neuron block.

Public Static Attributes

output_type = NeuronHandle

Protected Static Attributes

_cadc_readout_source = lola.AtomicNeuron.Readout.Source.membrane
_madc_readout_source = \hal.NeuronConfig.ReadoutSource.membrane
hxtorch.spiking.modules.input_neuron.InputNeuron : public hxtorch.spiking.modules.hx_module.HXModule , public hxtorch.spiking.modules.entity_on_execution_instance.EntityOnExecutionInstance

Spike source generating spikes at the times [ms] given in the spike_times array.

Public Functions

__init__(self, int size, Experiment experiment, grenade.common.ExecutionInstanceID execution_instance=grenade.common.ExecutionInstanceID())

Instantiate a InputNeuron.

This module serves as an External Population for input injection and is created within experiment if not present in the considered model. This module performs an identity mapping when forward is called.

:param size: Number of input neurons. :param experiment: Experiment to which this module is assigned. :param execution_instance: Execution instance to place to.

add_to_input_generator(self, NeuronHandle input, grenade.network.InputGenerator builder)

Add the neurons events represented by this instance to grenades input generator.

:param input: Dense spike tensor. These spikes are implicitly converted to spike times. TODO: Allow sparse tensors. :param builder: Grenade’s input generator to append the events to.

add_to_network_graph(self, grenade.network.NetworkBuilder builder)

Adds instance to grenade’s network builder.

:param builder: Grenade network builder to add external population to. :returns: External population descriptor.

extra_repr(self)

Add additional information.

post_process(self, Optional[SpikeHandle] hw_spikes, Optional[CADCHandle] hw_cadc, Optional[MADCHandle] hw_madc, float runtime)

This methods needs to be overridden for every derived module that demands hardware observables.

:param hw_spikes: The optional SpikeHandle holding raw spike data from hardware. :param hw_cadc: The optional CADCHandle holding raw CADC measurements from hardware. :param hw_madc: The optional MADCHandle holding raw MADC measurements from hardware. :param runtime: The requested runtime of the experiment on hardware in s. :param dt: The expected temporal resolution in hxtorch. :returns: Hardware data represented as torch.Tensors. Note that torch.Tensors are required here to enable gradient flow.

register_hw_entity(self)

Register instance in member experiment.

Public Members

descriptor
size

Public Static Attributes

output_type = NeuronHandle
hxtorch.spiking.modules.neuron.Neuron : public hxtorch.spiking.modules.types.Population

Neuron layer.

Caveat: For execution on hardware, this module can only be used in conjunction with a preceding Synapse module.

Subclassed by hxtorch.spiking.modules.iaf_neuron.IAFNeuron, hxtorch.spiking.modules.readout_neuron.ReadoutNeuron

Public Functions

__init__(self, int size, Experiment experiment, Union[Callable, torch.autograd.Function] func=F.LIF, grenade.common.ExecutionInstanceID execution_instance=grenade.common.ExecutionInstanceID(), Optional[NamedTuple] params=None, bool enable_spike_recording=True, bool enable_cadc_recording=True, bool enable_madc_recording=False, Optional[int] record_neuron_id=None, Optional[List[halco.LogicalNeuronOnDLS]] placement_constraint=None, Union[Dict[halco.LogicalNeuronOnDLS, float], torch.Tensor, float] trace_offset=0., Union[Dict[halco.LogicalNeuronOnDLS, float], torch.Tensor, float] trace_scale=1., int cadc_time_shift=1, bool shift_cadc_to_first=False, str interpolation_mode="linear", Optional[Morphology] neuron_structure=None)

Initialize a Neuron.

This module creates a population of spiking neurons of size size. This module has a internal spiking mask, which allows to disable the event output and spike recordings of specific neurons within the layer. This is particularly useful for dropout.

:param size: Size of the population. :param experiment: Experiment to append layer to. :param func: Callable function implementing the module’s forward functionality or a torch.autograd.Function implementing the module’s forward and backward operation. Defaults to LIF. :param execution_instance: Execution instance to place to. :param params: Neuron Parameters in case of mock neuron integration of for backward path. If func does have a param argument the params object will get injected automatically. :param enable_spike_recording: Boolean flag to enable or disable spike recording. Note, this does not disable the event out put of neurons. The event output has to be disabled via mask. :param enable_cadc_recording: Enables or disables parallel sampling of the populations membrane trace via the CADC. A maximum sample rate of 1.7us is possible. :param enable_madc_recording: Enables or disables the recording of the neurons record_neuron_id membrane trace via the MADC. Only a single neuron can be recorded. This membrane traces is samples with a significant higher resolution as with the CADC. :param record_neuron_id: The in-population neuron index of the neuron to be recorded with the MADC. This has only an effect when enable_madc_recording is enabled. :param placement_constraint: An optional list of logical neurons defining where to place the module`s neurons on hardware. :param trace_offset: The value by which the measured CADC traces are shifted before the scaling is applied. If this offset is given as float the same value is applied to all neuron traces in this population. One can also provide a torch tensor holding one offset for each individual neuron in this population. The corresponding tensor has to be of size size. Further, the offsets can be supplied in a dictionary where the keys are the logical neuron coordinates and the values are the offsets, i.e. Dict[LogicalNeuronOnDLS, float]. The dictionary has to provide one coordinate for each hardware neuron represented by this population, but might also hold neuron coordinates that do not correspond to this layer. The layer-specific offsets are then picked and applied implicitly. :param trace_scale: The value by which the measured CADC traces are scaled after the offset is applied. If this scale is given as float all neuron traces are scaled with the same value population. One can also provide a torch tensor holding one scale for each individual neuron in this population. The corresponding tensor has to be of size size. Further, the scales can be supplied in a dictionary where the keys are the logical neuron coordinates and the values are the scales, i.e. Dict[LogicalNeuronOnDLS, float]. The dictionary has to provide one coordinate for each hardware neuron represented by this population, but might also hold neuron coordinates that do not correspond to this layer. The layer- specific scales are then picked and applied implicitly. :param cadc_time_shift: An integer indicating by how many time steps the CADC values are shifted in time. A positive value shifts later CADC samples to earlier times and vice versa for a negative value. :param shift_cadc_to_first: A boolean indicating that the first measured CADC value is used as an offset. Note, this disables the param trace_offset. :param interpolation_mode: The method used to interpolate the measured CADC traces onto the given time grid. :param neuron_structure: Structure of the neuron. If not supplied a single neuron circuit is used.

add_to_network_graph(self, grenade.network.NetworkBuilder builder)

Add the layer’s neurons to grenades network builder.

If enable_spike_recording is enabled the neuron’s spikes are recorded according to the layer’s spiking mask. If no spiking mask is given all neuron spikes will be recorded. Note, the event output of the neurons are configured in configure_hw_entity. If enable_cadc_recording is enabled the populations neuron’s are registered for CADC membrane recording. If enable_madc_recording is enabled the neuron with in-population index record_neuron_id will be recording via the MADC. Note, since the MADC can only record a single neuron on hardware, other Neuron layers registering also MADC recording might overwrite the setting here.

:param builder: Grenade’s network builder to add the layer’s population to. :returns: Returns the builder with the population added.

configure_hw_entity(self, int neuron_id, lola.NeuronBlock neuron_block, halco.LogicalNeuronOnDLS coord)

Configures a neuron in the given layer with its specific properties.

The neurons digital event outputs are enabled according to the given spiking mask.

TODO: Additional parameterization should happen here, i.e. with population-specific parameters.

:param neuron_id: In-population neuron index. :param neuron_block: The neuron block hardware entity. :param coord: Coordinate of neuron on hardware. :returns: Configured neuron block.

extra_repr(self)

Add additional information.

mask(self)

Getter for spike mask.

:returns: Returns the current spike mask.

mask(self, torch.Tensor mask)

Setter for the spike mask.

:param mask: Spike mask. Must be of shape (self.size,).

post_process(self, Optional[SpikeHandle] hw_spikes, Optional[CADCHandle] hw_cadc, Optional[MADCHandle] hw_madc, float runtime)

User defined post process method called as soon as population-specific hardware observables are returned.

This function has to convert the data types returned by grenade into PyTorch tensors. This function can be overridden by the user if non-default grenade-PyTorch data type conversion is required. Note: This function should return Tuple[Optional[torch.Tensor], …], like (cadc or madc,). This should match the ReadoutTensorHandle signature.

:param hw_spikes: A SpikeHandle holding the population’s spikes recorded by grenade as a sparse tensor. This data can be ignored for this readout neuron. :param hw_cadc: The CADCHandle holding the CADC membrane readout events in a sparse tensor. :param hw_madc: The MADCHandle holding the MADC membrane readout events in a sparse tensor. :param runtime: The requested runtime of the experiment on hardware in s.

:returns: Returns a tuple of optional torch.Tensors holding the hardware data (madc or cadc,)

register_hw_entity(self)

Infer neuron IDs on hardware and register them.

Public Members

cadc_time_shift
descriptor
interpolation_mode
offset
params
scale
shift_cadc_to_first
size
unit_ids

Public Static Functions

add_to_input_generator(HXModule module, grenade.network.InputGenerator builder)

Add the input to an input module to grenades input generator.

:param module: The module to add the input for. :param builder: Grenade’s logical network builder.

create_default_hw_entity()

At the moment, the default neuron is loaded from grenade’s ChipConfig object, which holds the atomic neurons configured as a calibration is loaded in hxtorch.hardware_init().

TODO: - Needed?

  • Maybe this can return a default neuron, when pop-specific calibration is needed.

Public Static Attributes

output_type = NeuronHandle

Protected Attributes

_changed_since_last_run
_enable_cadc_recording
_enable_madc_recording
_enable_spike_recording
_mask
_neuron_structure
_placement_constraint
_record_neuron_id

Protected Static Attributes

_cadc_readout_source = lola.AtomicNeuron.Readout.Source.membrane
_madc_readout_source = \hal.NeuronConfig.ReadoutSource.membrane
hxtorch.spiking.modules.readout_neuron.ReadoutNeuron : public hxtorch.spiking.modules.neuron.Neuron

Readout neuron layer.

Caveat: For execution on hardware, this module can only be used in conjunction with a preceding Synapse module.

Public Functions

__init__(self, int size, Experiment experiment, Union[Callable, torch.autograd.Function] func=F.LI, grenade.common.ExecutionInstanceID execution_instance=grenade.common.ExecutionInstanceID(), Optional[NamedTuple] params=None, bool enable_cadc_recording=True, bool enable_madc_recording=False, Optional[int] record_neuron_id=None, Optional[List[halco.LogicalNeuronOnDLS]] placement_constraint=None, Union[Dict[halco.AtomicNeuronOnDLS, float], torch.Tensor, float] trace_offset=0., Union[Dict[halco.AtomicNeuronOnDLS, float], torch.Tensor, float] trace_scale=1., int cadc_time_shift=1, bool shift_cadc_to_first=False, str interpolation_mode="linear", Optional[Morphology] neuron_structure=None)

Initialize a ReadoutNeuron.

This module creates a population of non- spiking neurons of size size and is equivalent to Neuron when its spiking mask is disabled for all neurons.

:param size: Size of the population. :param experiment: Experiment to register the module in. :param func: Callable function implementing the module’s forward functionality or a torch.autograd.Function implementing the module’s forward and backward operation. Defaults to LI. :param execution_instance: Execution instance to place to. :param params: Neuron Parameters in case of mock neuron integration of for backward path. If func does have a param argument the params object will get injected automatically. :param enable_cadc_recording: Enables or disables parallel sampling of the populations membrane trace via the CADC. A maximum sample rate of 1.7us is possible. :param enable_madc_recording: Enables or disables the recording of the neurons record_neuron_id membrane trace via the MADC. Only a single neuron can be recorded. This membrane traces is samples with a significant higher resolution as with the CADC. :param record_neuron_id: The in-population neuron index of the neuron to be recorded with the MADC. This has only an effect when enable_madc_recording is enabled. :param placement_constraint: An optional list of logical neurons defining where to place the module`s neurons on hardware. :param trace_offset: The value by which the measured CADC traces are shifted before the scaling is applied. If this offset is given as float the same value is applied to all neuron traces in this population. One can also provide a torch tensor holding one offset for each individual neuron in this population. The corresponding tensor has to be of size size. Further, the offsets can be supplied in a dictionary where the keys are the hardware neuron coordinates and the values are the offsets, i.e. Dict[AtomicNeuronOnDLS, float]. The dictionary has to provide one coordinate for each hardware neuron represented by this population, but might also hold neuron coordinates that do not correspond to this layer. The layer-specific offsets are then picked and applied implicitly. :param trace_scale: The value by which the measured CADC traces are scaled after the offset is applied. If this scale is given as float all neuron traces are scaled with the same value population. One can also provide a torch tensor holding one scale for each individual neuron in this population. The corresponding tensor has to be of size size. Further, the scales can be supplied in a dictionary where the keys are the hardware neuron coordinates and the values are the scales, i.e. Dict[AtomicNeuronOnDLS, float]. The dictionary has to provide one coordinate for each hardware neuron represented by this population, but might also hold neuron coordinates that do not correspond to this layer. The layer- specific scales are then picked and applied implicitly. :param cadc_time_shift: An integer indicating by how many time steps the CADC values are shifted in time. A positive value shifts later CADC samples to earlier times and vice versa for a negative value. :param shift_cadc_to_first: A boolean indicating that the first measured CADC value is used as an offset. Note, this disables the param trace_offset. :param interpolation_mode: The method used to interpolate the measured CADC traces onto the given time grid. :param neuron_structure: Structure of the neuron. If not supplied a single neuron circuit is used.

configure_hw_entity(self, int neuron_id, lola.NeuronBlock neuron_block, halco.LogicalNeuronOnDLS coord)

Configures a neuron in the given module with its specific properties.

The neurons digital event outputs are enabled according to the given spiking mask.

TODO: Additional parameterization should happen here, i.e. with population-specific parameters.

:param neuron_id: In-population neuron index. :param neuron_block: The neuron block hardware entity. :param coord: Coordinate of neuron on hardware. :returns: Configured neuron block.

post_process(self, Optional[SpikeHandle] hw_spikes, Optional[CADCHandle] hw_cadc, Optional[MADCHandle] hw_madc, float runtime)

User defined post process method called as soon as population-specific hardware observables are returned.

This function has to convert the data types returned by grenade into PyTorch tensors. This function can be overridden by the user if non-default grenade-PyTorch data type conversion is required. Note: This function should return Tuple[Optional[torch.Tensor], …], like (cadc or madc,). This should match the ReadoutTensorHandle signature.

:param hw_spikes: A SpikeHandle holding the population’s spikes recorded by grenade as a sparse tensor. This data can be ignored for this readout neuron. :param hw_cadc: The CADCHandle holding the CADC membrane readout events in a sparse tensor. :param hw_madc: The MADCHandle holding the MADC membrane readout events in a sparse tensor. :param runtime: The requested runtime of the experiment on hardware in s.

:returns: Returns a tuple of optional torch.Tensors holding the hardware data (madc or cadc,)

Public Static Attributes

output_type = ReadoutNeuronHandle
hxtorch.spiking.modules.sparse_synapse.SparseSynapse : public Projection

Sparse synapse layer.

Caveat: For execution on hardware, this module can only be used in conjuction with a subsequent Neuron module.

Public Functions

__init__(self, torch.SparseTensor connections, Experiment experiment, Union[Callable, torch.autograd.Function] func=F.linear_sparse, grenade.common.ExecutionInstanceID execution_instance=grenade.common.ExecutionInstanceID(), str device=None, Type dtype=None, Callable transform=weight_transforms.linear_saturating)

A sparse projection, with connections defined by non-zero entries in connections, represented sparsely on hardware.

:param connections: A tensor of shape (in_features, out_features) defining existing connections by one-entries. Can be sparse or non-sparse. :param experiment: Experiment to append layer to. :param func: Callable function implementing the module’s forward functionallity or a torch.autograd.Function implementing the module’s forward and backward operation. Required function args: [input (torch.Tensor), weight (torch.Tensor)] :param device: Device to execute on. Only considered in mock-mode. :param dtype: Data type of weight tensor. :param transform: A function taking the modules weight tensor and transforms it into weights mappable to hardware.

add_to_network_graph(self, grenade.PopulationDescriptor pre, grenade.PopulationDescriptor post, grenade.NetworkBuilder builder)

Adds the projection to a grenade network builder by providing the population descriptor of the corresponding pre and post population.

Note: This creates one inhibitory and one excitatory population on hardware in order to represent signed hardware weights.

:param pre: Population descriptor of pre-population. :param post: Population descriptor of post-population. :param builder: Greande netowrk builder to add projection to.

:returns: A tuple of grenade ProjectionDescriptors holding the descriptors for the excitatory and inhibitory projection.

changed_since_last_run(self)

Getter for changed_since_last_run.

:returns: Boolean indicating wether module changed since last run.

extra_repr(self)

Add additional information.

register_hw_entity(self)

Add the synapse layer to the experiment’s projections.

reset_changed_since_last_run(self)

Reset changed_since_last_run.

Sets the corresponding flag to false.

reset_parameters(self)

Resets the synapses weights by reinitalization using torch.nn.kaiming_uniform_.

Public Members

connections
descriptor
extra_args
in_features
mask
out_features
size
weight
weight_transform

Public Static Attributes

connections = .Tensor
output_type = SynapseHandle

Protected Attributes

_weight_old

Private Static Attributes

__constants__ = ['connections', 'in_features', 'out_features']
hxtorch.spiking.modules.synapse.Synapse : public hxtorch.spiking.modules.types.Projection

Synapse layer.

Caveat: For execution on hardware, this module can only be used in conjunction with a subsequent Neuron module.

Public Functions

__init__(self, int in_features, int out_features, Experiment experiment, Union[Callable, torch.autograd.Function] func=F.linear, grenade.common.ExecutionInstanceID execution_instance=grenade.common.ExecutionInstanceID(), str device=None, Type dtype=None, Callable transform=weight_transforms.linear_saturating)

TODO: Think about what to do with device here.

:param in_features: Size of input dimension. :param out_features: Size of output dimension. :param device: Device to execute on. Only considered in mock-mode. :param dtype: Data type of weight tensor. :param experiment: Experiment to append layer to. :param func: Callable function implementing the module’s forward functionality or a torch.autograd.Function implementing the module’s forward and backward operation. Required function args: [input (torch.Tensor), weight (torch.Tensor)] :param execution_instance: Execution instance to place to.

add_to_network_graph(self, grenade.network.PopulationOnNetwork pre, grenade.network.PopulationOnNetwork post, grenade.network.NetworkBuilder builder)

Adds the projection to a grenade network builder by providing the population descriptor of the corresponding pre and post population.

Note: This creates one inhibitory and one excitatory projection on hardware in order to represent signed hardware weights.

:param pre: Population descriptor of pre-population. :param post: Population descriptor of post-population. :param builder: Grenade network builder to add projection to.

:returns: A tuple of grenade ProjectionOnNetworks holding the descriptors for the excitatory and inhibitory projection.

changed_since_last_run(self)

Getter for changed_since_last_run.

:returns: Boolean indicating wether module changed since last run.

extra_repr(self)

Add additional information.

register_hw_entity(self)

Add the synapse layer to the experiment’s projections.

reset_changed_since_last_run(self)

Reset changed_since_last_run.

Sets the corresponding flag to false.

reset_parameters(self)

Resets the synapses weights by reinitialization using torch.nn.kaiming_uniform_.

Public Members

descriptor
extra_args
in_features
out_features
size
weight
weight_transform

Public Static Attributes

output_type = SynapseHandle

Protected Attributes

_weight_old
hxtorch.spiking.modules.types.Population : public hxtorch.spiking.modules.hx_module.HXModule , public hxtorch.spiking.modules.entity_on_execution_instance.EntityOnExecutionInstance

Base class for populations on BSS-2.

Subclassed by hxtorch.spiking.modules.batch_dropout.BatchDropout, hxtorch.spiking.modules.neuron.Neuron

Public Functions

__init__(self, "Experiment" experiment, Union[Callable, torch.autograd.Function] func, grenade.common.ExecutionInstanceID execution_instance)

:param experiment: Experiment to append layer to.

:param execution_instance: Execution instance to place to. :param func: Callable function implementing the module’s forward functionality or a torch.autograd.Function implementing the module’s forward and backward operation. TODO: Inform about func args

extra_repr(self)

Add additional information.

hxtorch.spiking.modules.types.Projection : public hxtorch.spiking.modules.hx_module.HXModule , public hxtorch.spiking.modules.entity_on_execution_instance.EntityOnExecutionInstance

Base class for projections on BSS-2.

Subclassed by hxtorch.spiking.modules.synapse.Synapse

Public Functions

__init__(self, "Experiment" experiment, Union[Callable, torch.autograd.Function] func, grenade.common.ExecutionInstanceID execution_instance)

:param experiment: Experiment to append layer to.

:param execution_instance: Execution instance to place to. :param func: Callable function implementing the module’s forward functionality or a torch.autograd.Function implementing the module’s forward and backward operation. TODO: Inform about func args

extra_repr(self)

Add additional information.

Public Static Attributes

in_features
out_features
weight = .Tensor

Private Static Attributes

__constants__ = ['in_features', 'out_features']
hxtorch.spiking.morphology.Morphology : public ABC

Represents the internal structure of a neuron.

This neuron might be made up of several compartments and the compartments themselves can consist of several neuron circuits.

:note: Currently spike and voltage recording is only supported in the first neuron circuit of the first compartment.

Subclassed by hxtorch.spiking.morphology.SingleCompartmentNeuron

Public Functions

compartments(self)

Unplaced coordinate of the logical neuron.

implement_morphology(self, halco.LogicalNeuronOnDLS coord, lola.NeuronBlock neuron_block)

Configure the atomic neurons in the given neuron block to represent this morphology.

:param coord: Coordinate of the logical neuron which should be configured. :param neuron_block: The configuration of neurons at coord will be changed such that a neuron with the given morphology is implemented.

logical_neuron(self)

Base configuration of the logical neuron.

Default constructed logical neuron, the connections between neuron circuits are configured such that the specified morphology is implemented.

Public Static Functions

disable_leak(halco.LogicalNeuronOnDLS coord, lola.NeuronBlock neuron_block)

Disable the leak for the given neuron.

:param coord: Coordinate of the logical neuron for which the leak is disabled. :param neuron_block: Neuron block in which the configuration of the atomic neurons is changed.

disable_spiking(halco.LogicalNeuronOnDLS coord, lola.NeuronBlock neuron_block)

Disable spiking for the given neuron.

Disable the threshold comparator and the digital spike output.

:param coord: Coordinate of the logical neuron for which spiking is disabled. :param neuron_block: Neuron block in which the configuration of the atomic neurons is changed.

enable_madc_recording(halco.LogicalNeuronOnDLS coord, lola.NeuronBlock neuron_block, hal.NeuronConfig.ReadoutSource readout_source)

Configure neuron such that traces can be recorded with the MADC.

:param coord: Coordinate of the logical neuron for which the recording is enabled. :param neuron_block: Neuron block in which the configuration of the atomic neurons is changed. :param readout_source: Voltage which should be recorded.

set_spike_recording(bool enable, halco.LogicalNeuronOnDLS coord, lola.NeuronBlock neuron_block)

Set whether spikes are forwarded digitally.

:param enable: Enable/disable the digital routing of spikes. :param coord: Coordinate of the logical neuron for which the recording is enabled. :param neuron_block: Neuron block in which the configuration of the atomic neurons is changed.

hxtorch.spiking.morphology.SingleCompartmentNeuron : public hxtorch.spiking.morphology.Morphology

Neuron with a single iso-potential compartment.

The compartment can consist of several neuron circuits. For all but the first neuron circuit leak, threshold and capacitance are disabled.

Public Functions

__init__(self, int size, bool expand_horizontally=False)

Create a single-compartment neuron.

:param size: Number of neuron circuits per compartment. :param expand_horizontally: Expand the neurons in the same row before starting a second row. If False, the columns are filled before the shape is expanded horizontally.

compartments(self)

Unplaced coordinate of the logical neuron.

implement_morphology(self, halco.LogicalNeuronOnDLS coord, lola.NeuronBlock neuron_block)

Configure the atomic neurons in the given neuron block to represent this morphology.

:param coord: Coordinate of the logical neuron which should be configured. :param neuron_block: The configuration of neurons at coord will be changed such that a neuron with the given morphology is implemented.

logical_neuron(self)

Base configuration of the logical neuron.

Default constructed logical neuron, the connections between neuron circuits are configured such that the specified morphology is implemented.

Protected Attributes

_logical_neuron

Protected Static Functions

_one_active_circuit(halco.LogicalNeuronOnDLS coord, lola.NeuronBlock neuron_block)

Enable fire signal forwarding for first circuit and disable leak, capacitance as well as threshold for all other circuit.

class hxtorch.spiking.neuron_placement.NeuronPlacement

Tracks assignment of pyNN IDs of HXNeuron based populations to the corresponding hardware entities, i.e.

LogicalNeuronOnDLS.

Public Functions

__init__(self)
id2logicalneuron(self, Union[List[int], int] neuron_id)

Get hardware coordinate from pyNN int.

:param neuron_id: pyNN neuron int

register_id(self, Union[List[int], int] neuron_id, halco.LogicalNeuronCompartments shape, Optional[Union[List[halco.LogicalNeuronOnDLS], halco.LogicalNeuronOnDLS]] placement_constraint=None)

Register a new ID to placement :param neuron_id: pyNN neuron ID to be registered :param shape: The shape of the neurons on hardware.

:param placement_constraint: A logical neuron or a list of logical neurons, each corresponding to one ID in neuron_id.

Protected Functions

_register(self, Union[List[int], int] neuron_id, halco.LogicalNeuronCompartments shape)

Register neurons with global IDs neuron_id with creating logical neurons implicitly.

:param neuron_id: An int or list of ints corresponding to the global IDs of the neurons. :param shape: The shape of the neurons on hardware.

_register_with_logical_neurons(self, Union[List[int], int] neuron_id, Union[List[halco.LogicalNeuronOnDLS], halco.LogicalNeuronOnDLS] placement_constraint)

Register neurons with global IDs neuron_id with given logical neurons logical_neuron.

:param neuron_id: An int or list of ints corresponding to the global IDs of the neurons. :param placement_constraint: A logical neuron or a list of logical neurons, each corresponding to one ID in neuron_id.

Protected Attributes

_id_2_ln
_used_an

Protected Static Attributes

_id_2_ln = [int, halco.LogicalNeuronOnDLS]
_used_an = [halco.AtomicNeuronOnDLS]
hxtorch.spiking.transforms.decode.MaxOverTime : public torch.nn.Module

Simple max-over-time decoding.

Public Functions

forward(self, torch.Tensor input)

Translate an input tensor of shape (batch_size, time_length, population_size) into a tensor of shape (batch_size, population_size), where the time dimension is discarded by picking the maximum value along the time.

Hence this module performs a ‘max-over-time’ operation.

:param input: The input tensor to transform. expected shape: (batch_size, time_length, population_size) :return: Returns the tensor holding the max-over-time values.

hxtorch.spiking.transforms.decode.MeanOverTime : public torch.nn.Module

Simple mean-over-time decoding.

Public Functions

forward(self, torch.Tensor input)

Translate an input tensor of shape (batch_size, time_length, population_size) into a tensor of shape (batch_size, population_size), where the time dimension is discarded by computing the average value along the time.

Hence this module performs a ‘mean-over-time’ operation.

:param input: The input tensor to transform. expected shape: (batch_size, time_length, population_size) :return: Returns the tensor holding the mean-over-time values.

hxtorch.spiking.transforms.decode.SumOverTime : public torch.nn.Module

Simple sum-over-time decoding.

Public Functions

forward(self, torch.Tensor input)

Translate an input tensor of shape (batch_size, time_length, population_size) into a tensor of shape (batch_size, population_size), where the time dimension is discarded by computing the sum along the time.

Hence this module performs a ‘sum-over-time’ operation.

:param input: The input tensor to transform. expected shape: (batch_size, time_length, population_size) :return: Returns the tensor holding the sum-over-time values.

hxtorch.spiking.transforms.encode.CoordinatesToSpikes : public torch.nn.Module

Convert values between 0 and 1 to spikes in a given timeframe.

Public Functions

__init__(self, int seq_length, float t_early, float t_late, float dt=1.e-6, Optional[float] t_bias=None)

Construct a coordinates-to-spikes converter.

This converter takes coordinate values in [0, 1] and maps them to spike times in interval [t_early, t_late]. A spike is indicated by a 1 on a dense time axis of length seq_length with temporal resolution dt. Further, it adds a bias spike at time t_bias, if t_bias is not None.

:param seq_length: Number of time steps in the resulting time sequence. The effective time length is given by seq_length * dt. :param t_early: The earliest time a spike will occur. :param t_late: The latest time a spike will occur. :param dt: The temporal resolution. :param t_bias: The time a bias spike occurs.

forward(self, torch.Tensor coordinate_values)

Convert coordinate values of to dense spike tensor of zeros and ones.

:param coordinate_values: Tensor with values in [0, 1], shaped (batch_size, num_channels)

:returns: Returns a dense tensor of shape (batch_size, seq_length, num_channels)

Protected Attributes

_dt
_seq_length
_t_bias
_t_early
_t_late
hxtorch.spiking.transforms.encode.PixelsToSpikeTimes : public torch.nn.Module

Encode image by spike trains.

Public Functions

__init__(self, tau=20, threshold=0.2, t_max=1.0, epsilon=1e-7)

Initialize a pixel to spike time transformation.

:param tau: Stretching factor of pixel to spike-time transformation. Lager values correspond to later spike times. :param threshold: The threshold under which a pixel is considered non-spiking (resp. spike at time t_max). :param t_max: Maximum spike time. :param epsilon: Safety margin to prevent zero-division.

forward(self, torch.Tensor pic)

Turns an image into a spike representation.

Image pixels >= threshold are assigned a spike time according to:

t_spike = \tau * log(pixel / (pixel - threshold))
If a pixel is < threshold it gets assigned the spike time t_max.

:param pic: Image to transform into spike trains. Has to be of shape (color_channel, width, height).

:return: Returns the image represented by spike trains, given as a tensor of shape (spike_time, color_channel, width, height).

Protected Attributes

_epsilon
_t_max
_tau
_threshold
hxtorch.spiking.transforms.encode.SpikeTimesToDense : public torch.nn.Module

Convert spike times to a dense matrix of zeros and ones.

Public Functions

__init__(self, float bin_width, int size=100)

Initialize the conversion of spike times to a dense matrix of zeros and ones.

:param bin_width: Binning interval in seconds. :param size: number of bins along time axis.

forward(self, torch.Tensor spikes)

Convert spike times to dense matrix of zeros and ones.

:param spikes: Spike times of shape ‘(color_channels, x0[, x1, …])’.

:returns: Returns a dense matrix of shape ‘(time_bins, color_channels, x0[, x1, …])’.

Protected Attributes

_to_sparse
hxtorch.spiking.transforms.encode.SpikeTimesToSparseTensor : public torch.nn.Module

Convert spike times to a dense matrix of zeros and ones.

Public Functions

__init__(self, float bin_width, int size=100)

Initialize the conversion of spike times to a dense matrix of zeros and ones.

:param bin_width: Binning interval in seconds. :param size: number of bins along time axis.

forward(self, torch.Tensor spikes)

Convert spike times to dense matrix of zeros and ones.

:param spikes: Spike times of shape ‘(color_channels, x0[, x1, …])’.

:returns: Returns a dense matrix of shape ‘(time_bins, color_channels, x0[, x1, …])’.

Protected Attributes

_size
_time_step
class hxtorch.spiking.utils.model_mapper.MixinHXModelMapper

Mapper mixin to map snn models to hxtorch.spiking models.

Public Functions

map_from(self, Any state_dict, Dict mapping, bool map_all=True)

Map an SNN model with state dict state_dict to this model.

:param state_dict: The state dict used to map from. :param mapping: The mapping from the keys of this model’s state dict to the keys in state_dict. :param map_all: A boolean value indicating if a state dict key is looked up in state_dict if not present in mapping. This allows to only define a mapping for some keys and load the others implicitly if the key names match. Defaults to true.

mnist.MNIST : public torch.utils.data.TensorDataset

The MNIST dataset.

Public Functions

__init__(self, root, train)

:param root: Root directory of the dataset that contains MNIST/processed/training.pt and MNIST/processed/test.pt.

:param train: If True, creates dataset from training.pt, otherwise from test.pt.

mnist.Model : public torch.nn.Module

Simple CNN model to classify written digits from the MNIST database.

Model topology:

  • Conv2d with 10x10 kernel, stride 5

  • Linear layer with 128 hidden neurons

Public Functions

__init__(self, bool mock)

:param mock: Whether to use a software simulation instead of the ASIC.

forward(self, *x)

Public Members

classifier
features
yinyang_model.Model : public torch.nn.Module

Complete model with encoder, network (snn) and decoder.

Public Functions

__init__(self, torch.nn.Module encoder, torch.nn.Module network, torch.nn.Module decoder, float readout_scale=1.)

Initialize the model by assigning encoder, network and decoder.

:param encoder: Module to encode input data :param network: Network module containing layers and parameters / weights :param decoder: Module to decode network output

forward(self, torch.Tensor inputs)

Perform forward pass through whole model, i.e.

data -> encoder -> network -> decoder -> output

:param inputs: tensor input data

:returns: Returns tensor output

regularize(self, float reg_readout, float reg_bursts, float reg_w_hidden, float reg_w_output)

Get regularization terms for bursts and weights like factor * (thing to be regularized) ** 2.

:param reg_bursts: prefactor of burst / hidden spike regulaization :param reg_weights_hidden: prefactor of hidden weight regularization :param reg_weights_output: prefactor of output weight regularization

:returns: Returns sum of regularization terms

Public Members

decoder
encoder
network
readout_scale
scores
yinyang_model.SNN : public torch.nn.Module

SNN with one hidden LIF layer and one readout LI layer.

Public Functions

__init__(self, int n_in, int n_hidden, int n_out, bool mock, str calib_path, float dt=1.0e-6, float tau_mem=8e-6, float tau_syn=8e-6, float alpha=50, int trace_shift_hidden=0, int trace_shift_out=0, Optional[Tuple[float, float]] weight_init_hidden=None, Optional[Tuple[float, float]] weight_init_output=None, float weight_scale=1., float trace_scale=1., int input_repetitions=1, torch.device device=torch.device("cpu"))

Initialize the SNN.

:param n_in: Number of input units. :param n_hidden: Number of hidden units. :param n_out: Number of output units. :param mock: Indicating whether to train in software or on hardware. :param calib_path: Path to hardware calibration file. :param dt: Time-binning width. :param tau_mem: Membrane time constant. :param tau_syn: Synaptic time constant. :param trace_shift_hidden: Indicates how many indices the membrane trace of hidden layer is shifted to left along time axis. :param trace_shift_out: Indicates how many indices the membrane trace of readout layer is shifted to left along time axis. :param weight_init_hidden: Hidden layer weight initialization mean and std value. :param weight_init_output: Output layer weight initialization mean and std value. :param weight_scale: The factor with which the software weights are scaled when mapped to hardware. :param input_repetitions: Number of times to repeat input channels. :param device: The used PyTorch device used for tensor operations in software.

forward(self, torch.Tensor spikes)

Perform a forward path.

:param spikes: NeuronHandle holding spikes as input.

:return: Returns the output of the network, i.e. membrane traces of the readout neurons.

Public Members

device
exp
input_repetitions
li_readout
lif_h
linear_h
linear_o
s_h
module _hxtorch_core
module _hxtorch_perceptron
module hxtorch

Variables

_modules = {}
level
module examples
module perceptron
module hxtorch.perceptron.nn

This module contains layers that can be used in modules together with the building blocks from py:mod:torch.nn.

Unlike their counterparts, their multiply-accumulate operations are performed with the BrainScaleS-2 accelerator. Additional digital operations are performed in the SIMD processors of BSS-2.

Functions

clamp_weight_(torch.Tensor weight)

Clamps all elements of the weight in-place into the maximal weight range of BrainScaleS-2.

scale_input(torch.Tensor x_in)

Scales the tensor to the maximal input range of BrainScaleS-2.

scale_weight(torch.Tensor weight)

Scales the tensor to the maximal weight range of BrainScaleS-2.

module spiking
module backend
module hxtorch.spiking.backend.module_manager

Define graph-based data structure managing Nodes.

Variables

Module = Union[spiking_module.HXModule, Any]
Source = Tuple[Any]
Target = Any
Wrapper = Union[spiking_module.HXModuleWrapper, Any]
module datasets
module yinyang

YinYangDataset class from https://github.com/lkriener/yin_yang_data_set/blob/master/dataset.py with minor changes.

module hxtorch.spiking.experiment

Defining basic types to create hw-executable instances.

Variables

log = logger.get("hxtorch.spiking.experiment")
module functional
module hxtorch.spiking.functional.dropout

Custom BatchDropout function.

Functions

batch_dropout(torch.Tensor input, torch.Tensor mask)

Applies a dropout mask to a batch of inputs.

:param input: The input tensor to apply dropout to. :param mask: The dropout mask. Entires in the mask which are False will disable their corresponding entry in input.

:returns: The input tensor with dropout mask applied.

module hxtorch.spiking.functional.iaf

Integrate and fire neurons.

Functions

cuba_iaf_integration(torch.Tensor input, NamedTuple params, Optional[torch.Tensor] hw_data=None, float dt=1e-6)

Leaky-integrate and fire neuron integration for realization of simple spiking neurons with exponential synapses.

Integrates according to: v^{t+1} = dt / \tau_{men} * (v_l - v^t + i^t) + v^t i^{t+1} = i^t * (1 - dt / \tau_{syn}) + x^t z^{t+1} = 1 if v^{t+1} > params.v_th v^{t+1} = v_reset if z^{t+1} == 1 Assumes i^0, v^0 = 0., v_reset :note: One dt synaptic delay between input and output :param input: Input spikes in shape (batch, time, neurons). :param params: LIFParams object holding neuron parameters. :return: Returns the spike trains in shape and membrane trace as a tuple. Both tensors are of shape (batch, time, neurons).

cuba_refractory_iaf_integration(torch.Tensor input, NamedTuple params, Optional[torch.Tensor] hw_data=None, float dt=1e-6)

Integrate and fire neuron integration for realization of simple spiking neurons with exponential synapses and refractory period.

Integrates according to: v^{t+1} = dt / \tau_{men} * i^t + v^t i^{t+1} = i^t * (1 - dt / \tau_{syn}) + x^t z^{t+1} = 1 if v^{t+1} > params.v_th v^{t+1} = params.v_reset if z^{t+1} == 1 or ref^t > 0 ref^{t+1} -= 1 ref^{t+1} = params.tau_ref if z^{t+1} == 1 Assumes i^0, v^0 = 0., v_reset :note: One dt synaptic delay between input and output :param input: Input spikes in shape (batch, time, neurons). :param params: LIFParams object holding neuron parameters. :return: Returns the spike trains in shape and membrane trace as a tuple. Both tensors are of shape (batch, time, neurons).

iaf_step(torch.Tensor z, torch.Tensor v, torch.Tensor i, torch.Tensor input, torch.Tensor z_hw, torch.Tensor v_hw, NamedTuple params, float dt)

Integrate the membrane of a neurons one time step further according to the integrate and fire dynamics.

:param z: The spike tensor at time step t. :param v: The membrane tensor at time step t. :param i: The current tensor at time step t. :param input: The input tensor at time step t (graded spikes). :param z_hw: The hardware spikes corresponding to the current time step. In case this is None, no HW spikes will be injected. :param v_hw: The hardware cadc traces corresponding to the current time step. In case this is None, no HW cadc values will be injected. :param params: Parameter object holding the LIF parameters. :param dt: Integration step width. :returns: Returns a tuple (z, v, i) holding the tensors of time step t + 1.

module hxtorch.spiking.functional.li

Leaky-integrate neurons.

Functions

cuba_li_integration(torch.Tensor input, CUBALIParams params, Optional[torch.Tensor] hw_data=None, float dt=1e-6)

Leaky-integrate neuron integration for realization of readout neurons with exponential synapses.

Integrates according to: v^{t+1} = dt / \tau_{mem} * (v_l - v^t + i^t) + v^t i^{t+1} = i^t * (1 - dt / \tau_{syn}) + x^t

Assumes i^0, v^0 = 0. :note: One dt synaptic delay between input and output :param input: Input spikes in shape (batch, time, neurons). :param params: LIParams object holding neuron parameters. :param dt: Integration step width

:return: Returns the membrane trace in shape (batch, time, neurons).

module hxtorch.spiking.functional.lif

Leaky-integrate and fire neurons.

Functions

cuba_lif_integration(torch.Tensor input, CUBALIFParams params, Optional[torch.Tensor] hw_data=None, float dt=1e-6)

Leaky-integrate and fire neuron integration for realization of simple spiking neurons with exponential synapses.

Integrates according to: i^{t+1} = i^t * (1 - dt / \tau_{syn}) + x^t v^{t+1} = dt / \tau_{men} * (v_l - v^t + i^t) + v^t z^{t+1} = 1 if v^{t+1} > params.v_th v^{t+1} = params.v_reset if z^{t+1} == 1

Assumes i^0, v^0 = 0, v_leak :note: One dt synaptic delay between input and output

TODO: Issue 3992

:param input: Input spikes in shape (batch, time, neurons). :param params: LIFParams object holding neuron parameters. :param dt: Step width of integration.

:return: Returns the spike trains in shape and membrane trace as a tuple. Both tensors are of shape (batch, time, neurons).

module hxtorch.spiking.functional.linear

Implement linear autograd function.

Functions

linear(torch.Tensor input, torch.nn.parameter.Parameter weight, torch.nn.parameter.Parameter bias=None)

Wrap linear to allow signature inspection.

linear_sparse(torch.Tensor input, torch.nn.parameter.Parameter weight, torch.Tensor connections=None, torch.nn.parameter.Parameter bias=None)

Wrap linear to allow signature inspection.

Disable inactive connections in weight tensor.

:param input: The input to be multiplied with the params tensor weight. :param weight: The weight parameter tensor. This tensor is expected to be dense since pytorch, see issue: 4039. :param bias: The bias of the linear operation. :param connections: A dense boolean connection mask indicating active connections. If None, the weight tensor remains untouched.

module hxtorch.spiking.functional.refractory

Refractory update for neurons with refractory behaviour.

Functions

refractory_update(torch.Tensor z, torch.Tensor v, torch.Tensor ref_state, NamedTuple params, float dt=1e-6)

Update neuron membrane and spikes to account for refractory period.

This implemention is widly adopted from: https://github.com/norse/norse/blob/main/norse/torch/functional/lif_refrac.py :param z: The spike tensor at time step t. :param v: The membrane tensor at time step t. :param ref_state: The refractory state holding the number of time steps the neurons has to remain in the refractory period. :param params: Parameter object holding the LIF parameters. :returns: Returns a tuple (z, v, ref_state) holding the tensors of time step t.

module hxtorch.spiking.functional.spike_source

Define different input spike sources.

Functions

input_neuron(torch.Tensor input)

Identity input neuron.

This forwards only the input tensor and is only used for consistency in HXInputNeuron which can also takes autograd functions. This enables gradient flow though input layers.

:param input: Input spike tensor.

:returns: Returns the input spike tensor.

module hxtorch.spiking.functional.superspike

Surrograte gradient for SuperSpike.

Basically reimplemented from: https://github.com/norse/norse/blob/18cd8aa256c3e7b5a28a852f5e928b104bc637fc/norse/torch/functional/superspike.py#L33

Functions

superspike_func(torch.Tensor input, float alpha)
module hxtorch.spiking.functional.threshold

Threshold function providing functionality for making spiking outputs differentiable.

Inspired by https://github.com/norse/norse/blob/ 72a812e17da23487878a667ad82a075ef7ad91ec/norse/torch/functional/ superspike.py

Functions

threshold(torch.Tensor input, str method, float alpha)

Selection of the used threshold function.

:param input: Input tensor to threshold function. :param method: The string indicator of the the threshold function. Currently supported: ‘super_spike’. :param alpha: Parameter controlling the slope of the surrogate derivative in case of ‘superspike’. :return: Returns the tensor of the threshold function.

module unterjubel

Autograd function to ‘unterjubel’ (german for ‘inject’) hardware observables and allow correct gradient back-propagation.

Basically taken from: https://gerrit.bioai.eu:9443/gitweb?p=model-hx-strobe.git;a=blob;f=src/py/strobe/unterjubel.py;h=4b13de159bd54b629a0b6278cb9c2f58f62883bf;hb=HEAD;js=1

module handle

Defining tensor handles able to hold references to tensors for lazy assignment after hardware data acquisition.

module modules
module hxtorch.spiking.modules.batch_dropout

Implementing BatchDropout Module.

Variables

log = logger.get("hxtorch.spiking.modules")
module entity_on_execution_instance
module hxtorch.spiking.modules.hx_module

Implementing the base module HXModule.

Variables

log = logger.get("hxtorch.spiking.modules")
module hxtorch.spiking.modules.hx_module_wrapper

Implementing a module wrapper to wrap multiple modules as one.

Variables

log = logger.get("hxtorch.spiking.modules")
module hxtorch.spiking.modules.iaf_neuron

Implementing integrate-and-fire neuron module.

Variables

log = logger.get("hxtorch.spiking.modules")
module hxtorch.spiking.modules.input_neuron

Implementing input neuron module.

Variables

log = logger.get("hxtorch.spiking.modules")
module hxtorch.spiking.modules.neuron

Implementing SNN modules.

Variables

log = logger.get("hxtorch.spiking.modules")
module hxtorch.spiking.modules.readout_neuron

Implementing SNN modules.

Variables

log = logger.get("hxtorch.spiking.modules")
module hxtorch.spiking.modules.sparse_synapse

Implementing SNN modules.

Variables

log = logger.get("hxtorch.spiking.modules")
module hxtorch.spiking.modules.synapse

Implementing SNN modules.

Variables

log = logger.get("hxtorch.spiking.modules")
module types

Define module types.

module morphology

User defined neuron morphologies.

module neuron_placement

Defining neuron placement allocator.

module hxtorch.spiking.run

Run function to execute a SNN given in an experiment.

Functions

run(Experiment experiment, Optional[int] runtime)

Execute the given experiment.

TODO: Why is this a standalone function?

:param experiment: The experiment representing the computational graph to be executed on hardware and/or in software. :param runtime: Only relevant for hardware experiments. Indicates the runtime resolved with experiment.dt.

Variables

log = logger.get("hxtorch.snn.run")
module transforms
module decode

Define modules to decode SNN observables.

module encode

Define transformations for spiking input coding.

module hxtorch.spiking.transforms.weight_transforms

Define convenient software <-> hardware weight mappings.

Functions

linear_saturating(torch.Tensor weight, float scale=1., float min_weight=-63., float max_weight=63.)

Scale all weights according to:

w <- clip(scale * w, min_weight, max_weight)
TODO: Maybe make this function member of HXSynapse and allow different weight transformations by inheritance.

:param weight: The weight tensor to be transformed. :param scale: A constant the weight tensor is scaled with. :param min_weight: The minimum value, smaller values are clipped to after scaling. :param max_weight: The maximum value, bigger values are clipped to after scaling.

:returns: The transformed weight tensor.

module utils
module hxtorch.spiking.utils.calib_helper

Helpers to handle calibrations.

Functions

chip_from_file(str path)

Extract chip config from coco file dump.

:param path: path to file containing coco dump.

chip_from_portable_binary(bytes data)

Convert portable binary data to chip object.

:param data: Coco list in portable binary format. :return: lola chip configuration.

nightly_calib_path(str name="spiking")

Find path for nightly calibration.

module model_mapper

Mapper mixin to map Norse models to hxtorch models.

module minimal

A minimal example that multiplies a vector and a matrix.

Functions

main()
module mnist

Training example for the MNIST handwritten-digits dataset using a host machine with the BrainScaleS-2 ASIC in the loop.

Functions

get_parser()

Returns an argument parser with all the options.

init(str calibration_path, bool mock, Real mock_noise_std, Real mock_gain)

Initialize hxtorch connection and load calibration.

Caveat: This also measures and sets the gain, therefore do this before initializing the model (as this influences layer initialization).

:param calibration_path: Path of custom calibration :param mock: Whether to simulate the hardware :param mock_noise_std: Standard deviation of artificial noise in mock mode :param mock_gain: Multiplication gain used in mock mode

main(argparse.Namespace args)

The main experiment function.

:param args: Command-line arguments

shrink_dataset(torch.utils.data.Dataset dataset, Real fraction)

Returns a fraction of the original dataset

test(torch.nn.Module model, torch.utils.data.DataLoader loader)

Test the model.

:param model: The model to test :param loader: Data loader containing the test data set :returns: Test accuracy

train(torch.nn.Module model, torch.utils.data.DataLoader loader, torch.optim.Optimizer optimizer)

Train the model.

:param model: The model :param loader: Data loader containing the train data set :param optimizer: Optimizer that handles the weight updates

Variables

log = hxtorch.logger.get("hxtorch.examples.perceptron.mnist")
namespace std

STL namespace.

namespace torch
namespace autograd
namespace nn
namespace modules
namespace conv
namespace utils
namespace data
module yinyang

Spiking HX torch yinyang example.

Functions

get_parser()

Returns an argument parser with all the options.

main(argparse.Namespace args)

Entrypoint for SNN training on the YinYang dataset.

Loads the dataset and executes training.

:param args: Argparse Namespace providing necessary constants.

:return: Returns the achieved accuracy after the last test epoch.

plot(train_loss, train_acc, test_loss, test_acc, args)

Plot losses and accuracies.

:param train_loss: List holding the average training loss for each epoch :param train_acc: List holding the average training accuracy for each epoch :param test_loss: List holding the average test loss each epoch :param test_acc: List holding the average accuracy for each epoch :param args: The arguments.

test(torch.nn.Module model, torch.utils.data.DataLoader loader, argparse.Namespace args, int epoch)

Test the model.

:param model: The model to test :param loader: Data loader containing the test data set :param epoch: Current trainings epoch.

:returns: Tuple of (test loss, test accuracy)

train(torch.nn.Module model, DataLoader loader, torch.optim.Optimizer optimizer, argparse.Namespace args, int epoch)

Perform training for one epoch.

:param model: The model to train. :param loader: Pytorch DataLoader instance providing training data. :param optimizer: The optimizer used or weight optimization. :param args: The argparse Namespace. :param epoch: Current epoch for logging.

:returns: Tuple (training loss, training accuracy)

Variables

level
log = hxtorch.logger.get("hxtorch.examples.spiking.yinyang")
module yinyang_model

Model class for spiking HX torch yinyang example.

file minimal.py
file mnist.py
file yinyang_model.py
file __init__.py
file __init__.py
file __init__.py
file __init__.py
file __init__.py
file __init__.py
file __init__.py
file __init__.py
file __init__.py
file __init__.py
file nn.py
file module_manager.py
file yinyang.py
file yinyang.py
file experiment.py
file dropout.py
file iaf.py
file li.py
file lif.py
file linear.py
file refractory.py
file spike_source.py
file superspike.py
file threshold.py
file unterjubel.py
file handle.py
file batch_dropout.py
file entity_on_execution_instance.py
file hx_module.py
file hx_module_wrapper.py
file iaf_neuron.py
file input_neuron.py
file neuron.py
file readout_neuron.py
file sparse_synapse.py
file synapse.py
file types.py
file morphology.py
file neuron_placement.py
file run.py
file decode.py
file encode.py
file weight_transforms.py
file calib_helper.py
file model_mapper.py
dir /jenkins/jenlib_workspaces_f9/doc_gerrit_documentation-brainscales2-dependencies.ZG9jX2dlcnJpdF9kb2N1bWVudGF0aW9uLWJyYWluc2NhbGVzMi1kZXBlbmRlbmNpZXMjMTE3OTA.x/hxtorch/src/pyhxtorch/hxtorch/spiking/backend
dir /jenkins/jenlib_workspaces_f9/doc_gerrit_documentation-brainscales2-dependencies.ZG9jX2dlcnJpdF9kb2N1bWVudGF0aW9uLWJyYWluc2NhbGVzMi1kZXBlbmRlbmNpZXMjMTE3OTA.x/hxtorch/src/pyhxtorch/hxtorch/spiking/datasets
dir /jenkins/jenlib_workspaces_f9/doc_gerrit_documentation-brainscales2-dependencies.ZG9jX2dlcnJpdF9kb2N1bWVudGF0aW9uLWJyYWluc2NhbGVzMi1kZXBlbmRlbmNpZXMjMTE3OTA.x/hxtorch/src/pyhxtorch/hxtorch/examples
dir /jenkins/jenlib_workspaces_f9/doc_gerrit_documentation-brainscales2-dependencies.ZG9jX2dlcnJpdF9kb2N1bWVudGF0aW9uLWJyYWluc2NhbGVzMi1kZXBlbmRlbmNpZXMjMTE3OTA.x/hxtorch/src/pyhxtorch/hxtorch/spiking/functional
dir /jenkins/jenlib_workspaces_f9/doc_gerrit_documentation-brainscales2-dependencies.ZG9jX2dlcnJpdF9kb2N1bWVudGF0aW9uLWJyYWluc2NhbGVzMi1kZXBlbmRlbmNpZXMjMTE3OTA.x/hxtorch
dir /jenkins/jenlib_workspaces_f9/doc_gerrit_documentation-brainscales2-dependencies.ZG9jX2dlcnJpdF9kb2N1bWVudGF0aW9uLWJyYWluc2NhbGVzMi1kZXBlbmRlbmNpZXMjMTE3OTA.x/hxtorch/src/pyhxtorch/hxtorch
dir /jenkins/jenlib_workspaces_f9/doc_gerrit_documentation-brainscales2-dependencies.ZG9jX2dlcnJpdF9kb2N1bWVudGF0aW9uLWJyYWluc2NhbGVzMi1kZXBlbmRlbmNpZXMjMTE3OTA.x/hxtorch/src/pyhxtorch/hxtorch/spiking/modules
dir /jenkins/jenlib_workspaces_f9/doc_gerrit_documentation-brainscales2-dependencies.ZG9jX2dlcnJpdF9kb2N1bWVudGF0aW9uLWJyYWluc2NhbGVzMi1kZXBlbmRlbmNpZXMjMTE3OTA.x/hxtorch/src/pyhxtorch/hxtorch/examples/perceptron
dir /jenkins/jenlib_workspaces_f9/doc_gerrit_documentation-brainscales2-dependencies.ZG9jX2dlcnJpdF9kb2N1bWVudGF0aW9uLWJyYWluc2NhbGVzMi1kZXBlbmRlbmNpZXMjMTE3OTA.x/hxtorch/src/pyhxtorch/hxtorch/perceptron
dir /jenkins/jenlib_workspaces_f9/doc_gerrit_documentation-brainscales2-dependencies.ZG9jX2dlcnJpdF9kb2N1bWVudGF0aW9uLWJyYWluc2NhbGVzMi1kZXBlbmRlbmNpZXMjMTE3OTA.x/hxtorch/src/pyhxtorch
dir /jenkins/jenlib_workspaces_f9/doc_gerrit_documentation-brainscales2-dependencies.ZG9jX2dlcnJpdF9kb2N1bWVudGF0aW9uLWJyYWluc2NhbGVzMi1kZXBlbmRlbmNpZXMjMTE3OTA.x/hxtorch/src/pyhxtorch/hxtorch/examples/spiking
dir /jenkins/jenlib_workspaces_f9/doc_gerrit_documentation-brainscales2-dependencies.ZG9jX2dlcnJpdF9kb2N1bWVudGF0aW9uLWJyYWluc2NhbGVzMi1kZXBlbmRlbmNpZXMjMTE3OTA.x/hxtorch/src/pyhxtorch/hxtorch/spiking
dir /jenkins/jenlib_workspaces_f9/doc_gerrit_documentation-brainscales2-dependencies.ZG9jX2dlcnJpdF9kb2N1bWVudGF0aW9uLWJyYWluc2NhbGVzMi1kZXBlbmRlbmNpZXMjMTE3OTA.x/hxtorch/src
dir /jenkins/jenlib_workspaces_f9/doc_gerrit_documentation-brainscales2-dependencies.ZG9jX2dlcnJpdF9kb2N1bWVudGF0aW9uLWJyYWluc2NhbGVzMi1kZXBlbmRlbmNpZXMjMTE3OTA.x/hxtorch/src/pyhxtorch/hxtorch/spiking/transforms
dir /jenkins/jenlib_workspaces_f9/doc_gerrit_documentation-brainscales2-dependencies.ZG9jX2dlcnJpdF9kb2N1bWVudGF0aW9uLWJyYWluc2NhbGVzMi1kZXBlbmRlbmNpZXMjMTE3OTA.x/hxtorch/src/pyhxtorch/hxtorch/spiking/utils

hxtorch from C++

struct hxtorch::core::CalibrationPath
#include <connection.h>

Path to a calibration.

Public Functions

inline explicit CalibrationPath(std::string value)

Public Members

std::string value
struct hxtorch::core::HWDBPath
#include <connection.h>

Path to a hardware database.

Public Functions

inline explicit HWDBPath(std::optional<std::string> path = std::nullopt, std::string version = "stable/latest")

Public Members

std::optional<std::string> path
std::string version
template<typename R, typename Trafo, typename T, size_t N, template<typename U> class PtrTraits, typename index_t>
struct hxtorch::perceptron::detail::ConvertToVector
#include <util.h>

Implementation for the at::TensorAccessor<T, N, PtrTraits, index_t> to std::vector<…<R>> (nesting-level N) conversion helper below.

Note

Other template parameaters come from at::TensorAccessor

Template Parameters
  • R – return value type

  • Trafo – transformation function

Public Types

typedef std::vector<typename unpacked_type::result_type> result_type
typedef at::TensorAccessor<T, N, PtrTraits, index_t> value_type

Public Static Functions

static inline result_type apply(value_type const &value, Trafo t)

Private Types

typedef ConvertToVector<R, Trafo, T, N - 1, PtrTraits, index_t> unpacked_type
template<typename R, typename Trafo, typename T, template<typename U> class PtrTraits, typename index_t>
struct hxtorch::perceptron::detail::ConvertToVector<R, Trafo, T, 1, PtrTraits, index_t>
#include <util.h>

Public Types

typedef std::vector<R> result_type
typedef at::TensorAccessor<T, 1, PtrTraits, index_t> value_type

Public Static Functions

static inline result_type apply(value_type const &value, Trafo t)
struct hxtorch::perceptron::detail::InferenceTracer
#include <inference_tracer.h>

Inference tracer implementation.

Currently only traces operation names.

Public Functions

void check_input(torch::Tensor const &value) const

Check input is equal to saved output.

Allows to ensure that between two traecd operations, the data is modified only by an identity function and thus all not-traced operations in between can be discarded.

Parameters

value – Value to check

void update_output(torch::Tensor const &value)

Update cached output value.

This is compared with the input of the next traced operation to ensure no modifications in-between.

Parameters

value – Value to update

Public Members

std::vector<std::string> operation_names
grenade::vx::compute::Sequence ops

Private Members

std::optional<torch::Tensor> m_last_output

Last output tensor to compare to next operations input tensor for sanity check.

struct hxtorch::perceptron::detail::MultidimIterator
#include <iterator.h>

Public Functions

inline MultidimIterator(std::vector<int64_t> const &range)
inline MultidimIterator end() const
inline bool operator!=(MultidimIterator const &other) const
inline std::vector<int64_t> operator*() const
inline MultidimIterator &operator++()
inline bool operator==(MultidimIterator const &other) const

Private Members

std::vector<int64_t> m_range
std::vector<int64_t> m_state
class hxtorch::perceptron::InferenceTracer
#include <inference_tracer.h>

Inference tracer for a linear sequence of operations.

The traced operations’ state is saved as a grenade::compute::Sequence, which can be executed as a single operation without transformation to and from PyTorch tensors. It is ensured, that no untraced modifications are made in-between traced operations by comparing the last traced operation’s output with the currently traced operation’s input value.

Note

Not final API or implementation, see Issue #3694

Public Functions

InferenceTracer(std::string const &filename)

Construct inference tracer with filename to store traced operations to.

void start()

Start tracing operations by registering tracer.

std::vector<std::string> stop()

Stop tracing operations by deregistering tracer and save traced operations to given file.

Returns

List of traced operation names

Private Members

std::string m_filename
std::shared_ptr<detail::InferenceTracer> m_impl
class hxtorch::perceptron::MAC : public torch::autograd::Function<MAC>
#include <mac.h>

Public Static Functions

static torch::autograd::variable_list backward(torch::autograd::AutogradContext *ctx, torch::autograd::variable_list grad_output)
static torch::autograd::variable_list forward(torch::autograd::AutogradContext *ctx, torch::autograd::Variable x, torch::autograd::Variable weights, int64_t num_sends, int64_t wait_between_events, bool mock, int64_t madc_recording_neuron_id, std::string madc_recording_path)
struct hxtorch::perceptron::MockParameter
#include <mock.h>

Parameter of hardware mock.

Public Functions

MockParameter() = default

Default constructor.

inline MockParameter(double noise_std, double gain)

Construct with noise standard deviation and gain.

Parameters
  • noise_std – Noise standard deviation to use

  • gain – Gain to use

Public Members

double gain = hxtorch::perceptron::constants::defaults::gain
double noise_std = hxtorch::perceptron::constants::defaults::noise_std
class hxtorch::spiking::CADCHandle : public hxtorch::spiking::DataHandle<std::vector<std::tuple<int32_t, int64_t, int64_t, int64_t>>>
#include <types.h>

Public Functions

inline int batch_size()
inline DataHandle()
template<typename U>
inline DataHandle(U &&data, int batch_size, int population_size)
inline std::vector<std::tuple<int32_t, int64_t, int64_t, int64_t>> &get_data()
inline int population_size()
inline void set_data(U &&data, int batch_size, int population_size)
torch::Tensor to_dense(float runtime, float dt, std::string mode = "linear")
std::tuple<torch::Tensor, float> to_dense(float runtime, std::string mode = "linear")
std::tuple<torch::Tensor, torch::Tensor> to_raw()
template<typename T>
class hxtorch::spiking::DataHandle
#include <types.h>

Public Functions

inline DataHandle()
template<typename U>
inline DataHandle(U &&data, int batch_size, int population_size)
inline int batch_size()
inline T &get_data()
inline int population_size()
template<typename U>
inline void set_data(U &&data, int batch_size, int population_size)

Private Members

int m_batch_size
T m_data
int m_population_size
class hxtorch::spiking::MADCHandle : public hxtorch::spiking::DataHandle<std::vector<std::tuple<int16_t, int64_t, int64_t, int64_t>>>
#include <types.h>

Public Functions

inline int batch_size()
inline DataHandle()
template<typename U>
inline DataHandle(U &&data, int batch_size, int population_size)
inline std::vector<std::tuple<int16_t, int64_t, int64_t, int64_t>> &get_data()
inline int population_size()
inline void set_data(U &&data, int batch_size, int population_size)
class hxtorch::spiking::SpikeHandle : public hxtorch::spiking::DataHandle<std::vector<std::tuple<int64_t, int64_t, int64_t>>>
#include <types.h>

Public Functions

inline int batch_size()
inline DataHandle()
template<typename U>
inline DataHandle(U &&data, int batch_size, int population_size)
inline std::vector<std::tuple<int64_t, int64_t, int64_t>> &get_data()
inline int population_size()
inline void set_data(U &&data, int batch_size, int population_size)
torch::Tensor to_dense(float runtime, float dt)
namespace grenade
namespace vx
namespace execution
namespace signal_flow
namespace hxtorch
namespace hxtorch::core

Functions

std::vector< std::vector< std::vector< float > > > dense_spikes_to_list (std::tuple< pybind11::array_t< int >, pybind11::array_t< float > > spikes, int input_size) SYMBOL_VISIBLE

Convert dense spike representation to grenade spike representation.

{ idx: [batch_idx, spike_idx], time: [batch_idx, spike_idx] } -> [batch, neuron_idx, spike_time]

Parameters
  • spikes – A tuple holding an array of neuron indices and an array of corresponding spike times

  • input_spikes – The size of the input population

Returns

Returns a vector of spike times of shape [batch, neuron_idx, spike_time]

std::map< grenade::vx::network::PopulationOnNetwork, std::tuple< pybind11::array_t< int >, pybind11::array_t< float > > > extract_n_spikes (grenade::vx::signal_flow::OutputData const &data, grenade::vx::network::NetworkGraph const &network_graph, int runtime, std::map< grenade::vx::network::PopulationOnNetwork, int > n_spikes) SYMBOL_VISIBLE

Convert recorded spikes in OutputData to population-specific tuples of NumPy arrays holding N spikes for each population in each batch entry.

If less spikes are encountered their entry will be np.inf

Parameters
  • data – The OutputData returned by grenade holding all recorded data.

  • network_graph – The logical grenade graph representation of the network.

  • n_spikes – The maximal numer of spikes per population.

  • runtime – The runtime of the experiment given in FPGA clock cycles.

Returns

Returns a tuple of indices and times, each as numpy array, where the first one holds the neuron index and the second one the spike time corresponding to the index

std::string get_unique_identifier(std::optional<HWDBPath> const &hwdb_path = std::nullopt)

Get unique identifier.

Parameters

hwdb_path – Optional path to the hwdb to use

void init_hardware(CalibrationPath const &calibration_path)

Initialize the hardware with calibration path.

Parameters

calibration_path – Calibration path to load from

void init_hardware(std::optional<HWDBPath> const &hwdb_path = std::nullopt, bool ann = false)

Initialize the hardware automatically from the environment.

Parameters
  • hwdb_path – Optional path to the hwdb to use. Only effective if param ann is true.

  • ann – Bool indicating whether additionally a default chip object is constructed for ANNs from a calibration loaded from hwdb_path, or if not given, from the latest nightly calibration.

void init_hardware_minimal()

Initialize automatically from the environment without ExperimentInit and without any calibration.

void release_hardware()

Release hardware resource.

grenade::vx::network::Projection::Connections weight_to_connection (pybind11::array_t< int > weight) SYMBOL_VISIBLE

Turns a weight matrix given as a rectangular NumPy array of type int into grenade connections.

Each entry in the weight matrix is translated to a single connection. The entries are expected to be positive integers.

Parameters

weight – NumPy tensor holding the weights as positive integers.

Returns

All grenade connections given as a vector of connections.

grenade::vx::network::Projection::Connections weight_to_connection (pybind11::array_t< int > weight, std::vector< std::vector< int > > connections) SYMBOL_VISIBLE

Turns a 1-D weight NumPay array together with a list of (pre, post) neuron connections into a list of grenade connections.

Each entry in the weight weight list corresponds to the weight of the connection int the connection list at the same index.

Parameters
  • weight – 1-D NumPy array holding the weights.

  • connections – Vector holding active connections

Returns

All grenade connections given as a vector of connections.

namespace hxtorch::core::detail

Functions

lola::vx::v3::Chip &getChip()

Get singleton chip configuration.

Returns

Reference to chip configuration

std::unique_ptr<grenade::vx::execution::JITGraphExecutor> &getExecutor()

Get singleton executor.

Returns

Reference to executor

namespace hxtorch::perceptron

Functions

torch::Tensor add(torch::Tensor const &input, torch::Tensor const &other, double alpha = 1., bool mock = false)

Elementwise addition operating on int8 value range.

Parameters
  • input – Input tensor

  • other – Other tensor, which must be broadcastable to input tensor dimension

  • alpha – The scalar multiplier for other

  • mock – Enable mock mode

torch::Tensor argmax(torch::Tensor const &input, c10::optional<int64_t> dim = c10::nullopt, bool keepdim = false, bool mock = false)

Arg max operation on int8 value range.

Parameters
  • input – The input tensor

  • dim – The dimension to reduce. If unspecified, the argmax of the flattened input is returned.

  • keepdim – Whether the output tensor has dim retained or not. Ignored if dim is unspecified.

  • mock – Enable mock mode

Returns

The indices of the maximum values of a tensor across a dimension

torch::Tensor conv1d(torch::Tensor const &input, torch::Tensor const &weight, c10::optional<torch::Tensor> const &bias, int64_t stride = 1, int64_t num_sends = 1, int64_t wait_between_events = constants::defaults::wait_between_events, bool mock = false)
torch::Tensor conv1d(torch::Tensor const &input, torch::Tensor const &weight, c10::optional<torch::Tensor> const &bias, std::array<int64_t, 1> stride, int64_t num_sends = 1, int64_t wait_between_events = constants::defaults::wait_between_events, bool mock = false)
torch::Tensor conv2d(torch::Tensor const &input, torch::Tensor const &weight, c10::optional<torch::Tensor> const &bias, int64_t stride = 1, int64_t num_sends = 1, int64_t wait_between_events = constants::defaults::wait_between_events, bool mock = false)
torch::Tensor conv2d(torch::Tensor const &input, torch::Tensor const &weight, c10::optional<torch::Tensor> const &bias, std::array<int64_t, 2> stride, int64_t num_sends = 1, int64_t wait_between_events = constants::defaults::wait_between_events, bool mock = false)
template<typename R, typename T, size_t N, template<typename U> class PtrTraits, typename index_t, typename Trafo = decltype(detail::default_transform<R, T>)>
detail::ConvertToVector<R, Trafo, T, N, PtrTraits, index_t>::result_type convert_to_vector(at::TensorAccessor<T, N, PtrTraits, index_t> const &tensor, Trafo func = detail::default_transform)

Conversion helper for converting at::TensorAccessor<T, N, PtrTraits, index_t> to std::vector<…<R>> (nesting-level N) types.

Note

The underlying value_type T is converted to R. All other template parameters come from at::TensorAccessor

Template Parameters
  • R – value_type to be returned

  • Trafo – Conversion type (defaults to R)

Parameters
  • tensor – The tensor accessor to be converted to a nested vector

  • func – The conversion function for the value_type inside (defaults to R())

Returns

A nested std::vector<std::vector<…<R>>> (N nested vectors).

torch::Tensor converting_relu(torch::Tensor const &input, int64_t shift = 2, bool mock = false)

Rectified linear unit operating on int8 value range converting to uint5 value range.

The result is bit-shifted by shift after applying the ReLU and clipped to the input range of BrainScaleS-2.

Parameters
  • input – Input tensor

  • shift – Amount of bits to shift before clipping

  • mock – Enable mock mode

torch::Tensor expanded_conv1d(torch::Tensor const &input, torch::Tensor const &weight, c10::optional<torch::Tensor> const &bias, int64_t stride = 1, int64_t num_expansions = 1, int64_t num_sends = 1, int64_t wait_between_events = constants::defaults::wait_between_events, bool mock = false)

1D convolution operation that unrolls the weight matrix for execution on hardware.

This maximizes the use of the synapses array.

Note

Fixed-pattern noise cannot be individually compensated for during training, because the same weights are used at different locations!

Parameters
  • input – Input tensor of shape (minibatch, in_channels, iW)

  • weight – Filters of shape (out_channels, in_channels / groups, kW)

  • bias – Optional bias of shape (out_channels)

  • stride – Stride of the convolving kernel

  • num_expansions – Number of enrolled kernels that will be placed side by side in a single operation

  • num_sends – How often to send the (same) input vector

  • wait_between_events – How long to wait (in FPGA cycles) between events

  • mock – Enable mock mode

torch::Tensor expanded_conv1d(torch::Tensor const &input, torch::Tensor const &weight, c10::optional<torch::Tensor> const &bias, std::array<int64_t, 1> stride, int64_t num_expansions = 1, int64_t num_sends = 1, int64_t wait_between_events = constants::defaults::wait_between_events, bool mock = false)
MockParameter get_mock_parameter()
torch::Tensor inference_trace(torch::Tensor const &input, std::string const &filename)

Execute inference of stored trace.

Parameters
  • input – Input data to use

  • filename – Filename to serialized operation trace

torch::Tensor mac(torch::Tensor const &x, torch::Tensor const &weights, int64_t num_sends = 1, int64_t wait_between_events = wait_between_events, bool mock = false, int64_t madc_recording_neuron_id = 0, std::string madc_recording_path = "")

The bare mutliply-accumulate operation of BrainScaleS-2.

A 1D input x is multiplied by the weight matrix weights. If x is two-dimensional, the weights are sent only once to the synapse array and the inputs are consecutively multiplied as a 1D vector.

Parameters
  • x – Input tensor

  • weights – The weights of the synapse array

  • num_sends – How often to send the (same) input vector

  • wait_between_events – How long to wait (in FPGA cycles) between events

  • mock – Enable mock mode

  • madc_recording_neuron_id – Neuron ID to record via MADC

  • madc_recording_path – Path to which to store MADC neuron membrane recordings in CSV format. If file exists new data is appended. By default recording is disabled.

Throws

std::runtime_error – When MADC recording is enabled but mock-mode is used.

Returns

Resulting tensor

torch::Tensor matmul(torch::Tensor const &input, torch::Tensor const &other, int64_t num_sends = 1, int64_t wait_between_events = wait_between_events, bool mock = false, int64_t madc_recording_neuron_id = 0, std::string madc_recording_path = "")

Drop-in replacement for the torch.matmul operation that uses BrainScaleS-2.

Note

The current implementation only supports other to be 1D or 2D.

Parameters
  • input – First input tensor

  • other – Second input tensor

  • num_sends – How often to send the (same) input vector

  • wait_between_events – How long to wait (in FPGA cycles) between events

  • mock – Enable mock mode

  • madc_recording_neuron_id – Neuron ID to record via MADC

  • madc_recording_path – Path to which to store MADC neuron membrane recordings in CSV format. If file exists new data is appended. By default recording is disabled.

Throws

std::runtime_error – When MADC recording is enabled but mock-mode is used.

Returns

Resulting tensor

MockParameter measure_mock_parameter()
torch::Tensor relu(torch::Tensor const &input, bool mock = false)

Rectified linear unit operating on int8 value range.

Parameters
  • input – Input tensor

  • mock – Enable mock mode

void set_mock_parameter(MockParameter const &parameter)
namespace hxtorch::perceptron::constants

Variables

static constexpr intmax_t hardware_matrix_height = halco::hicann_dls::vx::v3::SynapseRowOnSynram::size / 2
static constexpr intmax_t hardware_matrix_width = halco::hicann_dls::vx::v3::SynapseOnSynapseRow::size
static constexpr intmax_t input_activation_max = grenade::vx::signal_flow::UInt5::max
static constexpr intmax_t input_activation_min = grenade::vx::signal_flow::UInt5::min
static constexpr intmax_t output_activation_max = std::numeric_limits<grenade::vx::signal_flow::Int8::value_type>::max()
static constexpr intmax_t output_activation_min = std::numeric_limits<grenade::vx::signal_flow::Int8::value_type>::min()
static constexpr intmax_t synaptic_weight_max = grenade::vx::compute::MAC::Weight::max
static constexpr intmax_t synaptic_weight_min = grenade::vx::compute::MAC::Weight::min
namespace hxtorch::perceptron::constants::defaults

Variables

static constexpr double gain = 0.002
static constexpr double noise_std = 2.
static constexpr intmax_t wait_between_events = 5
namespace hxtorch::perceptron::detail

Functions

torch::autograd::variable_list add_backward(torch::Tensor const &grad_output, torch::Tensor const &input, torch::Tensor const &other)
torch::Tensor add_forward(torch::Tensor const &input, torch::Tensor const &other)
torch::Tensor add_mock_forward(torch::Tensor const &input, torch::Tensor const &other)
torch::Tensor argmax(torch::Tensor const &input, c10::optional<int64_t> dim = c10::nullopt, bool keepdim = false)
torch::Tensor argmax_mock(torch::Tensor const &input, c10::optional<int64_t> dim = c10::nullopt, bool keepdim = false)
torch::Tensor conv(torch::Tensor const &input, torch::Tensor const &weights, c10::optional<torch::Tensor> const &bias, std::vector<int64_t> const &stride, std::vector<int64_t> const &dilation, int64_t num_sends, int64_t wait_between_events, bool mock)
int64_t conv1d_output_size(int64_t input_size, int64_t kernel_size, int64_t stride = 1, int64_t dilation = 1)

Returns the output size of a convolution with given input size, kernel size, stride and dilation.

std::vector<int64_t> conv_output_size(std::vector<int64_t> input_size, std::vector<int64_t> kernel_size, std::vector<int64_t> stride, std::vector<int64_t> dilation)

Returns the output size of a convolution with given input size, kernel size, stride and dilation.

grenade::vx::signal_flow::UInt5 convert_activation(float value)
float convert_membrane(int8_t value)
grenade::vx::compute::MAC::Weight convert_weight(float value)
torch::autograd::variable_list converting_relu_backward(torch::Tensor const &grad_output, torch::Tensor const &input, int64_t shift)
torch::Tensor converting_relu_forward(torch::Tensor const &input, int64_t shift)
torch::Tensor converting_relu_mock_forward(torch::Tensor const &input, int64_t shift)
template<typename R, typename T>
R default_transform(T const &t)

Default transformation function from T to R.

torch::Tensor expanded_conv1d(torch::Tensor const &input, torch::Tensor const &weights, c10::optional<torch::Tensor> const &bias, int64_t stride, int64_t dilation, int64_t num_expansions, int64_t num_sends, int64_t wait_between_events, bool mock)
std::unordered_set<std::shared_ptr<InferenceTracer>> &getInferenceTracer()

Get singleton set of registered inference tracers.

MockParameter &getMockParameter()
bool has_tracer()

Check whether inference tracers are registered.

Returns

Boolean value

torch::autograd::variable_list mac_backward(torch::Tensor grad_output, torch::Tensor x, torch::Tensor weights)
torch::Tensor mac_forward(torch::Tensor x, torch::Tensor weights, int64_t num_sends, int64_t wait_between_events, int64_t madc_recording_neuron_id, std::string madc_recording_path)

Calculate forward-pass of multiply accumulate operation.

Input dimensions supported are 1D or 2D, where in the latter the input plane is the highest dimension and the first dimension describes which input vector to choose. The multiply accumulate therefore multiplies the last input dimension with the first weights dimension like y = x^T W.

Parameters
  • x – Input (1D or 2D)

  • weights – 2D weight matrix

  • num_sends – How often to send the (same) input vector

  • wait_between_events – Wait time between two successive vector inputs, in FPGA clock cycles. Shorter wait time can lead to saturation of the synaptic input.

  • madc_recording_neuron_id – Neuron ID to record via MADC

  • madc_recording_path – Path to which to store MADC neuron membrane recordings. If file exists new data is appended. By default recording is disabled.

Returns

Resulting tensor

torch::Tensor mac_mock_forward(torch::Tensor const &x, torch::Tensor const &weights, int64_t num_sends)

Mocks the forward-pass of the multiply accumulate operation.

Input dimensions supported are 1D or 2D, where in the latter the input plane is the highest dimension and the first dimension describes which input vector to choose. The multiply accumulate therefore multiplies the last input dimension with the first weights dimension like y = x^T W.

Parameters
  • x – Input (1D or 2D)

  • weights – 2D weight matrix

  • num_sends – How often to send the (same) input vector

Returns

Resulting tensor

template<typename T>
auto multi_narrow(T &t, std::vector<int64_t> dim, std::vector<int64_t> start, std::vector<int64_t> length)
torch::autograd::variable_list relu_backward(torch::Tensor const &grad_output, torch::Tensor const &input)
torch::Tensor relu_forward(torch::Tensor const &input)
torch::Tensor relu_mock_forward(torch::Tensor const &input)
void tracer_add(std::string const &name, grenade::vx::compute::Sequence::Entry &&op)

Add operation to trace.

Parameters
  • name – Name to use

  • op – Operation to add

void tracer_check_input(torch::Tensor const &value)

Check all tracers for equality of the output of the last traced operation with the given value.

Throws

std::runtime_error – On this operations input being unequal to last operations output

Parameters

value – Value to check

void tracer_update_output(torch::Tensor const &value)

Update all tracers’ output of the last traced operation with the given value.

Parameters

value – Value to update

namespace hxtorch::spiking

Functions

std::map<grenade::vx::network::PopulationOnNetwork, CADCHandle> extract_cadc(grenade::vx::signal_flow::OutputData const &data, grenade::vx::network::NetworkGraph const &network_graph)

Convert recorded CADC samples in OutputData to population-specific CADCHandles holding the samples in a sparse tensor representation.

Parameters
  • data – The OutputData returned by grenade holding all recorded data.

  • network_graph – The logical grenade graph representation of the network.

Returns

Returns a mapping between population descriptors and CADC handles.

std::map<grenade::vx::network::PopulationOnNetwork, MADCHandle> extract_madc(grenade::vx::signal_flow::OutputData const &data, grenade::vx::network::NetworkGraph const &network_graph)

Convert recorded MADC samples in OutputData to population-specific MADCHandles holding the samples in a sparse tensor representation.

Parameters
  • data – The OutputData returned by grenade holding all recorded data.

  • network_graph – The logical grenade graph representation of the network.

Returns

Returns a mapping between population descriptors and MADC handles.

std::map<grenade::vx::network::PopulationOnNetwork, SpikeHandle> extract_spikes(grenade::vx::signal_flow::OutputData const &data, grenade::vx::network::NetworkGraph const &network_graph)

Convert recorded spikes in OutputData to population-specific SpikeHandles holding the spikes in a sparse tensor representation.

Parameters
  • data – The OutputData returned by grenade holding all recorded data.

  • network_graph – The logical grenade graph representation of the network.

Returns

Returns a mapping between population descriptors and spike handles.

grenade::vx::signal_flow::OutputData run(grenade::vx::execution::JITGraphExecutor::ChipConfigs const &config, grenade::vx::network::NetworkGraph const &network_graph, grenade::vx::signal_flow::InputData const &inputs, grenade::vx::execution::JITGraphExecutor::Hooks &hooks)

Strips connection from grenade::vx::network::run for python exposure.

std::vector<std::vector<std::vector<float>>> tensor_to_spike_times(torch::Tensor times, float dt)

Convert a torch tensor of spikes with a dense (but discrete) time representation into spike times.

Parameters
  • times – A tensor of shape (batch_size, time_length, population_size) holding spike represemted as ones. Absent spikes are represented by zeros.

  • dt – The temporal resolution of the spike tensor.

Returns

A vector with the first dimension being the batch dimension and the second dimension the neuron index, holding a list of spike times of the corresonding neuron, i.e. shape (batch, neuron index, spike times).

namespace hxtorch::spiking::detail

Functions

torch::Tensor sparse_cadc_to_dense_linear(std::vector<std::tuple<int32_t, int64_t, int64_t, int64_t>> const &data, int batch_size, int population_size, float runtime, float dt)
torch::Tensor sparse_cadc_to_dense_nn(std::vector<std::tuple<int32_t, int64_t, int64_t, int64_t>> const &data, int batch_size, int population_size, float runtime, float dt)
std::tuple<torch::Tensor, torch::Tensor> sparse_cadc_to_dense_raw(std::vector<std::tuple<int32_t, int64_t, int64_t, int64_t>> const &data, int batch_size, int population_size)
torch::Tensor sparse_spike_to_dense(std::vector<std::tuple<int64_t, int64_t, int64_t>> const &data, int batch_size, int population_size, float runtime, float dt)
namespace lola
namespace vx
namespace v3
namespace std

STL namespace.

namespace torch
namespace autograd
file dense_spikes_to_list.h
#include “”
#include <>
#include <>
#include <>
file connection.h
#include <>
#include <>
file connection.h
#include <>
file extract_data.h
#include “”
#include “”
#include <>
#include <>
#include <>
file weight_to_connection.h
#include “”
#include <>
file constants.h
#include “”
#include “”
#include “”
#include <>
file conv.h
#include <>
#include <>
file conv.h
#include <>
#include <>
file add.h
#include <>
file add.h
#include <>
file argmax.h
#include <>
file argmax.h
#include <>
file conv1d.h
#include <>
file conversion.h
#include “”
#include “”
file iterator.h
#include <>
#include <>
file mac.h
#include <>
file mac.h
#include <>
#include <>
file narrow.h
#include <>
#include <>
file relu.h
#include <>
file relu.h
#include <>
file util.h
#include <>
#include <>
#include <>
file docstrings.h

Variables

static const char * __doc_hxtorch_CalibrationPath   = R"doc(Path to a calibration.)doc"
static const char * __doc_hxtorch_CalibrationPath_CalibrationPath   = R"doc()doc"
static const char * __doc_hxtorch_get_unique_identifier  =R"doc(Return the unique identifier of the chip with the initialized connection.@param hwdb_path Optional path to the hwdb to use@return The identifier as string)doc"
static const char * __doc_hxtorch_HWDBPath   = R"doc(Path to a hardware database.)doc"
static const char * __doc_hxtorch_HWDBPath_HWDBPath   = R"doc()doc"
static const char * __doc_hxtorch_init_hardware  =R"doc(Initialize the hardware automatically from the environment.@param hwdb_path Optional path to the hwdb to use@param spiking Boolean flag indicating whether spiking or non-spiking calibration is loaded)doc"
static const char * __doc_hxtorch_init_hardware_2  =R"doc(Initialize the hardware with calibration path.@param calibration_path Calibration path to load from)doc"
static const char * __doc_hxtorch_init_hardware_minimal  =R"doc(Initialize automatically from the environmentwithout ExperimentInit and without any calibration.)doc"
static const char * __doc_hxtorch_release_hardware   = R"doc(Release hardware resource.)doc"
file docstrings.h

Variables

static const char * __doc_hxtorch_add  =R"doc(Elementwise addition operating on int8 value range.@param input Input tensor@param other Other tensor, which must be broadcastable to input tensor dimension@param alpha The scalar multiplier for other@param mock Enable mock mode)doc"
static const char * __doc_hxtorch_argmax  =R"doc(Arg max operation on int8 value range.@param input The input tensor@param dim The dimension to reduce. If unspecified, the argmax of the flattenedinput is returned.@param keepdim Whether the output tensor has @p dim retained or not. Ignoredif @p dim is unspecified.@param mock Enable mock mode@return The indices of the maximum values of a tensor across a dimension)doc"
static const char * __doc_hxtorch_conv1d   = R"doc()doc"
static const char * __doc_hxtorch_conv1d_2   = R"doc()doc"
static const char * __doc_hxtorch_conv2d   = R"doc()doc"
static const char * __doc_hxtorch_conv2d_2   = R"doc()doc"
static const char * __doc_hxtorch_converting_relu  =R"doc(Rectified linear unit operating on int8 value range converting to uint5value range.The result is bit-shifted by @p shift after applying the ReLU and clippedto the input range of BrainScaleS-2.@param input Input tensor@param shift Amount of bits to shift before clipping@param mock Enable mock mode)doc"
static const char * __doc_hxtorch_expanded_conv1d  =R"doc(1D convolution operation that unrolls the weight matrix for executionon hardware. This maximizes the use of the synapses array.@noteFixed-pattern noise cannot be individually compensated for duringtraining, because the same weights are used at different locations!@param input Input tensor of shape (minibatch, in_channels, *iW*)@param weight Filters of shape (out_channels, in_channels / groups, *kW*)@param bias Optional bias of shape (out_channels)@param stride Stride of the convolving kernel@param num_expansions Number of enrolled kernels that will be placed sideby side in a single operation@param num_sends How often to send the (same) input vector@param wait_between_events How long to wait (in FPGA cycles) between events@param mock Enable mock mode)doc"
static const char * __doc_hxtorch_expanded_conv1d_2   = R"doc()doc"
static const char * __doc_hxtorch_get_mock_parameter  =R"doc(Returns the current mock parameters.)doc"
static const char * __doc_hxtorch_inference_trace  =R"doc(Execute inference of stored trace.@param input Input data to use@param filename Filename to serialized operation trace)doc"
static const char * __doc_hxtorch_InferenceTracer  =R"doc(Inference tracer for a linear sequence of operations.The traced operations' state is saved as a grenade::compute::Sequence,which can be executed as a single operation without transformation to andfrom PyTorch tensors.It is ensured, that no untraced modifications are made in-between tracedoperations by comparing the last traced operation's output with thecurrently traced operation's input value.@noteNot final API or implementation, see Issue #3694)doc"
static const char * __doc_hxtorch_InferenceTracer_InferenceTracer  =R"doc(Construct inference tracer with filename to store traced operations to.)doc"
static const char * __doc_hxtorch_InferenceTracer_start  =R"doc(Start tracing operations by registering tracer.)doc"
static const char * __doc_hxtorch_InferenceTracer_stop  =R"doc(Stop tracing operations by deregistering tracer and save tracedoperations to given file.@return List of traced operation names)doc"
static const char * __doc_hxtorch_mac  =R"doc(The bare mutliply-accumulate operation of BrainScaleS-2. A 1D input @p xis multiplied by the weight matrix @p weights. If @p x is two-dimensional,the weights are sent only once to the synapse array and the inputs areconsecutively multiplied as a 1D vector.@param x Input tensor@param weights The weights of the synapse array@param num_sends How often to send the (same) input vector@param wait_between_events How long to wait (in FPGA cycles) between events@param mock Enable mock mode@return Resulting tensor)doc"
static const char * __doc_hxtorch_matmul  =R"doc(Drop-in replacement for the torch.matmul operation that uses BrainScaleS-2.@noteThe current implementation only supports @p other to be 1D or 2D.@param input First input tensor@param other Second input tensor@param num_sends How often to send the (same) input vector@param wait_between_events How long to wait (in FPGA cycles) between events@param mock: Enable mock mode@return Resulting tensor)doc"
static const char * __doc_hxtorch_measure_mock_parameter  =R"doc(Measures the mock parameters, i.e. gain and noise_std, by multiplying afull weight with an artificial test input on the BSS-2 chip.For this purpose a random pattern is used, whose mean value is successivelyreduced to also work with higher gain factors.The output for the actual calibration is chosen such that it is close tothe middle of the available range.)doc"
static const char * __doc_hxtorch_MockParameter   = R"doc(Parameter of hardware mock.)doc"
static const char * __doc_hxtorch_MockParameter_MockParameter  =R"doc(Construct with noise standard deviation and gain.@param noise_std Noise standard deviation to use@param gain Gain to use)doc"
static const char * __doc_hxtorch_relu  =R"doc(Rectified linear unit operating on int8 value range.@param input Input tensor@param mock Enable mock mode)doc"
static const char * __doc_hxtorch_set_mock_parameter   = R"doc(Sets the mock parameters.)doc"
file docstrings.h
file inference_tracer.h
#include <>
#include <>
#include <>
#include <>
#include <>
#include <>
#include “”
file inference_tracer.h
#include <>
#include <>
file matmul.h
#include <>
file mock.h
file mock.h
file to_dense.h
#include <>
file extract_tensors.h
#include “”
#include “”
#include “hxtorch/spiking/types.h
#include <>
file run.h
#include “”
#include “”
#include “”
#include “”
#include “”
file tensor_to_spike_times.h
#include <>
#include <>
file types.h
#include <>
#include <>
#include <>
dir /jenkins/jenlib_workspaces_f9/doc_gerrit_documentation-brainscales2-dependencies.ZG9jX2dlcnJpdF9kb2N1bWVudGF0aW9uLWJyYWluc2NhbGVzMi1kZXBlbmRlbmNpZXMjMTE3OTA.x/hxtorch/include/hxtorch/core
dir /jenkins/jenlib_workspaces_f9/doc_gerrit_documentation-brainscales2-dependencies.ZG9jX2dlcnJpdF9kb2N1bWVudGF0aW9uLWJyYWluc2NhbGVzMi1kZXBlbmRlbmNpZXMjMTE3OTA.x/hxtorch/include/hxtorch/core/detail
dir /jenkins/jenlib_workspaces_f9/doc_gerrit_documentation-brainscales2-dependencies.ZG9jX2dlcnJpdF9kb2N1bWVudGF0aW9uLWJyYWluc2NhbGVzMi1kZXBlbmRlbmNpZXMjMTE3OTA.x/hxtorch/include/hxtorch/perceptron/detail
dir /jenkins/jenlib_workspaces_f9/doc_gerrit_documentation-brainscales2-dependencies.ZG9jX2dlcnJpdF9kb2N1bWVudGF0aW9uLWJyYWluc2NhbGVzMi1kZXBlbmRlbmNpZXMjMTE3OTA.x/hxtorch/include/hxtorch/spiking/detail
dir /jenkins/jenlib_workspaces_f9/doc_gerrit_documentation-brainscales2-dependencies.ZG9jX2dlcnJpdF9kb2N1bWVudGF0aW9uLWJyYWluc2NhbGVzMi1kZXBlbmRlbmNpZXMjMTE3OTA.x/hxtorch
dir /jenkins/jenlib_workspaces_f9/doc_gerrit_documentation-brainscales2-dependencies.ZG9jX2dlcnJpdF9kb2N1bWVudGF0aW9uLWJyYWluc2NhbGVzMi1kZXBlbmRlbmNpZXMjMTE3OTA.x/hxtorch/include/hxtorch
dir /jenkins/jenlib_workspaces_f9/doc_gerrit_documentation-brainscales2-dependencies.ZG9jX2dlcnJpdF9kb2N1bWVudGF0aW9uLWJyYWluc2NhbGVzMi1kZXBlbmRlbmNpZXMjMTE3OTA.x/hxtorch/include
dir /jenkins/jenlib_workspaces_f9/doc_gerrit_documentation-brainscales2-dependencies.ZG9jX2dlcnJpdF9kb2N1bWVudGF0aW9uLWJyYWluc2NhbGVzMi1kZXBlbmRlbmNpZXMjMTE3OTA.x/hxtorch/include/hxtorch/perceptron
dir /jenkins/jenlib_workspaces_f9/doc_gerrit_documentation-brainscales2-dependencies.ZG9jX2dlcnJpdF9kb2N1bWVudGF0aW9uLWJyYWluc2NhbGVzMi1kZXBlbmRlbmNpZXMjMTE3OTA.x/hxtorch/include/hxtorch/spiking