mlfmu.utils.builder

Functions

build_fmu(fmu_src_path, fmu_build_path, ...)

Build the FMU.

create_files_from_templates(data, fmu_src)

Create and format all needed C++ files for FMU generation.

create_model_description(fmu, src_path)

Generate modelDescription.xml structure for FMU, and save it in a file.

format_template_data(onnx, fmi_model, ...)

Generate the key-value pairs needed to format the template files to valid C++.

format_template_file(template_path, ...)

Replace all the template strings with their corresponding values and save to a new file.

generate_fmu_files(fmu_src_path, onnx_path, ...)

Generate FMU files based on the FMU source, ONNX model, and interface specification.

make_fmu_dirs(src_path)

Create all the directories needed to put all the FMU files in.

validate_fmu_source_files(fmu_path)

Validate the FMU source files.

validate_interface_spec(spec)

Parse and validate JSON data from the interface file.

mlfmu.utils.builder.build_fmu(fmu_src_path: PathLike[str], fmu_build_path: PathLike[str], fmu_save_path: PathLike[str]) None

Build the FMU.

Parameters:
  • (os.PathLike[str]) (fmu_save_path)

  • (os.PathLike[str])

  • (os.PathLike[str])

Raises:

FileNotFoundError – If required files are missing in the FMU source directory.:

mlfmu.utils.builder.create_files_from_templates(data: dict[str, str], fmu_src: Path) None

Create and format all needed C++ files for FMU generation.

Parameters:
  • (dict[str (data)

  • str]) (The data containing the values to format the template files.)

  • (Path) (fmu_src)

mlfmu.utils.builder.create_model_description(fmu: FmiModel, src_path: Path) None

Generate modelDescription.xml structure for FMU, and save it in a file.

Parameters:
  • (FmiModel) (fmu)

  • (Path) (src_path)

mlfmu.utils.builder.format_template_data(onnx: ONNXModel, fmi_model: FmiModel, model_component: ModelComponent) dict[str, str]

Generate the key-value pairs needed to format the template files to valid C++.

Parameters:
  • (ONNXModel) (onnx)

  • (FmiModel) (fmi_model)

  • (ModelComponent) (model_component)

Returns:

dict[str, str]

Return type:

The formatted template data.

mlfmu.utils.builder.format_template_file(template_path: Path, save_path: Path, data: dict[str, str]) None

Replace all the template strings with their corresponding values and save to a new file.

Parameters:
  • (Path) (save_path)

  • (Path)

  • (dict[str (data)

  • str]) (The data containing the values to replace in the template.)

mlfmu.utils.builder.generate_fmu_files(fmu_src_path: PathLike[str], onnx_path: PathLike[str], interface_spec_path: PathLike[str]) FmiModel

Generate FMU files based on the FMU source, ONNX model, and interface specification.

Parameters:
  • (os.PathLike[str]) (interface_spec_path)

  • (os.PathLike[str])

  • (os.PathLike[str])

Returns:

FmiModel

Return type:

The FMI model.

mlfmu.utils.builder.make_fmu_dirs(src_path: Path) None

Create all the directories needed to put all the FMU files in.

Parameters:

(Path) (src_path)

mlfmu.utils.builder.validate_fmu_source_files(fmu_path: PathLike[str]) None

Validate the FMU source files.

Parameters:

(os.PathLike[str]) (fmu_path)

Raises:

FileNotFoundError – If required files are missing in the FMU source directory.:

mlfmu.utils.builder.validate_interface_spec(spec: str) tuple[ValidationError | None, ModelComponent]

Parse and validate JSON data from the interface file.

Parameters:

(str) (spec)

Returns:

The validation error (if any) and the validated model component. The pydantic model instance that contains all the interface information.

Return type:

tuple[Optional[ValidationError], ModelComponent]