MlFmuBuilder¶
- class mlfmu.api.MlFmuBuilder(fmu_name: str | None = None, interface_file: Path | None = None, ml_model_file: Path | None = None, source_folder: Path | None = None, fmu_output_folder: Path | None = None, build_folder: Path | None = None, root_directory: Path | None = None)¶
Bases:
object
Builder for creating FMUs (Functional Mock-up Units) from machine learning models.
This class is core to executing the different commands in the mlfmu process.
- __init__(fmu_name: str | None = None, interface_file: Path | None = None, ml_model_file: Path | None = None, source_folder: Path | None = None, fmu_output_folder: Path | None = None, build_folder: Path | None = None, root_directory: Path | None = None) None ¶
Initialize a new instance of the MlFmuBuilder class.
- Parameters:
fmu_name (str | None, optional) – The name of the FMU., by default None
interface_file (Path | None, optional) – The path to the interface JSON file., by default None
ml_model_file (Path | None, optional) – The path to the machine learning model file., by default None
source_folder (Path | None, optional) – The folder containing the source code for the FMU., by default None
fmu_output_folder (Path | None, optional) – The folder where the built FMU will be saved., by default None
build_folder (Path | None, optional) – The folder where the FMU will be built., by default None
root_directory (Path | None, optional) – The root directory for the builder., by default None
Methods
__init__
([fmu_name, interface_file, ...])Initialize a new instance of the MlFmuBuilder class.
build
()Build an FMU from the machine learning model file and interface file.
compile
()Compile the FMU from the C++ source code and model description.
Return the path to a build folder inside the temp_folder.
Return the path to a src folder inside the temp_folder.
Return the path to the default source folder for the compile process.
Return the path to the default fmu output folder.
Return the path to the default source folder for the generate process.
Return the path to a interface json file inside self.root_directory if it can be inferred.
Return the path to a ml model file inside self.root_directory if it can be inferred.
generate
()Generate C++ source code and model description from the machine learning model file and interface file.
Attributes
The temporary folder used for building the FMU.
- build() None ¶
Build an FMU from the machine learning model file and interface file.
Builds an FMU from ml_model_file and interface_file and saves it to fmu_output_folder. If the paths to the necessary files and directories are not given the function will try to find files and directories that match the ones needed.
- Raises:
FileNotFoundError – if ml_model_file or interface_file do not exists or is not set and cannot be easily inferred.
--- –
- compile() None ¶
Compile the FMU from the C++ source code and model description.
Compiles the FMU from the FMU C++ source code and model description contained in source_folder and saves it to fmu_output_folder.
If the paths to the necessary files and directories are not given the function will try to find files and directories that match the ones needed.
- Raises:
FileNotFoundError – if source_folder or fmu_name is not set and cannot be easily inferred.
- default_build_folder() Path ¶
Return the path to a build folder inside the temp_folder. Creates the temp_folder if it is not set.
- Returns:
the path to the build folder.
- Return type:
Path
- default_build_source_folder() Path ¶
Return the path to a src folder inside the temp_folder. Creates the temp_folder if it is not set.
- Returns:
the path to the src folder.
- Return type:
Path
- default_compile_source_folder() Path | None ¶
Return the path to the default source folder for the compile process.
Searches inside self.source_folder and self.root_directory for a folder that contains a folder structure and files that is required to be valid ml fmu source code.
- Returns:
the path to the default source folder for the compile process.
- Return type:
Path
- default_fmu_output_folder() Path ¶
Return the path to the default fmu output folder.
- Returns:
the path to the default fmu output folder.
- Return type:
Path
- default_generate_source_folder() Path ¶
Return the path to the default source folder for the generate process.
- Returns:
the path to the default source folder for the generate process.
- Return type:
Path
- default_interface_file() Path | None ¶
Return the path to a interface json file inside self.root_directory if it can be inferred.
- Returns:
the path to the interface json file, or None.
- Return type:
Path | None
- default_model_file() Path | None ¶
Return the path to a ml model file inside self.root_directory if it can be inferred.
- Returns:
the path to the ml model file, or None.
- Return type:
Path | None
- generate() None ¶
Generate C++ source code and model description from the machine learning model file and interface file.
Generates FMU C++ source code and model description from ml_model_file and interface_file and saves it to source_folder.
If the paths to the necessary files and directories are not given the function will try to find files and directories that match the ones needed.
- Raises:
FileNotFoundError – if ml_model_file or interface_file do not exists or is not set and cannot be easily inferred.
- temp_folder: TemporaryDirectory[str]¶
The temporary folder used for building the FMU.