lava.utils

lava.utils.float2fixed

This module will contain a tool to perform automated float- to fixed-point conversion of of Lava Processes.

Given a set of processes and data, the tool will perform the following steps:

1. Find fixed-point ProcessModels of every floating-point ProcessModel if available and throw an error otherwise. 2. Run the floating-point model and collect activation statistics. 3. Given activation statistic and type/precision/dynamic range specifications of fixed-point models, perform input parameter conversion for fixed-point model. 4. Replace floating-point ProcessModels by corresponding fixed-point ProcessModels 5. Initialize fixed-point ProcessModels

ProcessModel extraction might be a shared function with compiler.

This will likely lead to some performance degradation of the application so perhaps some iterative optimization may have to be included within this parameter conversion process. Reuse other libraries for this purpose where possible.

lava.utils.profiler

Inheritance diagram of lava.utils.profiler
class lava.utils.profiler.Profiler

Bases: object

Base class for profiling execution time, energy and other metrics on different resources. Depending on the computing ressource an appropriate profiler needs to be chosen. The run configuration is used to choose the related profiler, if there is one.

static init(run_cfg)

Decide which profiler is needed based on the run configuration.

Return type

Profiler

lava.utils.system

Inheritance diagram of lava.utils.system
class lava.utils.system.Loihi2

Bases: object

is_loihi2_available = True
partition = 'oheogulch'
preferred_partition: str = None
static set_environ_settings(partititon=None)

Sets the os environment for execution on Loihi.

Parameters

partititon (str, optional) – Loihi partition name, by default None.

Return type

None

class lava.utils.system.staticproperty(fget=None, fset=None, fdel=None, doc=None)

Bases: property

Wraps static member function of a class as a static property of that class.

lava.utils.validator

This module will contain a tool to automatically validate the correctness of one ProcessModel of Process against another ProcessModel of the same Process.

For instance, an application might use processes having both PyProcessModels and NcProcessModels. In order to ensure that the Python SW model of a NeuroCore produces the same result, this tool can be used to compare both implementations. In doing so, it will point out exactly at which point in time in which state variable a divergence in the internal dynamics occurs in order to ease mismatch resolution.

lava.utils.visualizer

This module will contain a tool to visualize a network of interconnected Lava Processes and Vars.

lava.utils.weightutils

Inheritance diagram of lava.utils.weightutils
class lava.utils.weightutils.OptimizedWeights(weights, num_weight_bits, weight_exp)

Bases: object

num_weight_bits: int
weight_exp: int
weights: ndarray
class lava.utils.weightutils.SignMode(value)

Bases: Enum

Enumeration of sign mode of weights.

EXCITATORY = 2
INHIBITORY = 3
MIXED = 1
NULL = 0
lava.utils.weightutils.clip_weights(weights, sign_mode, num_bits)

Truncate the least significant bits of the weight matrix given the sign mode and number of weight bits.

Parameters
  • weights (numpy.ndarray) – Weight matrix that is to be truncated.

  • sign_mode (SignMode) – Sign mode to use for truncation.

  • num_bits (int) – Number of bits to use to clip the weights to.

Returns

Truncated weight matrix.

Return type

numpy.ndarray

lava.utils.weightutils.determine_sign_mode(weights)

Determines the sign mode that describes the values in the given weight matrix.

Parameters

weights (numpy.ndarray) – Weight matrix

Returns

The sign mode that best describes the values in the given weight matrix.

Return type

SignMode

lava.utils.weightutils.optimize_weight_bits(weights, sign_mode, loihi2=False)

Optimizes the weight matrix to best fit in Loihi’s synapse.

Parameters
  • weights (np.ndarray) – Standard 8-bit signed weight matrix.

  • sign_mode (SignMode) – Determines whether the weights are purely excitatory, inhibitory, or mixed sign.

  • loihi2 (bool, optional) – Flag to optimize for Loihi 2. By default False.

Returns

An object that wraps the optimized weight matrix and weight parameters.

Return type

OptimizedWeights

lava.utils.weightutils.truncate_weights(weights, sign_mode, num_weight_bits, max_num_weight_bits=8)

Truncate the least significant bits of the weight matrix given the sign mode and number of weight bits.

Parameters
  • weights (numpy.ndarray) – Weight matrix that is to be truncated.

  • sign_mode (SignMode) – Sign mode to use for truncation. See SignMode class for the correct values.

  • num_weight_bits (int) – Number of bits to use for the weight matrix.

  • max_num_weight_bits (int, optional) – Maximum number of bits that can be used to represent weights. Default is 8.

Returns

Truncated weight matrix.

Return type

numpy.ndarray