libmuscle.manager.hammer module
- libmuscle.manager.hammer.Node
Describes a model to be processed while flattening.
This contains a model, its component path from the root, and a multiplicity. Components inside of the model will be prefixed with the path and multiplicity before being added to the flattened model.
- class libmuscle.manager.hammer.Plate[source]
Bases:
objectContainer for conduits during flattening.
Models may have conduits to or from model-implemented components, and to or from model ports. In the flattened model, these components and ports are removed, and the conduits on either side merged into each other, possibly connecting together many conduits into a single one. The flattening algorithm does this step by step, so that during flattening there is a pile of partially-finished conduits lying around that we’re working on.
This class provides a place to keep those conduits while allowing the access operations we need. Why Plate? Because that’s where the spaghetti goes.
Fundamentally, this stores Conduit objects, using two indexes. One maps each sending endpoint to a dict keyed by receiving endpoint that in turn maps to the Conduit object and a bool indicating whether that receiving endpoint is on a program-implemented conduit and therefore final. The other one does the same, but the other way around, and the bool referring to the sending endpoint.
- add(conduit: Conduit, snd_final: bool, recv_final: bool) None[source]
Add a conduit to the plate.
- Parameters:
conduit – The Conduit to add
snd_final – True iff the sender is final (a program port)
recv_final – True iff the receiver is final (a program port)
- pop_by_receiver(receiver: Reference) dict[Reference, tuple[Conduit, bool]][source]
Remove and return all conduits with the given receiver.
- Parameters:
receiver – The receiver to search for
- Returns:
A dictionary keyed by sender, mapping to a Conduit with that sender and the requested receiver, and a boolean indicating whether that sender is final.
- pop_by_sender(sender: Reference) dict[Reference, tuple[Conduit, bool]][source]
Remove and return all conduits with the given sender.
- Parameters:
sender – The sender to search for
- Returns:
A dictionary keyed by receiver, mapping to a Conduit with that receiver and the requested sender, and a boolean indicating whether that receiver is final.
- libmuscle.manager.hammer.flatten(nested_config: Configuration, model: Reference | None = None) Configuration[source]
Creates a flat version of the given configuration.
The result will have a single model, without any components that have a model for their implementation, or that do not have an implementation, and with the remaining components with their full name (path from the root model). Conduits will be merged and removed accordingly, and custom implementations applied.
This does a breadth-first traverse through model-implemented components, starting from the root model and a virtual component with an empty name and multiplicity. As it recurses downward, it accumulates component names and multiplicities.
Program-implemented components inside of the processed model-implemented components have their names and implementations prefixed with those of the parent component, and conduits between them have their endpoints updated accordingly. Finally, components leading into and out of submodels are glued together and added as well.
- Parameters:
nested_configuration – A complete, consistent, (potentially) nested configuration.
model – Root model to start from
- Returns:
A copy of that configuration, modified to contain only a single flat model corresponding to the input, with no custom_implementations.
- libmuscle.manager.hammer.glue_partial_conduits(nested_config: Configuration, flat_model: Model, node: tuple[Model, Reference, list[int]], plate: Plate) None[source]
Glue together conduits at model ports.
Conduits that do not lead directly from one program-implemented conduit to another will have at least one endpoint that ends at a model port or at a model-implemented component. Each port on a model-implemented component corresponds to a model port inside the model implementing that component, and these are the only places where two conduits can connect to each other.
This function runs through all the model ports of a model-implemented component, gets any conduits connected to it from the outside and the inside, glues them together, and then adds them to the flat model if they are now complete (i.e. both sides connected to a program-implemented component), or puts them back onto the plate if they’re not.
- Parameters:
nested_config – The nested configuration we’re flattening
flat_model – The new flat model we’re creating
node – model, parent_path, parent_mult tuple describing the model to process, the path to the component it implements, and the multiplicity of that component
plate – The plate to put partial components onto for later gluing
- libmuscle.manager.hammer.process_components(nested_config: Configuration, flat_model: Model, node: tuple[Model, Reference, list[int]]) list[tuple[Model, Reference, list[int]]][source]
Copy components to the flattened model.
This copies the components in the given model in nested_config to flat_model, prefixing their names with the given path and and multiplicities with the given multiplicity. Components that are implemented by a model are recursed into and are not added, and components with a None implementation are skipped and not added either.
- Parameters:
nested_config – The nested configuration we’re flattening
flat_model – The new flat model we’re creating
node – model, parent_path, parent_mult tuple describing the model to process, the path to the component it implements, and the multiplicity of that component
- Returns:
A list of new nodes to process for submodel implemented components, if any
- libmuscle.manager.hammer.process_conduits(nested_config: Configuration, flat_model: Model, node: tuple[Model, Reference, list[int]], plate: Plate) None[source]
Copy flat conduits to flat model and partial conduits to plate.
This takes the conduits from current node’s model, prefixes them with its component path, and then adds them to the flat model if both endpoints are on program-implemented components in the current model. If one or both endpoints are on model ports, or on a model-implemented component, then the conduit is a partial one and gets added to the plate.
- Parameters:
nested_config – The nested configuration we’re flattening
flat_model – The new flat model we’re creating
node – model, parent_path, parent_mult tuple describing the model to process, the path to the component it implements, and the multiplicity of that component
plate – The plate to put partial components onto for later gluing