lava.magma.compiler.builders

lava.magma.compiler.builders.channel_builder

digraph inheritance9ce7e3ddc7 { 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"]; "AbstractChannelBuilder" [URL="../lava/lava.magma.compiler.builders.html#lava.magma.compiler.builders.interfaces.AbstractChannelBuilder",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 AbstractChannelBuilder is the base type for"]; "ABC" -> "AbstractChannelBuilder" [arrowsize=0.5,style="setlinewidth(0.5)"]; "ChannelBuilderMp" [URL="../lava/lava.magma.compiler.builders.html#lava.magma.compiler.builders.channel_builder.ChannelBuilderMp",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="A ChannelBuilder assuming Python multi-processing is used as messaging"]; "AbstractChannelBuilder" -> "ChannelBuilderMp" [arrowsize=0.5,style="setlinewidth(0.5)"]; "WatchdogEnabledMixin" -> "ChannelBuilderMp" [arrowsize=0.5,style="setlinewidth(0.5)"]; "ChannelBuilderNx" [URL="../lava/lava.magma.compiler.builders.html#lava.magma.compiler.builders.channel_builder.ChannelBuilderNx",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="A ChannelBuilder for CNc and NcC Channels with NxBoard as"]; "AbstractChannelBuilder" -> "ChannelBuilderNx" [arrowsize=0.5,style="setlinewidth(0.5)"]; "ChannelBuilderPyNc" [URL="../lava/lava.magma.compiler.builders.html#lava.magma.compiler.builders.channel_builder.ChannelBuilderPyNc",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="A ChannelBuilder for PyNc and NcPy Channels with NxBoard as the messaging"]; "ChannelBuilderNx" -> "ChannelBuilderPyNc" [arrowsize=0.5,style="setlinewidth(0.5)"]; "RuntimeChannelBuilderMp" [URL="../lava/lava.magma.compiler.builders.html#lava.magma.compiler.builders.channel_builder.RuntimeChannelBuilderMp",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="A RuntimeChannelBuilder assuming Python multi-processing is"]; "AbstractChannelBuilder" -> "RuntimeChannelBuilderMp" [arrowsize=0.5,style="setlinewidth(0.5)"]; "WatchdogEnabledMixin" -> "RuntimeChannelBuilderMp" [arrowsize=0.5,style="setlinewidth(0.5)"]; "ServiceChannelBuilderMp" [URL="../lava/lava.magma.compiler.builders.html#lava.magma.compiler.builders.channel_builder.ServiceChannelBuilderMp",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="A RuntimeServiceChannelBuilder assuming Python multi-processing is used"]; "AbstractChannelBuilder" -> "ServiceChannelBuilderMp" [arrowsize=0.5,style="setlinewidth(0.5)"]; "WatchdogEnabledMixin" -> "ServiceChannelBuilderMp" [arrowsize=0.5,style="setlinewidth(0.5)"]; "WatchdogEnabledMixin" [URL="../lava/lava.magma.compiler.builders.html#lava.magma.compiler.builders.channel_builder.WatchdogEnabledMixin",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"]; }
class lava.magma.compiler.builders.channel_builder.ChannelBuilderMp(channel_type, src_process, dst_process, src_port_initializer, dst_port_initializer)

Bases: AbstractChannelBuilder, WatchdogEnabledMixin

A ChannelBuilder assuming Python multi-processing is used as messaging and multi processing backbone.

build(messaging_infrastructure, watchdog_manager)

Given the message passing framework builds a channel

Parameters:
Returns:

Channel

Return type:

Channel

Raises:

Exception – Can’t build channel of type specified

channel_type: ChannelType
dst_port_initializer: PortInitializer
dst_process: AbstractProcess
src_port_initializer: PortInitializer
src_process: AbstractProcess
class lava.magma.compiler.builders.channel_builder.ChannelBuilderNx(channel_type, src_process, dst_process, src_port_initializer, dst_port_initializer)

Bases: AbstractChannelBuilder

A ChannelBuilder for CNc and NcC Channels with NxBoard as the messaging infrastructure.

build(messaging_infrastructure)

Given the message passing framework builds a channel

Parameters:

messaging_infrastructure (MessageInfrastructureInterface) –

Returns:

Channel

Return type:

Channel

Raises:

Exception – Can’t build channel of type specified

channel_type: ChannelType
dst_port_initializer: PortInitializer
dst_process: AbstractProcess
src_port_initializer: PortInitializer
src_process: AbstractProcess
class lava.magma.compiler.builders.channel_builder.ChannelBuilderPyNc(channel_type, src_process, dst_process, src_port_initializer, dst_port_initializer)

Bases: ChannelBuilderNx

A ChannelBuilder for PyNc and NcPy Channels with NxBoard as the messaging infrastructure.

build(messaging_infrastructure)

Given the message passing framework builds a channel

Parameters:

messaging_infrastructure (MessageInfrastructureInterface) –

Returns:

Channel

Return type:

Channel

Raises:

Exception – Can’t build channel of type specified

class lava.magma.compiler.builders.channel_builder.RuntimeChannelBuilderMp(channel_type, src_process, dst_process, port_initializer)

Bases: AbstractChannelBuilder, WatchdogEnabledMixin

A RuntimeChannelBuilder assuming Python multi-processing is used as messaging and multi processing backbone.

build(messaging_infrastructure, watchdog_manager)

Given the message passing framework builds a channel

Parameters:
Returns:

PyPyChannel

Return type:

Channel

Raises:

Exception – Can’t build channel of type specified

channel_type: ChannelType
dst_process: Union[RuntimeServiceBuilder, Type[Runtime]]
port_initializer: PortInitializer
src_process: Union[RuntimeServiceBuilder, Type[Runtime]]
class lava.magma.compiler.builders.channel_builder.ServiceChannelBuilderMp(channel_type, src_process, dst_process, port_initializer)

Bases: AbstractChannelBuilder, WatchdogEnabledMixin

A RuntimeServiceChannelBuilder assuming Python multi-processing is used as messaging and multi processing backbone.

build(messaging_infrastructure, watchdog_manager)

Given the message passing framework builds a channel

Parameters:
Returns:

PyPyChannel

Return type:

Channel

Raises:

Exception – Can’t build channel of type specified

channel_type: ChannelType
dst_process: Union[RuntimeServiceBuilder, Type[AbstractProcessModel]]
port_initializer: PortInitializer
src_process: Union[RuntimeServiceBuilder, Type[AbstractProcessModel]]
class lava.magma.compiler.builders.channel_builder.WatchdogEnabledMixin

Bases: object

JOIN = 'join'
RECV = 'recv'
SEND = 'send'
create_watchdogs(watchdog_manager, queues, port_initializers)
Return type:

Tuple[Watchdog, Watchdog, Watchdog, Watchdog]

static watch(watchdog_manager, queue, process, other_process, pi, other_pi, method_type)
Return type:

Watchdog

lava.magma.compiler.builders.interfaces

digraph inheritanced53729e869 { 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"]; "AbstractBuilder" [URL="../lava/lava.magma.compiler.builders.html#lava.magma.compiler.builders.interfaces.AbstractBuilder",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="Builders interface for building processes in a given backend."]; "ABC" -> "AbstractBuilder" [arrowsize=0.5,style="setlinewidth(0.5)"]; "AbstractChannelBuilder" [URL="../lava/lava.magma.compiler.builders.html#lava.magma.compiler.builders.interfaces.AbstractChannelBuilder",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 AbstractChannelBuilder is the base type for"]; "ABC" -> "AbstractChannelBuilder" [arrowsize=0.5,style="setlinewidth(0.5)"]; "AbstractProcessBuilder" [URL="../lava/lava.magma.compiler.builders.html#lava.magma.compiler.builders.interfaces.AbstractProcessBuilder",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 AbstractProcessBuilder is the base type for process builders."]; "AbstractBuilder" -> "AbstractProcessBuilder" [arrowsize=0.5,style="setlinewidth(0.5)"]; "CompiledResource" [URL="../lava/lava.magma.compiler.builders.html#lava.magma.compiler.builders.interfaces.CompiledResource",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="Signifies a compiled resource held by the builder. Must be"]; "Resource" -> "CompiledResource" [arrowsize=0.5,style="setlinewidth(0.5)"]; "MappedResource" [URL="../lava/lava.magma.compiler.builders.html#lava.magma.compiler.builders.interfaces.MappedResource",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="Signifies a physical resource held by the builder."]; "Resource" -> "MappedResource" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Resource" [URL="../lava/lava.magma.compiler.builders.html#lava.magma.compiler.builders.interfaces.Resource",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"]; "ABC" -> "Resource" [arrowsize=0.5,style="setlinewidth(0.5)"]; "ResourceAddress" [URL="../lava/lava.magma.compiler.builders.html#lava.magma.compiler.builders.interfaces.ResourceAddress",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"]; "ABC" -> "ResourceAddress" [arrowsize=0.5,style="setlinewidth(0.5)"]; }
class lava.magma.compiler.builders.interfaces.AbstractBuilder

Bases: ABC

Builders interface for building processes in a given backend.

abstract build()

Build the actual process.

class lava.magma.compiler.builders.interfaces.AbstractChannelBuilder

Bases: ABC

An AbstractChannelBuilder is the base type for channel builders which build communication channels between services and processes

class lava.magma.compiler.builders.interfaces.AbstractProcessBuilder(proc_model, model_id)

Bases: AbstractBuilder

An AbstractProcessBuilder is the base type for process builders.

Process builders instantiate and initialize a ProcessModel.

Parameters:
  • proc_model (AbstractProcessModel) – ProcessModel class of the process to build.

  • model_id (int) – model_id represents the ProcessModel ID to build.

property proc_model: Type[AbstractProcessModel]
set_variables(variables)
Appends the given list of variables to the ProcessModel. Used by the

compiler to create a ProcessBuilder during the compilation of ProcessModels.

Parameters:

variables (ty.List[VarInitializer]) –

class lava.magma.compiler.builders.interfaces.CompiledResource

Bases: Resource

Signifies a compiled resource held by the builder. Must be serializable if the builder is being serialized after compilation before mapping

property l_address: ResourceAddress

Return the logical address of this compiled resource.

class lava.magma.compiler.builders.interfaces.MappedResource

Bases: Resource

Signifies a physical resource held by the builder. Must be serializable.

abstract property p_address: ResourceAddress

Return the physical address of this mapped resource.

class lava.magma.compiler.builders.interfaces.Resource

Bases: ABC

write(hw)

Given hw, write this compiled resource

class lava.magma.compiler.builders.interfaces.ResourceAddress

Bases: ABC

lava.magma.compiler.builders.py_builder

digraph inheritance1bdf490911 { 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"]; "AbstractBuilder" [URL="../lava/lava.magma.compiler.builders.html#lava.magma.compiler.builders.interfaces.AbstractBuilder",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="Builders interface for building processes in a given backend."]; "ABC" -> "AbstractBuilder" [arrowsize=0.5,style="setlinewidth(0.5)"]; "AbstractProcessBuilder" [URL="../lava/lava.magma.compiler.builders.html#lava.magma.compiler.builders.interfaces.AbstractProcessBuilder",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 AbstractProcessBuilder is the base type for process builders."]; "AbstractBuilder" -> "AbstractProcessBuilder" [arrowsize=0.5,style="setlinewidth(0.5)"]; "PyProcessBuilder" [URL="../lava/lava.magma.compiler.builders.html#lava.magma.compiler.builders.py_builder.PyProcessBuilder",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="A PyProcessBuilder instantiates and initializes a PyProcessModel."]; "AbstractProcessBuilder" -> "PyProcessBuilder" [arrowsize=0.5,style="setlinewidth(0.5)"]; }
class lava.magma.compiler.builders.py_builder.PyProcessBuilder(proc_model, model_id, proc_params=None)

Bases: AbstractProcessBuilder

A PyProcessBuilder instantiates and initializes a PyProcessModel.

The compiler creates a PyProcessBuilder for each PyProcessModel. In turn, the runtime, loads a PyProcessBuilder onto a compute node where it builds the PyProcessModel and its associated ports.

In order to build the PyProcessModel, the builder inspects all LavaType class variables of a PyProcessModel, creates the corresponding data type with the specified properties, the shape and the initial value provided by the Lava Var. In addition, the builder creates the required PyPort instances. Finally, the builder assigns both port and variable implementations to the PyProcModel.

Once the PyProcessModel is built, it is the RuntimeService’s job to connect channels to ports and start the process.

Note: For unit testing it should be possible to build processes locally instead of on a remote node. For pure atomic unit testing a ProcessModel locally, PyInPorts and PyOutPorts must be fed manually with data.

add_csp_port_mapping(py_port_id, csp_port)

Appends a mapping from a PyPort ID to a CSP port. This is used to associate a CSP port in a PyPort with transformation functions that implement the behavior of virtual ports.

Parameters:
  • py_port_id (str) – ID of the PyPort that contains the CSP on the other side of the channel of ‘csp_port’

  • csp_port (AbstractCspPort) – a CSP port

build()

Builds a PyProcModel at runtime within Runtime.

The Compiler initializes the PyProcBuilder with the ProcModel, VarInitializers and PortInitializers. The Runtime builds the channels and CSP ports between all ports, assigns them to builder.

At deployment to a node, the Builder.build(..) gets executed resulting in the following:

  1. ProcModel gets instantiated

  2. Vars are initialized and assigned to ProcModel

  3. PyPorts are initialized (with CSP ports) and assigned to ProcModel

Return type:

AbstractPyProcessModel

Raises:

NotImplementedError

check_all_vars_and_ports_set()

Checks that Vars and PyPorts assigned from Process have a corresponding LavaPyType.

Raises:

AssertionError – No LavaPyType found in ProcModel

check_lava_py_types()

Checks correctness of LavaPyTypes.

Any Py{In/Out/Ref}Ports must be strict sub-types of Py{In/Out/Ref}Ports.

set_csp_ports(csp_ports)

Appends the given list of CspPorts to the ProcessModel. Used by the runtime to configure csp ports during initialization (_build_channels).

Parameters:

csp_ports (ty.List[AbstractCspPort]) –

Raises:

AssertionError – PyProcessModel has no port of that name

set_py_ports(py_ports, check=True)
Appends the given list of PyPorts to the ProcessModel. Used by the

compiler to create a ProcessBuilder during the compilation of ProcessModels.

Parameters:
  • py_ports (ty.List[PortInitializer]) –

  • check (bool, optional) – , by default True

set_ref_ports(ref_ports)
Appends the given list of RefPorts to the ProcessModel. Used by the

compiler to create a ProcessBuilder during the compilation of ProcessModels.

Parameters:

ref_ports (ty.List[PortInitializer]) –

set_rs_csp_ports(csp_ports)

Set RS CSP Ports

Parameters:

csp_ports (ty.List[AbstractCspPort]) –

set_var_ports(var_ports)
Appends the given list of VarPorts to the ProcessModel. Used by the

compiler to create a ProcessBuilder during the compilation of ProcessModels.

Parameters:

var_ports (ty.List[VarPortInitializer]) –

lava.magma.compiler.builders.runtimeservice_builder

digraph inheritance32e2c74b1d { bgcolor=transparent; rankdir=TB; size=""; "NxSdkRuntimeService" [URL="../lava/lava.magma.compiler.builders.html#lava.magma.compiler.builders.runtimeservice_builder.NxSdkRuntimeService",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"]; "RuntimeServiceBuilder" [URL="../lava/lava.magma.compiler.builders.html#lava.magma.compiler.builders.runtimeservice_builder.RuntimeServiceBuilder",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="RuntimeService builders instantiate and initialize a RuntimeService."]; }
class lava.magma.compiler.builders.runtimeservice_builder.NxSdkRuntimeService

Bases: object

class lava.magma.compiler.builders.runtimeservice_builder.RuntimeServiceBuilder(rs_class, protocol, runtime_service_id, model_ids, loihi_version, loglevel=30, compile_config=None, *args, **kwargs)

Bases: object

RuntimeService builders instantiate and initialize a RuntimeService.

Parameters:
  • rs_class (AbstractRuntimeService class of the runtime service to build.) –

  • sync_protocol (AbstractSyncProtocol Synchronizer class that) – implements a protocol in a domain.

build()

Build the runtime service

Return type:

AbstractRuntimeService

Returns:

  • A concreate instance of AbstractRuntimeService

  • [PyRuntimeService or NxSdkRuntimeService]

property runtime_service_id

Return runtime service id.

set_csp_ports(csp_ports)

Set CSP Ports

Parameters:

csp_ports (ty.List[AbstractCspPort]) –

set_csp_proc_ports(csp_ports)

Set CSP Process Ports

Parameters:

csp_ports (ty.List[AbstractCspPort]) –