FMI-LS-REF¶
Validation of the results of an FMU from the reference material of FMI-LS-REF (see FMU Checker): the experiment files, the time series of their stimuli and references, and the replay of an experiment with the runtime of the FMU Container.
Experiment files of MA-HS-Experiments, referred to by FMI-LS-REF (draft of the Modelica Association).
An experiment file (<Experiments>) holds transient experiments: start and stop times, step size, tolerance, and the files of their parameters (SSV), stimuli and references (time series), given by URIs relative to the experiment file.
Experiment dataclass ¶
A TransientExperiment of an experiment file. The times are None when they are not given.
Attributes:
| Name | Type | Description |
|---|---|---|
name | str | Name of the experiment. |
description | str | None | Human-readable description. |
start_time | float | None | Start time, in seconds. |
stop_time | float | None | Stop time, in seconds. |
step_size | float | None | Step size, in seconds. |
tolerance | float | None | Tolerance. |
parameters | ExperimentSource | None | Parameters of the experiment. |
stimuli | ExperimentSource | None | Stimuli of the experiment. |
references | ExperimentSource | None | Reference results of the experiment. |
Source code in fmu_manipulation_toolbox/experiments.py
ExperimentSource dataclass ¶
The file of the parameters, of the stimuli or of the references of an experiment.
Attributes:
| Name | Type | Description |
|---|---|---|
source | str | URI of the file, relative to the experiment file. |
type | str | MIME type of the file. |
path | Path | None | The file, when it was found in the FMU. |
problem | str | None | Why the file was not found (see resolve_uri). |
Source code in fmu_manipulation_toolbox/experiments.py
Experiments dataclass ¶
An experiment file (Experiments element).
Attributes:
| Name | Type | Description |
|---|---|---|
name | str | Name of the set of experiments. |
description | str | None | Human-readable description. |
experiments | list[Experiment] | Its experiments, in the order of the file. |
Source code in fmu_manipulation_toolbox/experiments.py
ExperimentsError ¶
Parameter dataclass ¶
A parameter of an SSV parameter set.
Attributes:
| Name | Type | Description |
|---|---|---|
name | str | Name of the variable. |
type | str | Value element of the parameter ( |
value | str | Its value, as written in the file. |
Source code in fmu_manipulation_toolbox/experiments.py
read_experiments(filename, root) ¶
Reads the experiment file filename of the extracted FMU root.
The elements are matched by their local name: the namespace and the XSD are checked by the checker of LS-REF. The sources are resolved against the directory of the file (see resolve_uri).
Raises:
| Type | Description |
|---|---|
ExperimentsError | The file is not well-formed XML, its root is not |
Source code in fmu_manipulation_toolbox/experiments.py
read_parameter_set(filename) ¶
Reads the parameters of an SSV file (ssv:ParameterSet). A parameter is given by its first value element (ssv:Real, ssv:Integer...); a parameter without value element is ignored.
Raises:
| Type | Description |
|---|---|
ExperimentsError | The file is not well-formed XML or has no |
Source code in fmu_manipulation_toolbox/experiments.py
File designated by a relative URI of a layered standard, resolved against the directory base.
The URI may hold dot segments, as long as the resolved path stays inside the extracted FMU root.
Returns:
| Type | Description |
|---|---|
tuple[Path | None, str | None] | tuple[Path | None, str | None]: The path of the file and |
Source code in fmu_manipulation_toolbox/ls.py
Time series of FMI-LS-REF: stimuli and references of the experiments, simulated outputs.
The CSV files follow the convention of the FMI cross-check (Reference-FMUs, fmpy): comma separator, a header whose first column is time and whose other columns are the names of the FMI variables (quotes allowed), then one row per instant. Two rows may have the same time: an event, the second row gives the values after it.
Comparison dataclass ¶
Result of the comparison of a simulated variable with its reference.
Attributes:
| Name | Type | Description |
|---|---|---|
name | str | Name of the variable. |
max_error | float | Maximal absolute error over the instants of the reference (numbers only). |
max_error_time | float | None | Instant of the maximal error. |
failure_time | float | None | First instant where the criterion fails; |
expected | object | Value of the reference at |
simulated | object | Simulated value at |
Source code in fmu_manipulation_toolbox/timeseries.py
TimeSeries dataclass ¶
Values of variables over time.
Attributes:
| Name | Type | Description |
|---|---|---|
times | list[float] | Instants, non-decreasing (equal instants: an event). |
columns | dict[str, list] | Values of each variable, one per instant: text as read in a CSV file, or numbers. |
Source code in fmu_manipulation_toolbox/timeseries.py
index(time) ¶
Index of the last instant that is not after time (the value after an event at time); -1 before the first instant. time matches an instant within a relative epsilon of 1e-9, so that a communication point computed by the simulation finds the row of its instant.
Source code in fmu_manipulation_toolbox/timeseries.py
until(time) ¶
Copy of the series up to time included (within the epsilon of index).
Source code in fmu_manipulation_toolbox/timeseries.py
value(name, time, interpolation=LINEAR) ¶
Value of the variable name at time: before the first instant, the first value; after the last one, the last value; in between, the value interpolated as interpolation (LINEAR or HOLD).
Raises:
| Type | Description |
|---|---|
TimeSeriesError | The series has no instant, or a value to interpolate linearly is not a number. |
Source code in fmu_manipulation_toolbox/timeseries.py
TimeSeriesError ¶
compare(reference, simulated, name, rtol, atol, interpolation=LINEAR, exact=False) ¶
Compares the variable name of simulated with reference at the instants of the reference.
The simulated value is interpolated as interpolation. Numbers (booleans as 0 / 1) match when abs(simulated - reference) <= atol + rtol * abs(reference); with exact (strings), when the texts are equal. At an event of the reference (rows with the same time), the value after it (its last row) is compared.
Raises:
| Type | Description |
|---|---|
TimeSeriesError | A number is not a number, or a series has no instant. |
Source code in fmu_manipulation_toolbox/timeseries.py
read_csv(filename) ¶
Reads a CSV file of the FMI cross-check convention.
Raises:
| Type | Description |
|---|---|
TimeSeriesError | The file has no header, its first column is not |
Source code in fmu_manipulation_toolbox/timeseries.py
to_number(value) ¶
A value of a time series as a number: numbers as they are, text parsed (true / false accepted).
Raises:
| Type | Description |
|---|---|
TimeSeriesError | The value is not a number. |
Source code in fmu_manipulation_toolbox/timeseries.py
Replay of an experiment of FMI-LS-REF with the container runtime.
The FMU is embedded in a temporary FMI-3 container (FMUContainer, whatever the FMI version of the FMU: the runtime embeds FMI-2 FMUs as well): one input per stimulus, one output per variable to record, the parameters as start values. The library of the container is then driven through its FMI-3 API (ctypes; the logger of FMI-2 is variadic, which ctypes cannot read on every platform): at each communication point t_k = start + k * step (computed, not accumulated), the stimuli interpolated at t_k are set, the outputs are read and recorded at t_k, then the container steps to t_k+1 (convention of fmpy and of the results of the Reference-FMUs: an output fed through follows its input at the same instant). When an embedded FMU asks to terminate the simulation, the container stops at the time reached: the simulation ends there, the outputs of this instant being the last ones recorded. An array output is recorded as one column per element, named as by the structured naming convention of FMI-3 (indices from 1, row-major order): y[1], y[2]... or m[1,1], m[1,2]...
The simulation runs in a dedicated process (multiprocessing, spawn): a crash of the FMU or of the runtime, or a simulation that never returns, fails the replay instead of the calling process, and the libraries loaded by the simulation are unloaded with its process.
SimulationError ¶
SimulationUnavailable ¶
Bases: SimulationError
The container runtime, or the binary of the FMU, is not available for the host platform.
SimulationUnsupported ¶
Bases: SimulationError
An experiment that the temporary container cannot replay (a stimulus on a boolean input of an FMI-2 FMU).
experiment_times(experiment, model_description, references) ¶
Start and stop times of an experiment: those of the experiment, else those of the DefaultExperiment of the FMU, else the first and the last instants of the references.
Raises:
| Type | Description |
|---|---|
SimulationError | A time cannot be determined. |
Source code in fmu_manipulation_toolbox/simulation.py
replay(fmu_filename, experiment, outputs, stimuli=None, parameters=None, references=None, timeout=None, isolated=True) ¶
Replays experiment on the FMU fmu_filename with the container runtime and records outputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fmu_filename | Path | str | The FMU. | required |
experiment | Experiment | Its start and stop times and its step size ( | required |
outputs | list[str] | Names of the output variables to record. | required |
stimuli | TimeSeries | None | Values of input variables (linear interpolation for the continuous reals, previous value otherwise). | None |
parameters | list[Parameter] | None | Start values of parameters. | None |
references | TimeSeries | None | The references, whose instants give the start and stop times when nothing else does. | None |
timeout | float | None | Time limit of the simulation, in seconds ( | None |
isolated | bool | Run the simulation in a dedicated process ( | True |
Returns:
| Name | Type | Description |
|---|---|---|
TimeSeries | TimeSeries | The values of |
Raises:
| Type | Description |
|---|---|
SimulationUnavailable | The container or the FMU has no library for the host platform. |
SimulationUnsupported | A stimulus is on a boolean input of an FMI-2 FMU, which the FMI-3 container cannot expose, or on an array input; an output is an array whose dimension is given by a structural parameter. |
SimulationError | The container cannot be built, the simulation fails, crashes or exceeds |