lava.magma.core.process.ports

lava.magma.core.process.ports.exceptions

digraph inheritance36c4df946b { bgcolor=transparent; rankdir=TB; size=""; "ConcatIndexError" [URL="../lava/lava.magma.core.process.ports.html#lava.magma.core.process.ports.exceptions.ConcatIndexError",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="Raised when the axis over which ports should be concatenated is out of"]; "ConcatShapeError" [URL="../lava/lava.magma.core.process.ports.html#lava.magma.core.process.ports.exceptions.ConcatShapeError",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="Raised when incompatible ports are tried to be concatenated."]; "DuplicateConnectionError" [URL="../lava/lava.magma.core.process.ports.html#lava.magma.core.process.ports.exceptions.DuplicateConnectionError",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="Raised when an attempt is made to create more than one connection"]; "ReshapeError" [URL="../lava/lava.magma.core.process.ports.html#lava.magma.core.process.ports.exceptions.ReshapeError",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="Raised when new port shape is incompatible with old shape."]; "TransposeIndexError" [URL="../lava/lava.magma.core.process.ports.html#lava.magma.core.process.ports.exceptions.TransposeIndexError",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="Raised when indices in transpose axes are out of bounds for the old"]; "TransposeShapeError" [URL="../lava/lava.magma.core.process.ports.html#lava.magma.core.process.ports.exceptions.TransposeShapeError",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="Raised when transpose axes is incompatible with old shape dimension."]; "VarNotSharableError" [URL="../lava/lava.magma.core.process.ports.html#lava.magma.core.process.ports.exceptions.VarNotSharableError",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="Raised when an attempt is made to connect a RefPort or VarPort to a"]; }
exception lava.magma.core.process.ports.exceptions.ConcatIndexError(shape, axis)

Bases: Exception

Raised when the axis over which ports should be concatenated is out of bounds.

exception lava.magma.core.process.ports.exceptions.ConcatShapeError(shapes, axis)

Bases: Exception

Raised when incompatible ports are tried to be concatenated.

exception lava.magma.core.process.ports.exceptions.DuplicateConnectionError

Bases: Exception

Raised when an attempt is made to create more than one connection between source and destination port.

exception lava.magma.core.process.ports.exceptions.ReshapeError(old_shape, new_shape)

Bases: Exception

Raised when new port shape is incompatible with old shape.

exception lava.magma.core.process.ports.exceptions.TransposeIndexError(old_shape, axes, wrong_index)

Bases: Exception

Raised when indices in transpose axes are out of bounds for the old shape dimension.

exception lava.magma.core.process.ports.exceptions.TransposeShapeError(old_shape, axes)

Bases: Exception

Raised when transpose axes is incompatible with old shape dimension.

exception lava.magma.core.process.ports.exceptions.VarNotSharableError(var_name)

Bases: Exception

Raised when an attempt is made to connect a RefPort or VarPort to a non-sharable Var.

lava.magma.core.process.ports.ports

digraph inheritance27303b64d6 { 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"]; "AbstractDstPort" [URL="../lava/lava.magma.core.process.ports.html#lava.magma.core.process.ports.ports.AbstractDstPort",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="Interface for destination ports such as InPorts and VarPorts in which"]; "ABC" -> "AbstractDstPort" [arrowsize=0.5,style="setlinewidth(0.5)"]; "AbstractIOPort" [URL="../lava/lava.magma.core.process.ports.html#lava.magma.core.process.ports.ports.AbstractIOPort",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 base class for InPorts and OutPorts."]; "AbstractPort" -> "AbstractIOPort" [arrowsize=0.5,style="setlinewidth(0.5)"]; "AbstractPort" [URL="../lava/lava.magma.core.process.ports.html#lava.magma.core.process.ports.ports.AbstractPort",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 base class for any type of port of a Lava Process."]; "AbstractProcessMember" -> "AbstractPort" [arrowsize=0.5,style="setlinewidth(0.5)"]; "AbstractProcessMember" [URL="../lava.magma.core.process.html#lava.magma.core.process.interfaces.AbstractProcessMember",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 member of a process has a reference to its parent process, a name"]; "ABC" -> "AbstractProcessMember" [arrowsize=0.5,style="setlinewidth(0.5)"]; "AbstractRVPort" [URL="../lava/lava.magma.core.process.ports.html#lava.magma.core.process.ports.ports.AbstractRVPort",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 base class for RefPorts and VarPorts."]; "AbstractPort" -> "AbstractRVPort" [arrowsize=0.5,style="setlinewidth(0.5)"]; "AbstractSrcPort" [URL="../lava/lava.magma.core.process.ports.html#lava.magma.core.process.ports.ports.AbstractSrcPort",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="Interface for source ports such as OutPorts and RefPorts from which"]; "ABC" -> "AbstractSrcPort" [arrowsize=0.5,style="setlinewidth(0.5)"]; "AbstractVirtualPort" [URL="../lava/lava.magma.core.process.ports.html#lava.magma.core.process.ports.ports.AbstractVirtualPort",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 base class interface for any type of port that merely serves"]; "AbstractPort" -> "AbstractVirtualPort" [arrowsize=0.5,style="setlinewidth(0.5)"]; "ConcatPort" [URL="../lava/lava.magma.core.process.ports.html#lava.magma.core.process.ports.ports.ConcatPort",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 ConcatPort is a virtual port that allows to concatenate multiple"]; "AbstractVirtualPort" -> "ConcatPort" [arrowsize=0.5,style="setlinewidth(0.5)"]; "ImplicitVarPort" [URL="../lava/lava.magma.core.process.ports.html#lava.magma.core.process.ports.ports.ImplicitVarPort",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="Sub class for VarPort to identify implicitly created VarPorts when"]; "VarPort" -> "ImplicitVarPort" [arrowsize=0.5,style="setlinewidth(0.5)"]; "InPort" [URL="../lava/lava.magma.core.process.ports.html#lava.magma.core.process.ports.ports.InPort",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="Input ports are members of a Lava Process and can be connected to"]; "AbstractIOPort" -> "InPort" [arrowsize=0.5,style="setlinewidth(0.5)"]; "AbstractDstPort" -> "InPort" [arrowsize=0.5,style="setlinewidth(0.5)"]; "OutPort" [URL="../lava/lava.magma.core.process.ports.html#lava.magma.core.process.ports.ports.OutPort",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="Output ports are members of a Lava Process and can be connected to"]; "AbstractIOPort" -> "OutPort" [arrowsize=0.5,style="setlinewidth(0.5)"]; "AbstractSrcPort" -> "OutPort" [arrowsize=0.5,style="setlinewidth(0.5)"]; "RefPort" [URL="../lava/lava.magma.core.process.ports.html#lava.magma.core.process.ports.ports.RefPort",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="RefPorts are members of a Lava Process and can be connected to"]; "AbstractRVPort" -> "RefPort" [arrowsize=0.5,style="setlinewidth(0.5)"]; "AbstractSrcPort" -> "RefPort" [arrowsize=0.5,style="setlinewidth(0.5)"]; "ReshapePort" [URL="../lava/lava.magma.core.process.ports.html#lava.magma.core.process.ports.ports.ReshapePort",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 ReshapePort is a virtual port that allows to change the shape of a"]; "AbstractVirtualPort" -> "ReshapePort" [arrowsize=0.5,style="setlinewidth(0.5)"]; "TransposePort" [URL="../lava/lava.magma.core.process.ports.html#lava.magma.core.process.ports.ports.TransposePort",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 TransposePort is a virtual port that allows to permute the dimensions"]; "AbstractVirtualPort" -> "TransposePort" [arrowsize=0.5,style="setlinewidth(0.5)"]; "VarPort" [URL="../lava/lava.magma.core.process.ports.html#lava.magma.core.process.ports.ports.VarPort",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="VarPorts are members of a Lava Process and act as a wrapper for"]; "AbstractRVPort" -> "VarPort" [arrowsize=0.5,style="setlinewidth(0.5)"]; "AbstractDstPort" -> "VarPort" [arrowsize=0.5,style="setlinewidth(0.5)"]; }
class lava.magma.core.process.ports.ports.AbstractDstPort

Bases: ABC

Interface for destination ports such as InPorts and VarPorts in which connections terminate. This class needs no implementation and only serves to establish a clear type hierarchy needed for validating connections.

class lava.magma.core.process.ports.ports.AbstractIOPort(shape)

Bases: AbstractPort

Abstract base class for InPorts and OutPorts. This class needs no implementation and only serves to establish a clear type hierarchy needed for validating connections.

class lava.magma.core.process.ports.ports.AbstractPort(shape)

Bases: AbstractProcessMember

Abstract base class for any type of port of a Lava Process.

Ports of a process can be connected to ports of other processes to enable message-based communication via channels. Sub classes of AbstractPort only facilitate connecting to other compatible ports. Message-passing itself is only handled after compilation at runtime by port implementations within the corresponding ProcessModel.

Ports are tensor-valued, have a name and a parent process. In addition, a port may have zero or more input and output connections that contain references to ports that connect to this port or that this port connects to. Port to port connections are directional and connecting ports, effectively means to associate them with each other as inputs or outputs. These connections, imply an a-cyclic graph structure that allows the compiler to infer connections between processes.

Parameters:

shape (tuple[int, ...]) – Determines the number of connections created by this port

concat_with(ports, axis)

Concatenates this port with other ports in given order along given axis by deriving and returning a new virtual ConcatPort. This implies resulting ConcatPort can only be forward connected to another port. All ports must have the same shape outside of the concatenation dimension.

Parameters:
  • ports (ty.Union["AbstractPort", ty.List["AbstractPort"]]) – Port(s) that will be concatenated after this port.

  • axis (int) – Axis/dimension along which ports are concatenated.

Return type:

ConcatPort

flatten()

Flattens this port to a (N,)-shaped port by deriving and returning a new virtual ReshapePort with a N equal to the total number of elements of this port.

Return type:

ReshapePort

get_dst_ports(_include_self=False)

Returns the list of all destination ports that this port connects to either directly or indirectly (through other ports).

Return type:

List[AbstractDstPort]

get_incoming_transform_funcs()

Returns the incoming transformation functions for all incoming connections.

Returns:

A dictionary that maps from the ID of an incoming source port to the list of transformation functions implementing the virtual ports on the way to the current port. The transformation functions in the list are sorted from source to destination port.

Return type:

dict(list(functools.partial))

get_incoming_virtual_ports()

Returns the list of all incoming virtual ports in order from source to the current port.

Returns:

The string of the tuple is the ID of the source port, the list is the list of all incoming virtual ports, sorted from source to destination port.

Return type:

tuple(str, list(AbstractVirtualPorts))

get_outgoing_transform_funcs()

Returns the outgoing transformation functions for all outgoing connections.

Returns:

A dictionary that maps from the ID of a destination port to the list of transformation functions implementing the virtual ports on the way from the current port. The transformation functions in the list are sorted from source to destination port.

Return type:

dict(list(functools.partial))

get_outgoing_virtual_ports()

Returns the list of all outgoing virtual ports in order from the current port to the destination port.

Returns:

The string of the tuple is the ID of the destination port, the list is the list of all outgoing virtual ports, sorted from source to destination port.

Return type:

tuple(str, list(AbstractVirtualPorts))

get_src_ports(_include_self=False)

Returns the list of all source ports that connect either directly or indirectly (through other ports) to this port.

Return type:

List[AbstractSrcPort]

reshape(new_shape)

Reshapes this port by deriving and returning a new virtual ReshapePort with the new shape. This implies that the resulting ReshapePort can only be forward connected to another port.

Parameters:

new_shape (tuple[int, ...]) – New shape of port. Number of total elements must not change.

Return type:

ReshapePort

transpose(axes=None)

Permutes the tensor dimension of this port by deriving and returning a new virtual TransposePort the new permuted dimension. This implies that the resulting TransposePort can only be forward connected to another port.

Parameters:

axes (ty.Optional[ty.Union[ty.Tuple[int, ...], ty.List]]) – Order of permutation. Number of total elements and number of dimensions must not change.

Return type:

TransposePort

class lava.magma.core.process.ports.ports.AbstractRVPort(shape)

Bases: AbstractPort

Abstract base class for RefPorts and VarPorts. This class needs no implementation and only serves to establish a clear type hierarchy needed for validating connections.

class lava.magma.core.process.ports.ports.AbstractSrcPort

Bases: ABC

Interface for source ports such as OutPorts and RefPorts from which connections originate. This class needs no implementation and only serves to establish a clear type hierarchy needed for validating connections.

class lava.magma.core.process.ports.ports.AbstractVirtualPort(shape)

Bases: AbstractPort

Abstract base class interface for any type of port that merely serves to transform the properties of a user-defined port.

connect(ports, connection_configs=None)

Connects this virtual port to other port(s).

Parameters:
  • ports (ty.Union["AbstractPort", ty.List["AbstractPort"]]) – The port(s) to connect to. Connections from an IOPort to a RVPort and vice versa are not allowed.

  • connection_configs (ConnectionConfigs) – Configuration for this connection. See “ConnectionConfig” class.

abstract get_transform_func_bwd()

Returns a function pointer that implements the backward (bwd) transformation of the virtual port.

Returns:

function_pointer – a function pointer that can be applied to incoming data

Return type:

functools.partial

abstract get_transform_func_fwd()

Returns a function pointer that implements the forward (fwd) transformation of the virtual port.

Returns:

function_pointer – a function pointer that can be applied to incoming data

Return type:

functools.partial

property process

Returns parent process of parent port that this VirtualPort was derived from.

class lava.magma.core.process.ports.ports.ConcatPort(ports, axis)

Bases: AbstractVirtualPort

A ConcatPort is a virtual port that allows to concatenate multiple ports along given axis into a new port before connecting to another port. The shape of all concatenated ports outside of the concatenation dimension must be the same. It is used by the compiler to map the indices of the underlying tensor-valued data array from the derived to the new shape.

get_transform_func_bwd()

Returns a function pointer that implements the backward (bwd) transformation of the virtual port.

Returns:

function_pointer – a function pointer that can be applied to incoming data

Return type:

functools.partial

get_transform_func_fwd()

Returns a function pointer that implements the forward (fwd) transformation of the virtual port.

Returns:

function_pointer – a function pointer that can be applied to incoming data

Return type:

functools.partial

class lava.magma.core.process.ports.ports.ImplicitVarPort(var)

Bases: VarPort

Sub class for VarPort to identify implicitly created VarPorts when a RefPort connects directly to a Var.

class lava.magma.core.process.ports.ports.InPort(shape, reduce_op=None)

Bases: AbstractIOPort, AbstractDstPort

Input ports are members of a Lava Process and can be connected to other ports to facilitate receiving of messages via channels.

InPorts can receive connections from other OutPorts of peer processes or from other InPorts of processes that contain this InPort’s parent process as a sub process. Similarly, InPorts can connect to other InPorts of nested sub processes.

Parameters:
  • shape (tuple[int, ...]) – Determines the number of connections created by this port.

  • reduce_op (ty.Optional[ty.Type[AbstractReduceOp]]) – Operation to be applied on incoming data, default: None.

connect(ports, connection_configs=None)

Connects this InPort to other InPort(s) of a nested process. InPorts cannot connect to other OutPorts.

Parameters:
  • ports (ty.Union["InPort", ty.List["InPort"]]) – The InPort(s) to connect to.

  • connection_configs (ConnectionConfigs) – Configuration for this connection. See “ConnectionConfig” class.

connect_from(ports, connection_configs=None)

Connects other OutPort(s) to this InPort or connects other InPort(s) of parent process to this InPort.

Parameters:
  • ports (ty.Union["AbstractIOPort", ty.List["AbstractIOPort"]]) – The AbstractIOPort(s) that connect to this InPort.

  • connection_configs (ConnectionConfigs) – Configuration for this connection. See “ConnectionConfig” class.

class lava.magma.core.process.ports.ports.OutPort(shape)

Bases: AbstractIOPort, AbstractSrcPort

Output ports are members of a Lava Process and can be connected to other ports to facilitate sending of messages via channels.

OutPorts connect to other InPorts of peer processes or to other OutPorts of processes that contain this OutPort’s parent process as a sub process. Similarly, OutPorts can receive connections from other OutPorts of nested sub processes.

connect(ports, connection_configs=None)

Connects this OutPort to other InPort(s) of another process or to OutPort(s) of its parent process.

Parameters:
  • ports (ty.Union["AbstractIOPort", ty.List["AbstractIOPort"]]) – The AbstractIOPort(s) to connect to.

  • connection_configs (ConnectionConfigs) – Configuration for this connection. See “ConnectionConfig” class.

connect_from(ports, connection_configs=None)

Connects other OutPort(s) of a nested process to this OutPort. OutPorts cannot receive connections from other InPorts.

Parameters:
  • ports (ty.Union["OutPort", ty.List["OutPort"]]) – The OutPorts(s) that connect to this OutPort.

  • connection_configs (ConnectionConfigs) – Configuration for this connection. See “ConnectionConfig” class.

class lava.magma.core.process.ports.ports.RefPort(shape)

Bases: AbstractRVPort, AbstractSrcPort

RefPorts are members of a Lava Process and can be connected to internal Lava Vars of other processes to facilitate direct shared memory access to those processes.

Shared-memory-based communication can have side-effects and should therefore be used with caution.

RefPorts connect to other VarPorts of peer processes or to other RefPorts of processes that contain this RefPort’s parent process as a sub process via the connect(..) method.. Similarly, RefPorts can receive connections from other RefPorts of nested sub processes via the connect_from(..) method.

Here, VarPorts only serve as a wrapper for Vars. VarPorts can be created statically during process definition to explicitly expose a Var for remote memory access (which might be safer). Alternatively, VarPorts can be created dynamically by connecting a RefPort to a Var via the connect_var(..) method.

connect(ports, connection_configs=None)

Connects this RefPort to other VarPort(s) of another process or to RefPort(s) of its parent process.

Parameters:
  • ports (ty.Union["AbstractRVPort", ty.List["AbstractRVPort"]]) – The AbstractRVPort(s) to connect to.

  • connection_configs (ConnectionConfigs) – Configuration for this connection. See “ConnectionConfig” class.

connect_from(ports, connection_configs=None)

Connects other RefPort(s) of a nested process to this RefPort. RefPorts cannot receive connections from other VarPorts.

Parameters:
  • ports (ty.Union["RefPort", ty.List["RefPort"]]) – The RefPort(s) that connect to this RefPort.

  • connection_configs (ConnectionConfigs) – Configuration for this connection. See “ConnectionConfig” class.

connect_var(variables, connection_configs=None)

Connects this RefPort to Lava Process Var(s) to facilitate shared memory access.

Parameters:
  • variables (ty.Union[Var, ty.List[Var]]) – Var or list of Vars to connect to.

  • connection_configs (ConnectionConfigs) – Configuration for this connection. See “ConnectionConfig” class.

static create_implicit_var_port(var)

Creates and returns an ImplicitVarPort for the given Var.

Return type:

ImplicitVarPort

get_dst_vars()

Returns destination Vars this RefPort is connected to.

Return type:

List[Var]

class lava.magma.core.process.ports.ports.ReshapePort(new_shape, old_shape)

Bases: AbstractVirtualPort

A ReshapePort is a virtual port that allows to change the shape of a port before connecting to another port. It is used by the compiler to map the indices of the underlying tensor-valued data array from the derived to the new shape.

get_transform_func_bwd()

Returns a function pointer that implements the backward (bwd) transformation of the ReshapePort, which reshapes incoming data to a new shape (the shape of the source Process).

Returns:

function_pointer – a function pointer that can be applied to incoming data

Return type:

functools.partial

get_transform_func_fwd()

Returns a function pointer that implements the forward (fwd) transformation of the ReshapePort, which reshapes incoming data to a new shape (the shape of the destination Process).

Returns:

function_pointer – a function pointer that can be applied to incoming data

Return type:

functools.partial

class lava.magma.core.process.ports.ports.TransposePort(new_shape, axes)

Bases: AbstractVirtualPort

A TransposePort is a virtual port that allows to permute the dimensions of a port before connecting to another port. It is used by the compiler to map the indices of the underlying tensor-valued data array from the derived to the new shape.

Example

out_port = OutPort((2, 4, 3)) in_port = InPort((3, 2, 4)) out_port.transpose([3, 1, 2]).connect(in_port)

get_transform_func_bwd()

Returns a function pointer that implements the backward (bwd) transformation of the TransposePort, which transposes (permutes) incoming data according to a specific order of axes (to match the source Process).

Returns:

function_pointer – a function pointer that can be applied to incoming data

Return type:

functools.partial

get_transform_func_fwd()

Returns a function pointer that implements the forward (fwd) transformation of the TransposePort, which transposes (permutes) incoming data according to a specific order of axes (to match the destination Process).

Returns:

function_pointer – a function pointer that can be applied to incoming data

Return type:

functools.partial

class lava.magma.core.process.ports.ports.VarPort(var)

Bases: AbstractRVPort, AbstractDstPort

VarPorts are members of a Lava Process and act as a wrapper for internal Lava Vars to facilitate connections between RefPorts and Vars for shared memory access from the parent process of the RefPort to the parent process of the Var.

Shared-memory-based communication can have side-effects and should therefore be used with caution.

VarPorts can receive connections from other RefPorts of peer processes or from other VarPorts of processes that contain this VarPort’s parent process as a sub process via the connect(..) method. Similarly, VarPorts can connect to other VarPorts of nested sub processes via the connect_from(..) method.

VarPorts can either be created in the constructor of a Process to explicitly expose a Var for shared memory access (which might be safer). Alternatively, VarPorts can be created dynamically by connecting a RefPort to a Var via the RefPort.connect_var(..) method.

connect(ports, connection_configs=None)

Connects this VarPort to other VarPort(s) of a nested process. VarPorts cannot connect to other RefPorts.

Parameters:
  • ports (ty.Union["VarPort", ty.List["VarPort"]]) – The VarPort(s) to connect to.

  • connection_configs (ConnectionConfigs) – Configuration for this connection. See “ConnectionConfig” class.

connect_from(ports, connection_configs=None)

Connects other RefPort(s) to this VarPort or connects other VarPort(s) of parent process to this VarPort.

Parameters:
  • ports (ty.Union["AbstractRVPort", ty.List["AbstractRVPort"]]) – The AbstractRVPort(s) that connect to this VarPort.

  • connection_configs (ConnectionConfigs) – Configuration for this connection. See “ConnectionConfig” class.

lava.magma.core.process.ports.ports.create_port_id(proc_id, port_name)

Generates a string-based ID for a port that makes it identifiable within a network of Processes.

Parameters:
  • proc_id (int) – ID of the Process that the Port is associated with

  • port_name (str) – name of the Port

Returns:

port_id – ID of a port

Return type:

str

lava.magma.core.process.ports.ports.is_disjoint(a, b)

Checks that both lists are disjoint.

lava.magma.core.process.ports.ports.to_list(obj)

If ‘obj’ is not a list, converts ‘obj’ into [obj].

Return type:

List[Any]

lava.magma.core.process.ports.reduce_ops

digraph inheritance87647c58ab { 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"]; "AbstractReduceOp" [URL="../lava/lava.magma.core.process.ports.html#lava.magma.core.process.ports.reduce_ops.AbstractReduceOp",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="Reduce operations are required by InPorts to specify how date from"]; "ABC" -> "AbstractReduceOp" [arrowsize=0.5,style="setlinewidth(0.5)"]; "ReduceSum" [URL="../lava/lava.magma.core.process.ports.html#lava.magma.core.process.ports.reduce_ops.ReduceSum",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="ReduceOp to indicate that multiple inputs to same InPort should be"]; "AbstractReduceOp" -> "ReduceSum" [arrowsize=0.5,style="setlinewidth(0.5)"]; }
class lava.magma.core.process.ports.reduce_ops.AbstractReduceOp

Bases: ABC

Reduce operations are required by InPorts to specify how date from multiple OutPorts connected to the same InPorts gets integrated.

class lava.magma.core.process.ports.reduce_ops.ReduceSum

Bases: AbstractReduceOp

ReduceOp to indicate that multiple inputs to same InPort should be added.