libmuscle.mmp_client module

class libmuscle.mmp_client.MMPClient(instance_id: Reference, location: str)[source]

Bases: object

The client for the MUSCLE Manager Protocol.

This class connects to the Manager and communicates with it on behalf of the rest of libmuscle.

It manages the connection, and converts between our native types and the gRPC generated types.

Communication is protected by an internal lock, so this class can be called simultaneously from different threads.

close() None[source]

Close the connection

This closes the connection. After this no other member functions can be called.

deregister_instance() None[source]

Deregister a component instance with the manager.

get_checkpoint_info() Tuple[float, Checkpoints, Path | None, Path | None][source]

Get the checkpoint info from the manager.

Returns:

current elapsed time checkpoints: checkpoint configuration resume: path to the resume snapshot snapshot_directory: path to store snapshots

Return type:

elapsed_time

get_settings() Settings[source]

Get the central settings from the manager.

Returns:

The requested settings.

register_instance(locations: List[str], ports: List[Port]) None[source]

Register a component instance with the manager.

Parameters:
  • locations – List of places where the instance can be reached.

  • ports – List of ports of this instance.

request_peers() Tuple[List[Conduit], Dict[Reference, List[int]], Dict[Reference, List[str]]][source]

Request connection information about peers.

This will repeat the request at an exponentially increasing query interval at first, until it reaches the interval specified by PEER_INTERVAL_MIN and PEER_INTERVAL_MAX. From there on, intervals are drawn randomly from that range.

Returns:

A tuple containing a list of conduits that this instance is attached to, a dictionary of peer dimensions, which is indexed by Reference to the peer kernel, and specifies how many instances of that kernel there are, and a dictionary of peer instance locations, indexed by Reference to a peer instance, and containing for each peer instance a list of network location strings at which it can be reached.

submit_log_message(message: LogMessage) None[source]

Send a log message to the manager.

Parameters:

message – The message to send.

submit_profile_events(events: Iterable[ProfileEvent]) None[source]

Sends profiling events to the manager.

Parameters:

events – The events to send.

submit_snapshot_metadata(snapshot_metadata: SnapshotMetadata) None[source]

Send snapshot metadata to the manager.

Parameters:

snapshot_metadata – Snapshot metadata to supply to the manager.

libmuscle.mmp_client.decode_checkpoint_info(elapsed_time: float, checkpoints_dict: Dict[str, Any], resume: str | None, snapshot_dir: str | None) Tuple[float, Checkpoints, Path | None, Path | None][source]

Decode checkpoint info from a MsgPack-compatible value.

Parameters:
  • elapsed_time – current elapsed time according to the manager

  • checkpoints_dict – checkpoint definitions from the MsgPack

  • resume – path to the snapshot we should resume from, if any

  • snapshot_dir – path to the directory to store new snapshots in

Returns:

current elapsed time according to the manager checkpoints: checkpoint configuration resume: path to the snapshot we should resume from, if any snapshot_dir: path to the directory to store new snapshots in

Return type:

elapsed_time

libmuscle.mmp_client.decode_checkpoint_rule(rule: Dict[str, Any]) CheckpointRule[source]

Decode a checkpoint rule from a MsgPack-compatible value.

libmuscle.mmp_client.encode_operator(op: Operator) str[source]

Convert an Operator to a MsgPack-compatible value.

libmuscle.mmp_client.encode_port(port: Port) List[str][source]

Convert a Port to a MsgPack-compatible value.

libmuscle.mmp_client.encode_profile_event(event: ProfileEvent) Any[source]

Converts a ProfileEvent to a list.

Parameters:

event – A profile event

Returns:

A list with its attributes, for MMP serialisation.