MultiInput#

class maize.core.interface.MultiInput(*args: Any, **kwargs: Any)[source]#

Bases: MultiPort[T]

Aggregation of multiple input ports into a single port.

Index into the port to access a normal Input instance with a receive method.

Parameters:
  • timeout – Timeout used for continuously polling the connection for data on a blocking receive call.

  • optional – Whether this port is required for the process to stay alive. If the connection to an optional port is closed by a neighbouring process, the current node will not shutdown.

  • n_ports – The number of ports to instantiate, if not given will allow dynamic creation of new ports when set_channel is called

  • mode – Whether to 'link', 'move' or 'copy' (default) files.

name#

Unique port name

parent#

Parent node instance this port is part of

Raises:

PortException – If the port is used without a connected channel

Examples

>>> class Example(Node):
...     inp = MultiInput[int](n_ports=2)
...
...     def run(self):
...         a = self.inp[0].receive()
...         b = self.inp[1].receive()
__init__(timeout: float = 0.5, optional: bool = False, n_ports: int | None = None, mode: Literal['copy', 'link', 'move'] = 'copy') None#

Methods

__init__([timeout, optional, n_ports, mode])

build(name, parent)

Instantiate an interface from the description.

check(value)

Checks if a value is valid using type annotations.

close()

Closes the port.

dump()

Dump any data contained in any of the inputs.

is_connected(port)

Specifies whether the port is connected.

preload(data)

Preload the input with data, to allow resuming from a checkpoint.

set(value)

Set unconnected ports to a specified value

set_channel(channel)

Set the channel associated with the port.

Attributes

active

Specifies whether the port is active or not.

connected

Specifies whether the port is connected.

default

Provides the default value, if available

path

Provides a unique path to the interface.

serialized

Provides a serialized summary of the parameter

size

Returns the approximate number of items waiting in the channel

name

parent

datatype

doc

property active: bool#

Specifies whether the port is active or not.

build(name: str, parent: Component) _TInter#

Instantiate an interface from the description.

Parameters:
  • name – Name of the interface, will typically be the attribute name of the parent object

  • parent – Parent component instance

Returns:

Copy of the current instance, with references to the name and the parent

Return type:

_TInter

check(value: T) bool#

Checks if a value is valid using type annotations.

Parameters:

value – Value to typecheck

Returns:

True if the value is valid, False otherwise

Return type:

bool

close() None#

Closes the port.

This can be detected by neighbouring nodes waiting on the port, and subsequently cause them to shut down.

Raises:

PortException – If the port is not connected

property connected: bool#

Specifies whether the port is connected.

property default: T | None#

Provides the default value, if available

dump() list[list[T]][source]#

Dump any data contained in any of the inputs.

static is_connected(port: _PortType) TypeGuard[_PortChannel[T]]#

Specifies whether the port is connected.

property path: tuple[str, ...]#

Provides a unique path to the interface.

preload(data: list[T]) None[source]#

Preload the input with data, to allow resuming from a checkpoint.

property serialized: dict[str, Any]#

Provides a serialized summary of the parameter

set(value: T) None[source]#

Set unconnected ports to a specified value

set_channel(channel: Channel[T]) None#

Set the channel associated with the port. This needs to be called when connecting two ports together.

Parameters:

channel – An instantiated subclass of Channel

property size: int#

Returns the approximate number of items waiting in the channel