libmuscle.communicator module

class libmuscle.communicator.Communicator(kernel: Reference, index: List[int], port_manager: PortManager, profiler: Profiler)[source]

Bases: object

Communication engine for MUSCLE3.

This class is the mailroom for a kernel that uses MUSCLE3. It manages the sending and receiving of messages, although it leaves the actual data transmission to various protocol-specific servers and clients.

get_locations() List[str][source]

Returns a list of locations that we can be reached at.

These locations are of the form ‘protocol:location’, where the protocol name does not contain a colon and location may be an arbitrary string.

Returns:

A list of strings describing network locations.

receive_message(port_name: str, slot: int | None = None) Tuple[Message, float][source]

Receive a message and attached settings overlay.

Receiving is a blocking operation. This function will contact the sender, wait for a message to be available, and receive and return it.

If the port is not connected, then the default value will be returned if one was given, exactly as it was given. If no default was given then a RuntimeError will be raised.

Parameters:
  • port_name – The endpoint on which a message is to be received.

  • slot – The slot to receive the message on, if any.

Returns:

The received message, with message.settings holding the settings overlay. The settings attribute is guaranteed to not be None. Secondly, the saved_until metadata field from the received message.

Raises:

RuntimeError – If the network connection had an error, or the message number was incorrect.

send_message(port_name: str, message: Message, slot: int | None = None, checkpoints_considered_until: float = -inf) None[source]

Send a message and settings to the outside world.

Sending is non-blocking, a copy of the message will be made and stored until the receiver is ready to receive it.

Parameters:
  • port_name – The port on which this message is to be sent.

  • message – The message to be sent.

  • slot – The slot to send the message on, if any.

  • checkpoints_considered_until – When we last checked if we should save a snapshot (wallclock time).

set_peer_info(peer_info: PeerInfo) None[source]

Inform this Communicator about its peers.

This tells the Communicator about its peers, so that it can route messages accordingly.

Parameters:

peer_info – Information about the peers.

shutdown() None[source]

Shuts down the Communicator, closing connections.

class libmuscle.communicator.Message(timestamp: float, next_timestamp: float | None = None, data: Any | None = None, settings: Settings | None = None)[source]

Bases: object

A message to be sent or received.

This class describes a message to be sent or that has been received.

timestamp

Simulation time for which this data is valid.

Type:

float

next_timestamp

Simulation time for the next message to be transmitted through this port.

Type:

Optional[float]

data

An object to send or that was received.

Type:

MessageObject

settings

Overlay settings to send or that was received.

Type:

Settings