lava.magma.core.learning

lava.magma.core.learning.constants

digraph inheritancebc66c3dccc { bgcolor=transparent; rankdir=TB; size=""; "Enum" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Generic enumeration."]; "GradedSpikeCfg" [URL="../lava/lava.magma.core.learning.html#lava.magma.core.learning.constants.GradedSpikeCfg",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="An enumeration."]; "IntEnum" -> "GradedSpikeCfg" [arrowsize=0.5,style="setlinewidth(0.5)"]; "IntEnum" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Enum where members are also (and must be) ints"]; "Enum" -> "IntEnum" [arrowsize=0.5,style="setlinewidth(0.5)"]; }
class lava.magma.core.learning.constants.GradedSpikeCfg(value)

Bases: IntEnum

An enumeration.

ADD_WITHOUT_SATURATION = 3
ADD_WITH_SATURATION = 2
OVERWRITE = 1
USE_REGULAR_IMPULSE = 0

lava.magma.core.learning.learning_rule

digraph inheritance70b5a5cd0a { bgcolor=transparent; rankdir=TB; size=""; "Loihi2FLearningRule" [URL="../lava/lava.magma.core.learning.html#lava.magma.core.learning.learning_rule.Loihi2FLearningRule",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top"]; "LoihiLearningRule" -> "Loihi2FLearningRule" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Loihi3FLearningRule" [URL="../lava/lava.magma.core.learning.html#lava.magma.core.learning.learning_rule.Loihi3FLearningRule",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Encapsulation of learning-related information according to Loihi."]; "LoihiLearningRule" -> "Loihi3FLearningRule" [arrowsize=0.5,style="setlinewidth(0.5)"]; "LoihiLearningRule" [URL="../lava/lava.magma.core.learning.html#lava.magma.core.learning.learning_rule.LoihiLearningRule",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Encapsulation of learning-related information according to Loihi."]; }
class lava.magma.core.learning.learning_rule.Loihi2FLearningRule(dw=None, dd=None, dt=None, x1_impulse=0.0, x1_tau=0.0, x2_impulse=0.0, x2_tau=0.0, y1_impulse=0.0, y1_tau=0.0, y2_impulse=0.0, y2_tau=0.0, y3_impulse=0.0, y3_tau=0.0, t_epoch=1, rng_seed=None)

Bases: LoihiLearningRule

class lava.magma.core.learning.learning_rule.Loihi3FLearningRule(dw=None, dd=None, dt=None, x1_impulse=0.0, x1_tau=0.0, x2_impulse=0.0, x2_tau=0.0, t_epoch=1, rng_seed=None)

Bases: LoihiLearningRule

Encapsulation of learning-related information according to Loihi.

By using the three-factor (3F) learning rule all post-synaptic traces are handled by the post-synaptic neuron. Hence, the y_impulses and y_taus are set to 0 resp. 2^32 to the corresponding low-pass filter.

A LoihiLearningRule object has the following main objectives: (1) Given string representations of learning rules (equations) describing dynamics of the three synaptic variables (weight, delay, tag), generate adequate ProductSeries representations and store them.

(2) Store other learning-related information such as: impulse values by which to update traces upon spikes; time constants by which to decay traces over time; the length of the learning epoch; a dict with dependencies as keys and the set of all traces appearing with them in the specified learning rules as values; the set of traces used by all specified learning rules.

From the user’s perspective, a LoihiLearningRule object is to be used as follows: (1) Instantiate an implementation of LoihiLearningRule object with learning rules given in string format for all three synaptic variables (dw, dd, dt), as well as trace configuration parameters (impulse, decay) for all available traces (x1, x2, y1), and the learning epoch length.

(2) The LoihiLearningRule object encapsulating learning-related information is then passed to the Dense Process as instantiation argument.

(3) It will internally be used by ProcessModels to derive the operations to be executed in the learning phase (Py and Nc).

Parameters:
  • dw (str) – ProductSeries representation of synaptic weight learning rule.

  • dd (str) – ProductSeries representation of synaptic delay learning rule.

  • dt (str) – ProductSeries representation of synaptic tag learning rule.

  • x1_impulse (float) – Impulse by which x1 increases upon each pre-synaptic spike.

  • x1_tau (int) – Time constant by which x1 trace decays exponentially over time.

  • x2_impulse (float) – Impulse by which x2 increases upon each pre-synaptic spike.

  • x2_tau (int) – Time constant by which x2 trace decays exponentially over time.

  • t_epoch (int) – Duration of learning epoch.

  • rng_seed (int) – Seed for the random number generators. If None, seed will be chosen randomly. Only used in fixed point implementations.

class lava.magma.core.learning.learning_rule.LoihiLearningRule(dw=None, dd=None, dt=None, x1_impulse=0.0, x1_tau=0.0, x2_impulse=0.0, x2_tau=0.0, y1_impulse=0.0, y1_tau=0.0, y2_impulse=0.0, y2_tau=0.0, y3_impulse=0.0, y3_tau=0.0, t_epoch=1, rng_seed=None)

Bases: object

Encapsulation of learning-related information according to Loihi.

A LoihiLearningRule object has the following main objectives: (1) Given string representations of learning rules (equations) describing dynamics of the three synaptic variables (weight, delay, tag), generate adequate ProductSeries representations and store them.

(2) Store other learning-related information such as: impulse values by which to update traces upon spikes; time constants by which to decay traces over time; the length of the learning epoch; a dict with dependencies as keys and the set of all traces appearing with them in the specified learning rules as values; the set of traces used by all specified learning rules.

From the user’s perspective, a LoihiLearningRule object is to be used as follows: (1) Instantiate an implementation of LoihiLearningRule object with learning rules given in string format for all three synaptic variables (dw, dd, dt), as well as trace configuration parameters (impulse, decay) for all available traces (x1, x2, y1), and the learning epoch length.

(2) The LoihiLearningRule object encapsulating learning-related information is then passed to the Dense Process as instantiation argument.

(3) It will internally be used by ProcessModels to derive the operations to be executed in the learning phase (Py and Nc).

Parameters:
  • dw (str) – ProductSeries representation of synaptic weight learning rule.

  • dd (str) – ProductSeries representation of synaptic delay learning rule.

  • dt (str) – ProductSeries representation of synaptic tag learning rule.

  • x1_impulse (float) – Impulse by which x1 increases upon each pre-synaptic spike.

  • x1_tau (int) – Time constant by which x1 trace decays exponentially over time.

  • x2_impulse (float) – Impulse by which x2 increases upon each pre-synaptic spike.

  • x2_tau (int) – Time constant by which x2 trace decays exponentially over time.

  • y1_impulse (float) – Impulse by which y1 increases upon each post-synaptic spike.

  • y1_tau (int) – Time constant by which y1 trace decays exponentially over time.

  • y2_impulse (float) – Impulse by which y2 increases upon each post-synaptic spike.

  • y2_tau (int) – Time constant by which y2 trace decays exponentially over time.

  • y3_impulse (float) – Impulse by which y3 increases upon each post-synaptic spike.

  • y3_tau (int) – Time constant by which y3 trace decays exponentially over time.

  • t_epoch (int) – Duration of learning epoch.

  • rng_seed (int) – Seed for the random number generators. If None, seed will be chosen randomly. Only used in fixed point implementations.

property active_product_series: Dict[str, ProductSeries]

Get the active ProductSeries dict, containing ProductSeries associated to string learning rules that were not None.

Mapped by target name: either one of (dw, dd, dt)

Returns:

active_product_series – Active ProductSeries dict.

Return type:

dict

property active_traces: Set[str]

Get the set of all active traces in all ProductSeries of this LoihiLearningRule.

Returns:

active_traces – Set of all active traces.

Return type:

set

property active_traces_per_dependency: Dict[str, Set[str]]

Get the dict of active traces per dependency associated with all ProductSeries of this LoihiLearningRule.

Returns:

active_traces_per_dependency – Set of active traces per dependency in the list of ProductSeries.

Return type:

dict

property dd: ProductSeries | None

Get the ProductSeries associated with the “dd” target.

Returns:

dd – ProductSeries associated with the “dd” target.

Return type:

ProductSeries, optional

property dd_str
property decimate_exponent: int | None

Get the decimate exponent of this LoihiLearningRule.

Returns:

decimate_exponent – Decimate exponent of this LoihiLearningRule.

Return type:

int, optional

property dt: ProductSeries | None

Get the ProductSeries associated with the “dt” target.

Returns:

dt – ProductSeries associated with the “dt” target.

Return type:

ProductSeries, optional

property dt_str
property dw: ProductSeries | None

Get the ProductSeries associated with the “dw” target.

Returns:

dw – ProductSeries associated with the “dw” target.

Return type:

ProductSeries, optional

property dw_str
property rng_seed: int
property t_epoch: int

Get the epoch length.

Returns:

t_epoch – Epoch length.

Return type:

int

property x1_impulse: float

Get the impulse value for x1 trace.

Returns:

x1_impulse – Impulse value for x1 trace.

Return type:

float

property x1_tau: float

Get the tau value for x1 trace.

Returns:

x1_tau – Tau value for x1 trace.

Return type:

int

property x2_impulse: float

Get the impulse value for x2 trace.

Returns:

x2_impulse – Impulse value for x2 trace.

Return type:

float

property x2_tau: float

Get the tau value for x2 trace.

Returns:

x2_tau – Tau value for x2 trace.

Return type:

int

property y1_impulse: float

Get the impulse value for y1 trace.

Returns:

y1_impulse – Impulse value for y1 trace.

Return type:

float

property y1_tau: float

Get the tau value for y1 trace.

Returns:

y1_tau – Tau value for y1 trace.

Return type:

int

property y2_impulse: float

Get the impulse value for y2 trace.

Returns:

y2_impulse – Impulse value for y2 trace.

Return type:

float

property y2_tau: float

Get the tau value for y2 trace.

Returns:

y2_tau – Tau value for y2 trace.

Return type:

int

property y3_impulse: float

Get the impulse value for y3 trace.

Returns:

y3_impulse – Impulse value for y3 trace.

Return type:

float

property y3_tau: float

Get the tau value for y3 trace.

Returns:

y3_tau – Tau value for y3 trace.

Return type:

int

lava.magma.core.learning.learning_rule_applier

digraph inheritance31b6daccc0 { bgcolor=transparent; rankdir=TB; size=""; "AbstractLearningRuleApplier" [URL="../lava/lava.magma.core.learning.html#lava.magma.core.learning.learning_rule_applier.AbstractLearningRuleApplier",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="The LearningRuleApplier is a Python-specific representation of learning"]; "LearningRuleApplierBitApprox" [URL="../lava/lava.magma.core.learning.html#lava.magma.core.learning.learning_rule_applier.LearningRuleApplierBitApprox",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="The LearningRuleFixedApplier is an implementation of"]; "AbstractLearningRuleApplier" -> "LearningRuleApplierBitApprox" [arrowsize=0.5,style="setlinewidth(0.5)"]; "LearningRuleApplierFloat" [URL="../lava/lava.magma.core.learning.html#lava.magma.core.learning.learning_rule_applier.LearningRuleApplierFloat",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="The LearningRuleFloatApplier is an implementation of"]; "AbstractLearningRuleApplier" -> "LearningRuleApplierFloat" [arrowsize=0.5,style="setlinewidth(0.5)"]; }
class lava.magma.core.learning.learning_rule_applier.AbstractLearningRuleApplier(product_series)

Bases: object

The LearningRuleApplier is a Python-specific representation of learning rules. It is associated with a ProductSeries.

LearningRuleApplier implementations have to define an apply method, which tells how the learning rule represented by the associated ProductSeries, given states of Dependencies and Factors passed as arguments, is to be evaluated.

Parameters:

product_series (ProductSeries) – ProductSeries associated with this LearningRuleApplier.

abstract apply(init_accumulator, **applier_args)
Return type:

ndarray

class lava.magma.core.learning.learning_rule_applier.LearningRuleApplierBitApprox(product_series)

Bases: AbstractLearningRuleApplier

The LearningRuleFixedApplier is an implementation of AbstractLearningRuleApplier to be used with the PyFixedLearningDenseProcessModel.

Contrary to LearningRuleFloatApplier, there is no applier string constructed at initialization for LearningRuleFixedApplier. The apply method has to loop through all Products/Factors of the associated ProductSeries and accumulate results of synaptic variable update computation along the way.

This is due to the fact that it is not straightforward to construct such a string, in the fixed-point case, as there are intermediary stateful bit-shifts happening between steps of the computation, which can’t be translated to string operations.

apply(init_accumulator, **applier_args)

Apply the learning rule represented by this LearningRuleFixedApplier.

When called from the PyFixedLearningDenseProcessModel, applier_args contains variables with the following names : {“shape”, “x0”, “y0”, “u”, “weights”, “tag_2”, “tag_1”, “x_traces”, “y_traces”}

All variables apart from “shape”, “u” are numpy arrays. “shape” is a tuple. “u” is a scalar.

Parameters:

init_accumulator (np.ndarray) – Shifted values of the synaptic variable before learning rule application.

Returns:

result – Shifted values of the synaptic variable after learning rule application.

Return type:

np.ndarray

class lava.magma.core.learning.learning_rule_applier.LearningRuleApplierFloat(product_series)

Bases: AbstractLearningRuleApplier

The LearningRuleFloatApplier is an implementation of AbstractLearningRuleApplier to be used with the PyFloatLearningDenseProcessModel.

At initialization, it goes through the associated ProductSeries and derives a string representation of the learning rule where Dependencies and Factors are written in a way that is coherent with the names of the state variables they are associated to in the arguments of the apply method.

This string is compiled at initialization and evaluated at every call to apply.

Example: dw = “-2 * x0 * y1 + 4 * y0 * x1 + u0 * w”

applier_str = “-2 * x0 * traces[0][2] + 4 * y0 * traces[1][0] + u * weights”

apply(init_accumulator, **applier_args)

Apply the learning rule represented by this LearningRuleFloatApplier.

When called from the PyFloatLearningDenseProcessModel, applier_args contains variables with the following names : {“x0”, “y0”, “u”, “weights”, “tag_2”, “tag_1”, “np”, “traces”}

All variables apart from “u”, “np” are numpy arrays.

“u” is a scalar. “np” is a reference to numpy as it is needed for the evaluation of “np.sign()” types of call inside the applier string.

Parameters:

init_accumulator (np.ndarray) – Values of the synaptic variable before learning rule application.

Returns:

result – Values of the synaptic variable after learning rule application.

Return type:

np.ndarray

lava.magma.core.learning.product_series

digraph inheritance6cb1faa24c { bgcolor=transparent; rankdir=TB; size=""; "Factor" [URL="../lava/lava.magma.core.learning.html#lava.magma.core.learning.product_series.Factor",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Factor representation of a single factor found in a Product."]; "Product" [URL="../lava/lava.magma.core.learning.html#lava.magma.core.learning.product_series.Product",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Product representation of a single product found in a ProductSeries."]; "ProductSeries" [URL="../lava/lava.magma.core.learning.html#lava.magma.core.learning.product_series.ProductSeries",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="ProductSeries representation of a single learning rule."]; }
class lava.magma.core.learning.product_series.Factor(state_var, const=None, is_sgn=False)

Bases: object

Factor representation of a single factor found in a Product.

A Factor is a custom data structure holding information on: (1) State variable used by this Factor. (2) An optional constant added to the state variable. (3) Flag specifying if this Factor is a sgn() factor.

Parameters:
  • state_var (str) – State variable involved in this Factor.

  • const (int, optional) – Constant involved in this Factor.

  • is_sgn (bool) – Flag specifying if this Factor involves the sgn() function.

property const: int | None

Get the constant involved in this Factor.

Returns:

const – Constant involved in this Factor.

Return type:

int, optional

property factor_type: str

Get factor type string of this Factor.

Returns:

factor_type – Factor type string.

Return type:

str

has_const()

Check if this Factor has a constant.

Returns:

has_constant – Flag specifying if this Factor has a constant or not.

Return type:

bool

property is_sgn: bool

Get the is_sgn flag involved in this Factor, specifying if this Factor is an sgn Factor.

Returns:

is_sgn – Flag specifying if this Factor is an sgn Factor.

Return type:

bool

property state_var: str

Get the state variable involved in this Factor.

Returns:

state_var – State variable involved in this Factor.

Return type:

str

class lava.magma.core.learning.product_series.Product(target, dependency, s_mantissa, s_exp, factors, decimate_exponent=None)

Bases: object

Product representation of a single product found in a ProductSeries.

A Product is a custom data structure holding information on: (1) Synaptic variable affected by the learning rule (target). (2) Dependency of the Product. (3) Mantissa of the scaling factor associated with the Product. (4) Exponent of the scaling factor associated with the Product. (5) List of Factors. (6) Decimate exponent used if the Dependency is uk.

Parameters:
  • target (str) – Left-hand side of learning rule equation in which the product appears. Either one of (dw, dd, dt).

  • dependency (str) – Dependency used for this Product.

  • s_mantissa (int) – Mantissa of the scaling constant for this Product.

  • s_exp (int) – Exponent of the scaling constant for this Product.

  • factors (list) – List of Factor objects for this Product.

  • decimate_exponent (int, optional) – Decimate exponent used, if dependency is uk.

property decimate_exponent: int | None

Get the decimate exponent of this Product.

Will be None if the dependency is not “u”.

Returns:

decimate_exponent – Decimate exponent of this Product.

Return type:

int, optional

property dependency: str

Get the dependency of this Product.

Returns:

dependency – Dependency of this Product.

Return type:

str

property factors: List[Factor]

Get the list of Factors involved in this Product.

Returns:

factors – List of Factors involved in this Product.

Return type:

list

property s_exp: int

Get the exponent of the scaling factor of this Product.

Returns:

s_exp – Exponent of the scaling factor of this Product.

Return type:

str

property s_mantissa: int

Get the mantissa of the scaling factor of this Product.

Returns:

s_mantissa – Mantissa of the scaling factor of this Product.

Return type:

str

property target: str

Get the target of this Product.

Returns:

target – Target of this Product.

Return type:

str

class lava.magma.core.learning.product_series.ProductSeries(symbolic_equation)

Bases: object

ProductSeries representation of a single learning rule.

A ProductSeries is a custom data structure holding information on: (1) Synaptic variable affected by the learning rule (target). (2) Decimate exponent used in uk dependencies, if any. (3) List of Products. (4) Dict with dependencies as keys and the set of all traces appearing with them in this ProductSeries.

Parameters:
  • target (str) – Left-hand side of learning rule equation. Either one of (dw, dd, dt).

  • decimate_exponent (int, optional) – Decimate exponent used in uk dependencies, if any.

  • products (list) – List of Products.

active_traces_per_dependency

Dict mapping active traces to the set of dependencies they appear with.

Type:

dict

property active_traces_per_dependency: Dict[str, Set[str]]

Get the dict of active traces per dependency associated with this ProductSeries.

Returns:

active_traces_per_dependency – Set of active traces per dependency in the list of ProductSeries.

Return type:

dict

property decimate_exponent: int | None

Get the decimate exponent of this ProductSeries.

Returns:

decimate_exponent – Decimate exponent of this ProductSeries.

Return type:

int, optional

property products: List[Product]

Get the list of Products involved in this ProductSeries.

Returns:

products – List of Products involved in this ProductSeries.

Return type:

list

property target: str

Get the target of this ProductSeries.

Returns:

target – Target of this ProductSeries.

Return type:

str

lava.magma.core.learning.random

digraph inheritance190ca68545 { bgcolor=transparent; rankdir=TB; size=""; "AbstractRandomGenerator" [URL="../lava/lava.magma.core.learning.html#lava.magma.core.learning.random.AbstractRandomGenerator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Super class for random generators."]; "ConnVarRandom" [URL="../lava/lava.magma.core.learning.html#lava.magma.core.learning.random.ConnVarRandom",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Synaptic variable random generator."]; "AbstractRandomGenerator" -> "ConnVarRandom" [arrowsize=0.5,style="setlinewidth(0.5)"]; "TraceRandom" [URL="../lava/lava.magma.core.learning.html#lava.magma.core.learning.random.TraceRandom",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Trace random generator."]; "AbstractRandomGenerator" -> "TraceRandom" [arrowsize=0.5,style="setlinewidth(0.5)"]; }
class lava.magma.core.learning.random.AbstractRandomGenerator

Bases: object

Super class for random generators.

abstract advance(*args, **kwargs)
class lava.magma.core.learning.random.ConnVarRandom(seed_stochastic_rounding=2)

Bases: AbstractRandomGenerator

Synaptic variable random generator.

A ConnVarRandom generator holds randomly generated numbers for: (1) Stochastic rounding after learning rule application (float).

A call to the advance method generates new random numbers for each of these.

Parameters:

seed_stochastic_rounding (optional, int) – Seed for random generator of stochastic rounding after learning rule application.

advance()

Generate new random numbers for: (1) Stochastic rounding after learning rule application.

Return type:

None

property random_stochastic_round: float

Get randomly generated number for stochastic rounding after learning rule application.

Returns:

random_stochastic_round – Randomly generated number for stochastic rounding after learning rule application.

Return type:

float

class lava.magma.core.learning.random.TraceRandom(seed_trace_decay=0, seed_impulse_addition=1)

Bases: AbstractRandomGenerator

Trace random generator.

A TraceRandom generator holds randomly generated numbers for: (1) Stochastic rounding after trace decay (float). (2) Stochastic rounding after impulse addition (integer).

A call to the advance method generates new random numbers for each of these.

Parameters:
  • seed_trace_decay (optional, int) – Seed for random generator of stochastic rounding after trace decay.

  • seed_impulse_addition (optional, int) – Seed for random generator of stochastic rounding after impulse addition.

advance()

Generate new random numbers for: (1) Stochastic rounding after trace decay. (2) Stochastic rounding after impulse addition.

Return type:

None

property random_impulse_addition: int

Get randomly generated number for stochastic rounding after impulse addition.

Returns:

random_trace_decay – Randomly generated number for stochastic rounding after impulse addition.

Return type:

int

property random_trace_decay: float

Get randomly generated number for stochastic rounding after trace decay.

Returns:

random_trace_decay – Randomly generated number for stochastic rounding after trace decay.

Return type:

float

lava.magma.core.learning.string_symbols

lava.magma.core.learning.symbolic_equation

digraph inheritance8bf4b35c73 { bgcolor=transparent; rankdir=TB; size=""; "ABC" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Helper class that provides a standard way to create an ABC using"]; "Addition" [URL="../lava/lava.magma.core.learning.html#lava.magma.core.learning.symbolic_equation.Addition",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Symbol representing the addition operator."]; "Operator" -> "Addition" [arrowsize=0.5,style="setlinewidth(0.5)"]; "BracketExpression" [URL="../lava/lava.magma.core.learning.html#lava.magma.core.learning.symbolic_equation.BracketExpression",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Symbol representing a bracket expression of the form : (...)."]; "Expression" -> "BracketExpression" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Dependency" [URL="../lava/lava.magma.core.learning.html#lava.magma.core.learning.symbolic_equation.Dependency",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Abstract super class for dependency Symbols."]; "FactorSym" -> "Dependency" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Expression" [URL="../lava/lava.magma.core.learning.html#lava.magma.core.learning.symbolic_equation.Expression",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Abstract super class for multi-symbol Symbols."]; "FactorSym" -> "Expression" [arrowsize=0.5,style="setlinewidth(0.5)"]; "FactorSym" [URL="../lava/lava.magma.core.learning.html#lava.magma.core.learning.symbolic_equation.FactorSym",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Abstract super class for factor Symbols."]; "Symbol" -> "FactorSym" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Literal" [URL="../lava/lava.magma.core.learning.html#lava.magma.core.learning.symbolic_equation.Literal",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Symbol representing a literal."]; "Symbol" -> "Literal" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Multiplication" [URL="../lava/lava.magma.core.learning.html#lava.magma.core.learning.symbolic_equation.Multiplication",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Symbol representing the multiplication operator."]; "Operator" -> "Multiplication" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Operator" [URL="../lava/lava.magma.core.learning.html#lava.magma.core.learning.symbolic_equation.Operator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Abstract super class for operator Symbols."]; "Symbol" -> "Operator" [arrowsize=0.5,style="setlinewidth(0.5)"]; "SgnExpression" [URL="../lava/lava.magma.core.learning.html#lava.magma.core.learning.symbolic_equation.SgnExpression",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Symbol representing a sign expression of the form : sgn(...)."]; "Expression" -> "SgnExpression" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Subtraction" [URL="../lava/lava.magma.core.learning.html#lava.magma.core.learning.symbolic_equation.Subtraction",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Symbol representing the subtraction operator."]; "Operator" -> "Subtraction" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Symbol" [URL="../lava/lava.magma.core.learning.html#lava.magma.core.learning.symbolic_equation.Symbol",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Super class for all possible symbols."]; "ABC" -> "Symbol" [arrowsize=0.5,style="setlinewidth(0.5)"]; "SymbolList" [URL="../lava/lava.magma.core.learning.html#lava.magma.core.learning.symbolic_equation.SymbolList",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Represents as list of Symbols."]; "Symbol" -> "SymbolList" [arrowsize=0.5,style="setlinewidth(0.5)"]; "SymbolicEquation" [URL="../lava/lava.magma.core.learning.html#lava.magma.core.learning.symbolic_equation.SymbolicEquation",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="The SymbolicEquation represents a learning rule as a set of symbols."]; "Uk" [URL="../lava/lava.magma.core.learning.html#lava.magma.core.learning.symbolic_equation.Uk",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Symbol representing the uk dependency."]; "Dependency" -> "Uk" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Variable" [URL="../lava/lava.magma.core.learning.html#lava.magma.core.learning.symbolic_equation.Variable",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Symbol representing traces and synaptic variable factors."]; "FactorSym" -> "Variable" [arrowsize=0.5,style="setlinewidth(0.5)"]; "X0" [URL="../lava/lava.magma.core.learning.html#lava.magma.core.learning.symbolic_equation.X0",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Symbol representing the x0 dependency."]; "Dependency" -> "X0" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Y0" [URL="../lava/lava.magma.core.learning.html#lava.magma.core.learning.symbolic_equation.Y0",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Symbol representing the y0 dependency."]; "Dependency" -> "Y0" [arrowsize=0.5,style="setlinewidth(0.5)"]; }
class lava.magma.core.learning.symbolic_equation.Addition(expr='')

Bases: Operator

Symbol representing the addition operator.

static find(expr)

Factory method for creating Addition symbols.

Matches an expression to the regular expressions “+”.

Return a Addition Symbol if there is a match and the rest of the expression.

Parameters:

expr (str) – String expression.

Return type:

Tuple[Optional[Addition], str]

Returns:

  • symbol (Addition, optional) – Symbol matching regular expression.

  • expr (str) – Remaining string expression after extraction of the symbol.

class lava.magma.core.learning.symbolic_equation.BracketExpression

Bases: Expression

Symbol representing a bracket expression of the form : (…).

static find(expr)

Factory method for creating BracketExpression symbols.

Matches an expression to the regular expression “(”. If there is a match, find the sub expression.

Return a BracketExpression Symbol if there is a match and closing bracket and the rest of the expression.

Parameters:

expr (str) – String expression.

Return type:

Tuple[Optional[BracketExpression], str]

Returns:

  • symbol (BracketExpression, optional) – Symbol matching regular expression.

  • expr (str) – Remaining string expression after extraction of the symbol.

find_sub_expr(expr)

Find sub-expression of an expression, assuming the expression is of the form “(…)”, representing a BracketExpression.

Parameters:

expr (str) – String expression.

Returns:

sub_expr – String sub-expression.

Return type:

str

class lava.magma.core.learning.symbolic_equation.Dependency(expr='')

Bases: FactorSym

Abstract super class for dependency Symbols.

class lava.magma.core.learning.symbolic_equation.Expression

Bases: FactorSym

Abstract super class for multi-symbol Symbols.

abstract find_sub_expr(expr)
Return type:

str

property sub_expr: str | None

Get sub-expression of this Expression.

Returns:

sub_expr – String sub-expression.

Return type:

str

property symbol_list: SymbolList | None

Get SymbolList associated with sub-expression of this Expression.

Returns:

symbol_list – SymbolList.

Return type:

SymbolList

class lava.magma.core.learning.symbolic_equation.FactorSym(expr='')

Bases: Symbol

Abstract super class for factor Symbols.

class lava.magma.core.learning.symbolic_equation.Literal

Bases: Symbol

Symbol representing a literal.

property base: int

Get base of this Literal.

Returns:

base – Base of this literal.

Return type:

int

property exponent: int

Get exponent of this Literal.

Returns:

exponent – Exponent of this literal.

Return type:

int

static find(expr)

Factory method for creating Literal symbols.

Matches an expression to the regular expressions “[+-]?d+*2^[+-]?d+”, “[+-]?2^[+-]?d+”, “[+-]?d+”.

Return a Literal Symbol if there is a match and closing bracket and the rest of the expression.

Parameters:

expr (str) – String expression.

Returns:

  • symbol (Literal, optional) – Symbol matching regular expression.

  • expr (str) – Remaining string expression after extraction of the symbol.

property literal_type: int

Get literal type of this Literal.

Returns:

literal_type – Literal type of this literal.

Return type:

int

property mantissa: int

Get mantissa of this Literal.

Returns:

mantissa – Mantissa of this literal.

Return type:

int

to_int()

Extract mantissa, base and exponent of this Literal from string expression and store them.

Return type:

None

property val: int

Get the integer value represented by this Literal.

Returns:

val – Integer value of this Literal.

Return type:

int

class lava.magma.core.learning.symbolic_equation.Multiplication(expr='')

Bases: Operator

Symbol representing the multiplication operator.

static find(expr)

Factory method for creating Multiplication symbols.

Matches an expression to the regular expressions “*”.

Return a Multiplication Symbol if there is a match and the rest of the expression.

Parameters:

expr (str) – String expression.

Return type:

Tuple[Optional[Multiplication], str]

Returns:

  • symbol (Multiplication, optional) – Symbol matching regular expression.

  • expr (str) – Remaining string expression after extraction of the symbol.

class lava.magma.core.learning.symbolic_equation.Operator(expr='')

Bases: Symbol

Abstract super class for operator Symbols.

class lava.magma.core.learning.symbolic_equation.SgnExpression

Bases: Expression

Symbol representing a sign expression of the form : sgn(…).

static find(expr)

Factory method for creating SgnExpression symbols.

Matches an expression to the regular expression “sgn(”. If there is a match, find the sub expression.

Return a SgnExpression Symbol if there is a match and closing bracket and the rest of the expression.

Parameters:

expr (str) – String expression.

Return type:

Tuple[Optional[SgnExpression], str]

Returns:

  • symbol (SgnExpression, optional) – Symbol matching regular expression.

  • expr (str) – Remaining string expression after extraction of the symbol.

find_sub_expr(expr)

Find sub-expression of an expression, assuming the expression is of the form “sgn(…)”, representing a SgnExpression.

Parameters:

expr (str) – String expression.

Returns:

sub_expr – String sub-expression.

Return type:

str

class lava.magma.core.learning.symbolic_equation.Subtraction(expr='')

Bases: Operator

Symbol representing the subtraction operator.

static find(expr)

Factory method for creating Subtraction symbols.

Matches an expression to the regular expressions “-”.

Return a Subtraction Symbol if there is a match and the rest of the expression.

Parameters:

expr (str) – String expression.

Return type:

Tuple[Optional[Subtraction], str]

Returns:

  • symbol (Subtraction, optional) – Symbol matching regular expression.

  • expr (str) – Remaining string expression after extraction of the symbol.

class lava.magma.core.learning.symbolic_equation.Symbol(expr='')

Bases: ABC

Super class for all possible symbols.

property expr: str

Get expression of the Symbol.

Returns:

expr – String expression.

Return type:

str

static find_expr(expr, reg_expr, symbol)

Factory method for creating symbols.

Matches an expression to a regular expression and if there is a match, return a symbol of the matching part of the expression as well as the rest of the expression.

Parameters:
  • expr (str) – String expression.

  • reg_expr (str) – Regular expression.

  • symbol (Symbol) – Uninitialized symbol

Return type:

Tuple[Optional[Symbol], str]

Returns:

  • symbol (Symbol, optional) – Symbol matching regular expression.

  • expr (str) – Remaining string expression after extraction of the symbol.

class lava.magma.core.learning.symbolic_equation.SymbolList

Bases: Symbol

Represents as list of Symbols.

append(symbol)

Append a Symbol to the SymbolList’s list and the Symbol’s expression to the SymbolList’s expression.

Parameters:

symbol (Symbol) – Symbol object.

Return type:

None

property list: List[Symbol]

Get list of the SymbolList.

Returns:

list – List of Symbol objects.

Return type:

list

class lava.magma.core.learning.symbolic_equation.SymbolicEquation(target, str_learning_rule)

Bases: object

The SymbolicEquation represents a learning rule as a set of symbols.

It provides means to generate a SymbolicEquation from a string following a fixed syntax.

Parameters:
  • target (str) – Target of the learning rule to be represented by this SymbolicEquation.

  • str_learning_rule (str) – Learning rule in string format to be represented by this SymbolicEquation.

property symbol_list: SymbolList

Get SymbolList of this SymbolicEquation.

Returns:

symbol_list – SymbolList of this SymbolicEquation.

Return type:

SymbolList

property target: str

Get target of this SymbolicEquation.

Returns:

target – Target of this SymbolicEquation.

Return type:

str

class lava.magma.core.learning.symbolic_equation.Uk

Bases: Dependency

Symbol representing the uk dependency.

property decimate_exponent: int | None

Get decimate exponent of this Uk.

Returns:

decimate_exponent – Decimate exponent.

Return type:

int

static find(expr)

Factory method for creating Uk symbols.

Matches an expression to the regular expressions “ud”.

Return a Uk Symbol if there is a match and the rest of the expression.

Parameters:

expr (str) – String expression.

Return type:

Tuple[Optional[Uk], str]

Returns:

  • symbol (Uk, optional) – Symbol matching regular expression.

  • expr (str) – Remaining string expression after extraction of the symbol.

class lava.magma.core.learning.symbolic_equation.Variable(expr='')

Bases: FactorSym

Symbol representing traces and synaptic variable factors.

static find(expr)

Factory method for creating Variable symbols.

Matches an expression to the regular expressions “x[12]”, “y[123]”, “w”, “d”, “t”.

Return a Variable Symbol if there is a match and the rest of the expression.

Parameters:

expr (str) – String expression.

Return type:

Tuple[Optional[Variable], str]

Returns:

  • symbol (Variable, optional) – Symbol matching regular expression.

  • expr (str) – Remaining string expression after extraction of the symbol.

class lava.magma.core.learning.symbolic_equation.X0(expr='')

Bases: Dependency

Symbol representing the x0 dependency.

static find(expr)

Factory method for creating X0 symbols.

Matches an expression to the regular expressions “x0”.

Return a X0 Symbol if there is a match and the rest of the expression.

Parameters:

expr (str) – String expression.

Return type:

Tuple[Optional[X0], str]

Returns:

  • symbol (X0, optional) – Symbol matching regular expression.

  • expr (str) – Remaining string expression after extraction of the symbol.

class lava.magma.core.learning.symbolic_equation.Y0(expr='')

Bases: Dependency

Symbol representing the y0 dependency.

static find(expr)

Factory method for creating Y0 symbols.

Matches an expression to the regular expressions “y0”.

Return a Y0 Symbol if there is a match and the rest of the expression.

Parameters:

expr (str) – String expression.

Return type:

Tuple[Optional[Y0], str]

Returns:

  • symbol (Y0, optional) – Symbol matching regular expression.

  • expr (str) – Remaining string expression after extraction of the symbol.

lava.magma.core.learning.utils

lava.magma.core.learning.utils.apply_mask(item, nb_bits)

Get nb_bits least-significant bits.

Parameters:
  • item (np.ndarray or int) – Item to apply mask to.

  • nb_bits (int) – Number of LSBs to keep.

Returns:

result – Least-significant bits.

Return type:

np.ndarray or int

lava.magma.core.learning.utils.float_to_literal(learning_parameter)

Convert the floating point representation of the learning parameter to the form mantissa * 2 ^ [+/1]exponent. :param learning_parameters: the float value of learning-related parameter :type learning_parameters: float

Returns:

result – string representation of learning_parameter.

Return type:

str

lava.magma.core.learning.utils.stochastic_round(values, random_numbers, probabilities)

Stochastically add 1 to an ndarray at location where random numbers are less than given probabilities.

Parameters:
  • values (ndarray) – Values before stochastic rounding.

  • random_numbers (int or float or ndarray) – Randomly generated number or ndarray of numbers.

  • probabilities (ndarray) – Probabilities to stochastically round.

Returns:

result – Stochastically rounded values.

Return type:

ndarray