oedisi.componentframework package

Submodules

oedisi.componentframework.basic_component module

Generate basic component from description JSON

class oedisi.componentframework.basic_component.ComponentDescription(*, directory: str, execute_function: str, static_inputs: List[AnnotatedType], dynamic_inputs: List[AnnotatedType], dynamic_outputs: List[AnnotatedType])

Bases: BaseModel

Component description for simple ComponentType

Parameters:
directory: str
dynamic_inputs: List[AnnotatedType]
dynamic_outputs: List[AnnotatedType]
execute_function: str
static_inputs: List[AnnotatedType]
oedisi.componentframework.basic_component.basic_component(comp_desc: ComponentDescription, type_checker)

Uses data in component_definition to create a new component type

Parameters:
  • comp_desc (ComponentDescription) – Simplified component representation usually from a JSON file

  • type_checker (function taking the type and value and returning a boolean)

Returns:

ComponentType from the description

Return type:

BasicComponent(system_configuration.ComponentType)

oedisi.componentframework.basic_component.component_from_json(f, type_checker)
oedisi.componentframework.basic_component.types_to_dict(types: List[AnnotatedType])

oedisi.componentframework.mock_component module

MockComponent and MockFederate allow you to instantiate a mock component with a specified set of inputs and outputs. The parameters dictionary should contain a list under “inputs” and “outputs”. During implementation, the value pi is passed around every second until t=100.

MockComponent defines the ComponentType for a simple testing component.

MockFederate defines the corresponding implementation.

class oedisi.componentframework.mock_component.MockComponent(name, parameters: Dict[str, Dict[str, str]], directory: str, host: str | None = None, port: int | None = None, comp_type: str | None = None)

Bases: ComponentType

property dynamic_inputs
property dynamic_outputs
property execute_function
generate_helics_config(outputs)
generate_input_mapping(links)
process_parameters(parameters)
class oedisi.componentframework.mock_component.MockFederate

Bases: object

run()
oedisi.componentframework.mock_component.destroy_federate(fed)
oedisi.componentframework.mock_component.get_default_value(date_type: HelicsDataType)

oedisi.componentframework.system_configuration module

This module defines common types and methods for configuration.

The final method generate_runner_config brings together a WiringDiagram and a dictionary of ComponentTypes with optional comparison using a compatability checking function.

The ComponentType defines the common interface that component configuration must implement. By default, this can be instantiated using basic_component.py.

The WiringDiagram configuration contains a list of components and the links between them.

class oedisi.componentframework.system_configuration.AnnotatedType(*, type: str, description: str | None = None, unit: str | None = None, port_id: str | None = None)

Bases: BaseModel

Class for representing the types of components and their interfaces

description: str | None
port_id: str | None
property port_name
type: str
unit: str | None
class oedisi.componentframework.system_configuration.Component(*, name: str, type: str, host: str | None = None, container_port: int | None = None, image: str = '', parameters: Dict[str, Any])

Bases: BaseModel

Component type used in WiringDiagram, includes name, component type, and initial parameters

container_port: int | None
host: str | None
image: str
name: str
parameters: Dict[str, Any]
port(port_name: str)
type: str
classmethod validate_image(v, values, **kwargs)
class oedisi.componentframework.system_configuration.ComponentStruct(*, component: Component, links: List[Link])

Bases: BaseModel

component: Component
class oedisi.componentframework.system_configuration.ComponentType

Bases: ABC

Abstract type for component configuration.

The components define the main restrictions on how components can be configured. In the simplest case, the basic_copmonent function constructs a type from a ComponentDescription which just write files. There are no restrictions, so for example, one possibility is for the component type to interact with a web service.

First, the class is initialized for each component using the name, parameters, and target directory. The federate name in HELICS should be the name initialized here.

Then the dynamic_inputs and dynamic_outputs are used to check types and verify the links used between components. These can depend on the initialziation parameters. The dynamic_outputs should be initialized under the prefix name/.

Next, generate_input_mapping is then called with a mapping of the variable names to the HELICS subscription keys. The individual federate should then use these names to subscribe at the right location. This can also be used for endpoint targets less often.

Finally, the execute_function property defines the command to run the component.

abstract property dynamic_inputs
abstract property dynamic_outputs
abstract property execute_function
abstract generate_input_mapping(links: Dict[str, str])
class oedisi.componentframework.system_configuration.Federate(*, directory: str, hostname: str = 'localhost', name: str, exec: str)

Bases: BaseModel

Federate configuration for HELICS CLI

directory: str
exec: str
hostname: str
name: str

Bases: BaseModel

source: str
source_port: str
target: str
target_port: str
class oedisi.componentframework.system_configuration.Port(*, name: str, port_name: str)

Bases: BaseModel

connect(port: Port)
name: str
port_name: str
class oedisi.componentframework.system_configuration.RunnerConfig(*, name: str, federates: List[Federate])

Bases: BaseModel

HELICS running config for the full simulation

Examples

Save to JSON

>>> with open(filename, "w") as f:
...    f.write(config.json())

Run Simulation

$ helics run –path=filename

federates: List[Federate]
name: str
class oedisi.componentframework.system_configuration.WiringDiagram(*, name: str, components: List[Component], links: List[Link])

Bases: BaseModel

Cosimulation configuration. This may end up wrapped in another interface

add_component(c: Component)
classmethod check_component_names(components)

Check that the components all have unique names

clean_model(target_directory='.')
components: List[Component]
classmethod empty(name='unnamed')
name: str
oedisi.componentframework.system_configuration.bad_compatability_checker(type1, type2)

Basic compatability checker that says all types are compatible.

oedisi.componentframework.system_configuration.generate_runner_config(wiring_diagram: ~oedisi.componentframework.system_configuration.WiringDiagram, component_types: ~typing.Dict[str, ~typing.Type[~oedisi.componentframework.system_configuration.ComponentType]], compatibility_checker=<function bad_compatability_checker>, target_directory='.')

Brings together a WiringDiagram and a dictionary of ComponentTypes to create a helics run configuration.

Parameters:
  • wiring_diagram (WiringDiagram) – Configuration describing components, parameters, and links between them

  • component_types (Dict[str, Type[ComponentType]]) – Dictionary for the wiring diagram component types to Python component types

  • compatibility_checker (function of two types to the booleans) – Each link uses the compatability_checker to ensure the link is between compatible types.

Returns:

Configuration which can be used to run the cosimulation

Return type:

RunnerConfig

oedisi.componentframework.system_configuration.get_federates_conn_info(wiring_diagram: WiringDiagram)
oedisi.componentframework.system_configuration.initialize_federates(wiring_diagram: WiringDiagram, component_types: Dict[str, Type[ComponentType]], compatability_checker, target_directory='.') List[Federate]

Initialize all the federates

oedisi.componentframework.wiring_diagram_utils module

Wiring Diagram utilities

Wiring diagrams can be hard to manage in their final list based form. Some utilities plot, and future additions include nested wiring diagram composition and a programmatic interface.

oedisi.componentframework.wiring_diagram_utils.get_graph(wiring_diagram: WiringDiagram)

Get networkx graph representation of wiring_diagram

oedisi.componentframework.wiring_diagram_utils.get_graph_renderer(G)
oedisi.componentframework.wiring_diagram_utils.plot_graph_bokeh(wiring_diagram: WiringDiagram)
oedisi.componentframework.wiring_diagram_utils.plot_graph_matplotlib(wiring_diagram: WiringDiagram)

Module contents