Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Python API reference

The oedisi package exposes the component framework used to describe and compile co-simulations. The reference below is generated from the package’s own docstrings and Pydantic models. For the data models exchanged between components see Data types; for the CLI see the command-line interface.

Component framework

Module: oedisi.componentframework.system_configuration

WiringDiagram (class)

Cosimulation configuration. This may end up wrapped in another interface.

Parameters
----------
name :
    Name of the simulation.
components :
    List of components in the simulation.
links :
    List of links connecting component ports.
shared_helics_config :
    Optional shared federate configuration applied to all components.
    Per-component values (name, core_name) are derived automatically.

Fields

FieldTypeDefaultDescription
namestrrequired
componentslist[Component]required
linkslist[Link]required
shared_helics_configSharedFederateConfig | NoneNone

Component (class)

A component configuration in WiringDiagram.

Fields

FieldTypeDefaultDescription
namestrrequired
typestrrequired
hoststr | NoneNone
container_portint | NoneNone
imagestr''
parametersdict[str, Any]required
helics_config_overrideSharedFederateConfig | NoneNone

Connection between component ports in wiring diagram.

Fields

FieldTypeDefaultDescription
sourcestrrequired
source_portstrrequired
targetstrrequired
target_portstrrequired

Port (class)

Port identifier for creating links between components.

Fields

FieldTypeDefaultDescription
namestrrequired
port_namestrrequired

AnnotatedType (class)

Represent the type on component static input, dynamic input, and dynamic output.

Currently not checked in any type checker.

Fields

FieldTypeDefaultDescription
typestrrequired
descriptionstr | NoneNone
unitstr | NoneNone
port_idstr | NoneNone

ComponentStruct (class)

Component with its associated links for multi-container configuration.

Fields

FieldTypeDefaultDescription
componentComponentrequired
linkslist[Link]required

ComponentType (class)

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.

ComponentCapabilities (class)

Component capability declarations for build-time validation.

Parameters
----------
version :
    Capabilities schema version.
broker_config :
    Whether this component supports receiving federate_config in static_inputs.json.
    If True, the component can be used with WiringDiagram.shared_helics_config.

Fields

FieldTypeDefaultDescription
versionstr'1.0'
broker_configboolFalse

Federate (class)

Federate configuration for HELICS CLI runner.

Fields

FieldTypeDefaultDescription
directorystrrequired
hostnamestr'localhost'
namestrrequired
execstrrequired

RunnerConfig (class)

HELICS running config for the full simulation.

Examples
--------
Save to JSON

>>> with open(filename, "w") as f:
...    json.dump(config.model_dump(mode="json"), f)

Run Simulation

`$ helics run --path=filename`

Fields

FieldTypeDefaultDescription
namestrrequired
federateslist[Federate]required

generate_runner_config (function)

generate_runner_config(wiring_diagram: WiringDiagram, component_types: dict[str, type[ComponentType]], compatibility_checker=_bad_compatability_checker, target_directory='.')
Create HELICS run configuration from wiring diagram and component types.

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 a bool
    Each link uses the compatability_checker to ensure the link types are
    compatible.

Returns
-------
RunnerConfig
    Configuration which can be used to run the cosimulation

Raises
------
Can raise any exception from component type initialization

initialize_federates (function)

initialize_federates(wiring_diagram: WiringDiagram, component_types: dict[str, type[ComponentType]], compatability_checker, target_directory='.') -> list[Federate]
Initialize all the federates.

Extracts config and sends it to each Component in an initalization step,
then finds all dynamic inputs and outputs and sends input mappings.

Parameters
----------
wiring_diagram
component_types : dictionary of component type names to ComponentType class
compatibility_checker : function from types to bool
    Check if source type is compatible with target_type
target_directory : str | Path = "."
    Directory where all components should be initialized.

Returns
-------
List of `Federate` run configuration

Raises
------
ComponentType classes may return errors on configuration.

Basic components

Module: oedisi.componentframework.basic_component

ComponentDescription (class)

Component description for simple ComponentType.

Parameters
----------
directory :
    where code is stored relative to where this is run
execute_function :
    command to execute component
static_inputs :
    List of types for the parameter
dynamic_inputs :
    List of input types. Typically subscriptions.
dynamic_outputs :
    List of output types. Typically publications.
capabilities :
    Component capability declarations for build-time validation.

Fields

FieldTypeDefaultDescription
directorystrrequired
execute_functionstrrequired
static_inputslist[AnnotatedType]required
dynamic_inputslist[AnnotatedType]required
dynamic_outputslist[AnnotatedType]required
capabilitiesComponentCapabilitiesPydanticUndefined

component_from_json (function)

component_from_json(filepath, type_checker)
Load component description from JSON file and create component type.

Parameters
----------
filepath : str | Path
type_checker : function taking the type and value and returning a boolean

Returns
-------
BasicComponent class

basic_component (function)

basic_component(comp_desc: ComponentDescription, type_checker)
Create a new component type from component definition data.

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
-------
BasicComponent(system_configuration.ComponentType) :
     ComponentType from the description

Federate configuration

Module: oedisi.types.helics_config

HELICSFederateConfig (class)

Full HELICS federate configuration.

This is what federates receive in static_inputs.json, containing various HELICS
configuration at the top-level (name, core_type, broker, etc). Subtype this in your
applications for custom configuration.

Parameters
----------
name :
    Federate name (derived from Component.name).
core_type :
    HELICS core type (e.g., "zmq", "tcp", "inproc").
core_name :
    Core name for this federate (derived per-component).
core_init :
    Core initialization string.
broker :
    Broker connection configuration.

Examples
--------
>>> config = HELICSFederateConfig(
...     name="state_estimator",
...     core_type="zmq",
...     broker=HELICSBrokerConfig(port=23404)
... )
>>> config.to_json()
'{"name": "state_estimator", "coreType": "zmq", ...}'

Fields

FieldTypeDefaultDescription
namestrrequired
core_typestr | NoneNone
core_namestr | NoneNone
core_initstr | NoneNone
brokerHELICSBrokerConfig | NoneNone

HELICSBrokerConfig (class)

HELICS broker connection parameters.

Parameters
----------
host :
    Broker hostname or IP address.
port :
    Broker port number.
key :
    Broker key for authentication.
auto :
    Whether to automatically configure broker connection.
initstring :
    Additional initialization string for broker connection.

Fields

FieldTypeDefaultDescription
hoststr | NoneNone
portint | NoneNone
keystr | NoneNone
autobool | NoneNone
initstringstr | NoneNone

SharedFederateConfig (class)

Shared federate settings at the WiringDiagram level.

This contains settings that are shared across all federates in a simulation.
Does NOT include name/core_name (those are per-component). Users
are expected to write this as part of the wiring_diagram.json,
and invidual federates get passed `config.to_federate_config()`.

Parameters
----------
core_type :
    HELICS core type (e.g., "zmq", "tcp", "inproc").
core_init :
    Core initialization string.
broker :
    Broker connection configuration.

Examples
--------
>>> shared = SharedFederateConfig(
...     core_type="zmq",
...     broker=HELICSBrokerConfig(port=23404)
... )
>>> config = shared.to_federate_config("my_federate")
>>> config.name
'my_federate'

Fields

FieldTypeDefaultDescription
core_typestr | NoneNone
core_initstr | NoneNone
brokerHELICSBrokerConfig | NoneNone