FmiModel

class mlfmu.types.fmu_component.FmiModel(model: ModelComponent)

Bases: object

Represents an FMU model with its associated properties and variables.

__init__(model: ModelComponent) None

Initialize the FmiModel object with a ModelComponent object.

Parameters:

model (ModelComponent) – FMU component compliant with FMISlave

Methods

__init__(model)

Initialize the FmiModel object with a ModelComponent object.

add_state_initialization_parameters(states)

Generate or modify FmuInputVariables for initialization of states.

add_variable_references(inputs, parameters, ...)

Assign variable references to inputs, parameters and outputs from user interface to the FMU model class.

format_fmi_variable(var)

Get an inclusive list of variables from an interface variable definition.

get_fmi_model_variables()

Get a full list of all variables in the FMU, including each index of vector ports.

get_template_mapping()

Calculate the index to value reference mapping between onnx inputs/outputs/state to fmu variables.

get_total_variable_number()

Calculate the total number of variables including every index of vector ports.

Attributes

name

The name of the FMU model.

guid

The globally unique identifier of the FMU model.

inputs

The list of input variables for the FMU model.

outputs

The list of output variables for the FMU model.

parameters

The list of parameter variables for the FMU model.

author

The author of the FMU model.

description

The description of the FMU model.

copyright

The copyright information of the FMU model.

license

The license information of the FMU model.

state_initialization_reuse

Whether the FMU model reuses state initialization.

add_state_initialization_parameters(states: list[InternalState]) None

Generate or modify FmuInputVariables for initialization of states.

Generates or modifies FmuInputVariables for initialization of states for the InternalState objects that have set start_value and name or have set initialization_variable. Any generated parameters are appended to self.parameters.

Parameters:

states (list[InternalState]) – List of states from JSON interface.

Raises:
  • ValueError – If variables with same name are found. Variables must have a unique name.

  • ValueError – If no FMU variables were found for use for initialization.

  • ValueError – If a state has a state_value != None without having a name.

add_variable_references(inputs: list[InputVariable], parameters: list[InputVariable], outputs: list[OutputVariable]) None

Assign variable references to inputs, parameters and outputs from user interface to the FMU model class.

Parameters:
  • inputs (list[InputVariable]) – List of input variables from JSON interface.

  • parameters (list[InputVariable]) – List of model parameters from JSON interface.

  • outputs (list[OutputVariable]) – List of output variables from JSON interface.

format_fmi_variable(var: FmiInputVariable | FmiOutputVariable) list[FmiVariable]

Get an inclusive list of variables from an interface variable definition.

Vectors are separated as N number of signals, being N the size of the array.

Parameters:

var (FmiInputVariable | FmiOutputVariable) – Interface variable definition with the variable references.

Returns:

A list of FMI formatted variables.

Return type:

list[FmiVariable]

get_fmi_model_variables() list[FmiVariable]

Get a full list of all variables in the FMU, including each index of vector ports.

Returns:

List of all variables in the FMU.

Return type:

list[FmiVariable]

get_template_mapping() tuple[list[tuple[int, int]], list[tuple[int, int]], list[tuple[int, int]]]

Calculate the index to value reference mapping between onnx inputs/outputs/state to fmu variables.

Returns:

Tuple of lists of mappings between onnx indexes to fmu variables. (input_mapping, output_mapping, state_init_mapping)

Return type:

tuple[list[tuple[int, int]], list[tuple[int, int]], list[tuple[int, int]]]

get_total_variable_number() int

Calculate the total number of variables including every index of vector ports.

Returns:

The total number of variables.

Return type:

int

author: str | None

The author of the FMU model.

copyright: str | None

The copyright information of the FMU model.

description: str | None

The description of the FMU model.

guid: UUID | None

The globally unique identifier of the FMU model.

inputs: list[FmiInputVariable]

The list of input variables for the FMU model.

license: str | None

The license information of the FMU model.

name: str

The name of the FMU model.

outputs: list[FmiOutputVariable]

The list of output variables for the FMU model.

parameters: list[FmiInputVariable]

The list of parameter variables for the FMU model.

state_initialization_reuse: bool

Whether the FMU model reuses state initialization.