lava.magma.core

lava.magma.core.decorator

lava.magma.core.decorator.implements(proc=None, protocol=None)

Decorates ProcessModel class by adding the class of the Process and SyncProtocol that this ProcessModel implements as a class variable.

‘implements’ will fail if an attempt is made to overwrite an already set Process or SyncProtocol class of a parent class.

Parameters
  • proc (The Process class that the ProcessModel implements.) –

  • protocol (The SyncProtocol tht the ProcessModel implements.) –

lava.magma.core.decorator.requires(*args)

Decorator for ProcessModel classes that adds class variable to ProcessModel class that specifies which resources the ProcessModel requires. In order to express optionality between one or more resources, include them in a list or tuple.

Example: @requires(Res1, Res2, [Res3, Res4])

-> Requires Res1 and Res2 and one of Res3 or Res4

lava.magma.core.decorator.tag(*args)

Decorator for ProcessModel to add a class variable (a list of tags) to ProcessModel class, which further distinguishes ProcessModels implementing the same Process, with the same type and requiring the same ComputeResources.

For example, a user may write multiple ProcessModels in Python ( PyProcessModels), requiring CPU for execution (@requires(CPU)). The compiler selects the appropriate ProcessModel via RunConfig using the keywords stored in the list of tags set by this decorator.

The list of tags is additive over inheritance. Which means, if @tag decorates a child class, whose parent is already decorated, then the new keywords are appended to the tag-list inherited from the parent.

Parameters

args (keywords that tag a ProcessModel) –

Return type

Decorated class

Examples

>>> @implements(proc=ExampleProcess)
>>> @tag('bit-accurate', 'loihi')
>>> class ExampleProcModel(AbstractProcessModel):...

These tags identify a particular ProcessModel as being bit-accurate with Loihi hardware platform. This means that, the numerical output produced by such a ProcessModel on a CPU would be the same as on Loihi.

lava.magma.core.resources

Inheritance diagram of lava.magma.core.resources
class lava.magma.core.resources.AbstractComputeResource

Bases: AbstractResource

A compute resource, for example a particular type of neuromorphic processor or CPU.

class lava.magma.core.resources.AbstractNode

Bases: ABC

A node is a resource that has other compute or peripheral resources.

class lava.magma.core.resources.AbstractPeripheralResource

Bases: AbstractResource

A hardware resource that is a peripheral device.

class lava.magma.core.resources.AbstractResource

Bases: ABC

A hardware resource like a compute resource (e.g., a particular type of neuromorphic processor or a CPU), peripheral device, or complete system that is required for a ProcessModel.

Each ProcessModel lists its required hardware resources with the @requires decorator.

class lava.magma.core.resources.CPU

Bases: AbstractComputeResource

A central processing unit on a regular computer or laptop.

class lava.magma.core.resources.DVS

Bases: AbstractPeripheralResource

An event-based dynamic vision sensor (DVS).

class lava.magma.core.resources.ECPU

Bases: AbstractComputeResource

An embedded central processing unit that is part of a neuromorphic chip.

class lava.magma.core.resources.GPU

Bases: AbstractComputeResource

A graphical processing unit.

class lava.magma.core.resources.GenericNode

Bases: AbstractNode

A generic resource with a regular CPU and a hard drive.

resources = [<class 'lava.magma.core.resources.CPU'>, <class 'lava.magma.core.resources.HardDrive'>]
class lava.magma.core.resources.HardDrive

Bases: AbstractPeripheralResource

A hard drive in a computer.

class lava.magma.core.resources.HeadNode

Bases: GenericNode

The node on which user executes code, perhaps because processes require access to specific disk location.

resources = [<class 'lava.magma.core.resources.CPU'>, <class 'lava.magma.core.resources.HeadNodeHardDrive'>]
class lava.magma.core.resources.HeadNodeHardDrive

Bases: AbstractPeripheralResource

A hard drive attached to a HeadNode (the node on which a user executes code).

class lava.magma.core.resources.HostCPU

Bases: AbstractComputeResource

A central processing unit on a special host system that holds neuromorphic devices.

class lava.magma.core.resources.KapohoBay

Bases: Loihi1System

A KapohoBay system (USB form-factor) that consists of two Loihi 1 chips with Lakemont processors.

resources = [<class 'lava.magma.core.resources.Loihi1NeuroCore'>, <class 'lava.magma.core.resources.LMT'>]
class lava.magma.core.resources.KapohoPoint

Bases: Loihi2System

The smallest form-factor system with four Loihi 2 chips.

resources = [<class 'lava.magma.core.resources.Loihi2NeuroCore'>, <class 'lava.magma.core.resources.LMT'>, <class 'lava.magma.core.resources.PB'>]
class lava.magma.core.resources.LMT

Bases: ECPU

A Lakemont embedded central processing unit.

class lava.magma.core.resources.Loihi1NeuroCore

Bases: NeuroCore

A neuromorphic core on a Loihi 1 chip.

class lava.magma.core.resources.Loihi1System

Bases: AbstractNode

A neuromorphic system that carries Loihi 1 chips.

class lava.magma.core.resources.Loihi2NeuroCore

Bases: NeuroCore

A neuromorphic core on a Loihi 2 chip.

class lava.magma.core.resources.Loihi2System

Bases: AbstractNode

A neuromorphic system that carries Loihi 2 chips.

class lava.magma.core.resources.Nahuku

Bases: Loihi1System

A Nahuku system that carries up to 32 Loihi 1 chips.

resources = [<class 'lava.magma.core.resources.CPU'>, <class 'lava.magma.core.resources.Loihi1NeuroCore'>, <class 'lava.magma.core.resources.LMT'>]
class lava.magma.core.resources.NeuroCore

Bases: AbstractComputeResource

A neuromorphic core.

class lava.magma.core.resources.OheoGulch

Bases: Loihi2System

Development and test system with a single Loihi 2 chip.

resources = [<class 'lava.magma.core.resources.Loihi2NeuroCore'>, <class 'lava.magma.core.resources.LMT'>, <class 'lava.magma.core.resources.PB'>]
class lava.magma.core.resources.PB

Bases: ECPU

A Powell Bute embedded central processing unit.

class lava.magma.core.resources.Pohoiki

Bases: Loihi1System

A system configurable to have one or more Nahuku sub systems.

resources = [<class 'lava.magma.core.resources.CPU'>, <class 'lava.magma.core.resources.Loihi1NeuroCore'>, <class 'lava.magma.core.resources.LMT'>]
class lava.magma.core.resources.Unalaska

Bases: Loihi2System

resources = [<class 'lava.magma.core.resources.CPU'>, <class 'lava.magma.core.resources.Loihi2NeuroCore'>, <class 'lava.magma.core.resources.LMT'>, <class 'lava.magma.core.resources.PB'>]

lava.magma.core.run_conditions

Inheritance diagram of lava.magma.core.run_conditions
class lava.magma.core.run_conditions.AbstractRunCondition(blocking)

Bases: ABC

Base class for run conditions.

RunConditions specify for how long a process will run.

Parameters

blocking (bool) – If set to True, blocks further commands from execution until returns.

class lava.magma.core.run_conditions.RunContinuous

Bases: AbstractRunCondition

Runs a Process continuously without a time step limit (non-blocking).

Using this RunCondition, the runtime runs continuously and non-blocking. This means that the runtime must be paused or stopped manually by calling pause() or stop() from the running process. The runtime can be continued after pause() by calling run() again.

class lava.magma.core.run_conditions.RunSteps(num_steps, blocking=True)

Bases: AbstractRunCondition

Runs a process for a specified number of time steps with respect to a SyncDomain assigned to any sub processes.

Parameters
  • num_steps (int) – Number of steps to be run with respect to the SyncDomain.

  • blocking (bool) – If set to True, blocks further commands from execution until returns. (Default = True)

lava.magma.core.run_configs

Inheritance diagram of lava.magma.core.run_configs
class lava.magma.core.run_configs.AbstractLoihiHWRunCfg(custom_sync_domains=None, select_tag=None, select_sub_proc_model=False, exception_proc_model_map=None, loglevel=30)

Bases: AbstractLoihiRunCfg

class lava.magma.core.run_configs.AbstractLoihiRunCfg(custom_sync_domains=None, select_tag=None, select_sub_proc_model=False, exception_proc_model_map=None, loglevel=30)

Bases: RunConfig

Selects the appropriate ProcessModel for Loihi RunConfigs.

The following set of rules is applied, in that order of precedence:

1. A dictionary of exceptions exception_proc_model_map is checked first, in which user specifies key-value pairs {Process: ProcessModel} and the ProcessModel is returned.

  1. If there is only 1 ProcessModel available:

    • If the user does not specifically ask for any tags, the ProcessModel is returned

    • If the user asks for a specific tag, then the ProcessModel is returned only if the tag is found in its list of tags.

  2. If there are multiple `ProcessModel`s available:

    • If the user asks specifically to look for `SubProcessModel`s and they are available:

      • If there is only 1 SubProcessModel available, it is returned

      • If the user did not ask for any specific tags, the first available SubProcessModel is returned

      • If user asked for a specific tag, the first valid SubProcessModel is returned, which has the tag in its tag-list

    • If user did not explicitly ask for `SubProcessModel`s:

      • If the user did not also ask for any specific tag, then the first available ProcessModel is returned that requires the correct computing hardware.

      • If the user asked for a specific tag, the hardware-specific ProcessModel which has the tag in its tag-list is returned

Parameters
  • custom_sync_domains (List[SyncDomain]) – list of synchronization domains

  • select_tag (str) – The RunConfig will select only ProcessModels that have the tag ‘select_tag’. Example: By setting select_tag=”fixed_pt”, it will select ProcessModels that implement a fixed-point implementation of the Lava Processes in the architecture that is to be executed.

  • select_sub_proc_model (bool) – When set to True, hierarchical SubProcessModels are selected over LeafProcessModels, where available.

  • exception_proc_model_map ((Dict[AbstractProcess, AbstractProcessModel])) – explicit dictionary of {Process: ProcessModel} classes, provided as exceptions to the ProcessModel selection logic. The choices made in this dict are respected over any logic. For example, {Dense: PyDenseModel}. Note that this is a dict mapping classnames to classnames.

  • loglevel (int) – sets level of event logging, as defined by Python’s ‘logging’ facility. Default: logging.WARNING

select(proc, proc_models)

Selects an appropriate ProcessModel from a list of ProcessModels for a Process, based on user requests.

Parameters
Return type

Selected ProcessModel class

class lava.magma.core.run_configs.AbstractLoihiSimRunCfg(custom_sync_domains=None, select_tag=None, select_sub_proc_model=False, exception_proc_model_map=None, loglevel=30)

Bases: AbstractLoihiRunCfg

class lava.magma.core.run_configs.Loihi1HwCfg(custom_sync_domains=None, select_tag=None, select_sub_proc_model=False, exception_proc_model_map=None, loglevel=30, pre_run_fxs=[], post_run_fxs=[], embedded_allocation_order=EMBEDDED_ALLOCATION_ORDER.NORMAL)

Bases: AbstractLoihiHWRunCfg

A RunConfig for executing model on Loihi1 HW. For Loihi1 HW configurations, the preferred ProcModels are NcProcModels that can run on a NeuroCore of a Loihi1NeuroCore or, if none is found, CProcModels. This preference can be overwritten by a tag provided by the user. This RunConfig will default to a PyProcModel if no Loihi1-compatible ProcModel is being found. .

class lava.magma.core.run_configs.Loihi1SimCfg(custom_sync_domains=None, select_tag=None, select_sub_proc_model=False, exception_proc_model_map=None, loglevel=30)

Bases: AbstractLoihiSimRunCfg

Run configuration selects appropriate ProcessModel – either SubProcessModel for a hierarchical Process or else a PyProcessModel for a standard Process.

class lava.magma.core.run_configs.Loihi2HwCfg(custom_sync_domains=None, select_tag=None, select_sub_proc_model=False, exception_proc_model_map=None, loglevel=30, pre_run_fxs=None, post_run_fxs=None, embedded_allocation_order=EMBEDDED_ALLOCATION_ORDER.NORMAL)

Bases: AbstractLoihiHWRunCfg

A RunConfig for executing model on Loihi2 HW. For Loihi2 HW configurations, the preferred ProcModels are NcProcModels that can run on a NeuroCore of a Loihi2NeuroCore or, if none is found, CProcModels. This preference can be overwritten by a tag provided by the user. This RunConfig will default to a PyProcModel if no Loihi2-compatible ProcModel is being found.

class lava.magma.core.run_configs.Loihi2SimCfg(custom_sync_domains=None, select_tag=None, select_sub_proc_model=False, exception_proc_model_map=None, loglevel=30)

Bases: Loihi1SimCfg

A RunConfig for simulating a Loihi 2 model CPU/GPU.

class lava.magma.core.run_configs.RunConfig(custom_sync_domains=None, loglevel=30)

Bases: ABC

Basic run configuration and base class for other run configurations.

A RunConfig specifies how to execute Processes on a specific hardware backend. Its main purpose is to select the appropriate ProcessModels given the Processes to be executed and the given tags (i.e. bit-accurate, floating, etc) using the select() function.

A RunConfig allows the user to guide the compiler in its choice of ProcessModels. When the user compiles/runs a Process for the first time, a specific RunConfig must be provided. The compiler will follow the selection rules laid out in the select() method of the RunConfig to choose the optimal ProcessModel for the Process.

A RunConfig can filter the ProcessModels by various criteria. Examples include the preferred computing resource or user-defined tags. It may also specify how many computing nodes of a certain type, like embedded CPUs, will be available. This will allow to allocate all RuntimeService processes during compilation. A RunConfig can also give hints to the compiler which computational nodes are required and which are excluded.

Parameters
  • custom_sync_domains (List[SyncDomain]) – List of user-specified synchronization domains.

  • loglevel (int) – Sets level of event logging, as defined by Python’s ‘logging’ facility. Default: logging.WARNING

exclude_nodes(nodes)

Excludes given nodes from consideration by compiler.

require_nodes(nodes)

Requires that compiler maps processes to given nodes.

select(process, proc_model)
Return type

ty.Type[AbstractProcessModel]