libmuscle.port module
- class libmuscle.port.Port(name: str, operator: Operator, is_vector: bool, is_connected: bool, our_ndims: int, peer_dims: List[int])[source]
Bases:
Port
Represents a gateway to the outside world.
Ports can be used to send or receive messages. They have a name and an operator, as well as a set of dimensions that determines the valid slot indices for sending or receiving on this port.
Ports keep track of the amount of messages sent or received on the port. However, the actual incrementing and validation is done in
Communicator
.- name
Name of this port.
- Type:
Identifier
- operator
Operator associated with this port.
- Type:
Operator
- get_length() int [source]
Returns the length of this port.
- Raises:
RuntimeError – If this port is a scalar port.
- get_num_messages(slot: int | None = None) int [source]
Get the amount of messages sent or received.
- Parameters:
slot – The slot that is sent/received on
- increment_num_messages(slot: int | None = None) None [source]
Increment amount of messages sent or received.
- Parameters:
slot – The slot that is sent/received on
- is_connected() bool [source]
Returns whether the port is connected to a peer.
- Returns:
True if there is a peer, False if there is not.
- is_resuming(slot: int | None = None) bool [source]
True when this port has resumed.
After resumption, each port/slot may discard exactly one message. is_resuming keeps track of this state.
- Parameters:
slot – The slot that is sent/received on
- is_vector() bool [source]
Returns whether this is a vector port.
- Returns:
True if it is vector, False if it is scalar.
- restore_message_counts(num_messages: List[int]) None [source]
Restore message counts from a snapshot
- set_length(length: int) None [source]
Sets the length of a resizable vector port.
Only call this if is_resizable() returns True.
- Parameters:
length – The new length.
- Raises:
RuntimeError – If the port is not resizable.