Include ONNX into exported FMU

After an ONNX is generated it can be compiled into the FMU.

Warning

The FMU can't be compiled on Windows systems, because the ONNX Runtime is incompatible with the MSYS2 shell used by OpenModelica to compile the FMU.

Functions

NonLinearSystemNeuralNetworkFMU.buildWithOnnxFunction
buildWithOnnx(fmu, modelName, equations, onnxFiles; usePrevSol=false, tempDir=modelName*"_onnx")

Include ONNX into FMU and recompile to generate FMU with ONNX surrogates.

Arguments

  • fmu::String: Path to FMU to extend with ONNX surrogates.
  • modelName::String: Name of model in FMU.
  • equations::Array{ProfilingInfo}: Profiling info for all equations to replace.
  • onnxFiles::Array{String}: Array of paths to ONNX surrogates.

Keyword Arguments

  • usePrevSol::Bool: ONNX uses previous solution as additional input.
  • maxRelError::Float64: Maximum allowed relative error of ANN (default: 1e-4).
  • tempDir::String: Working directory.

Returns

  • Path to ONNX FMU.
source

Example

using NonLinearSystemNeuralNetworkFMU # hide
rm("onnxTempDir", recursive=true, force=true) # hide
modelName = "simpleLoop"
fmu = joinpath("tempDir", "simpleLoop.interface.fmu")
profilingInfo = getProfilingInfo("simpleLoop.bson")[1:1]
onnxFiles = ["eq_14.onnx"]

buildWithOnnx(fmu,
              modelName,
              profilingInfo,
              onnxFiles,
              tempDir = "onnxTempDir")

This FMU can now be simulated with most FMI importing tools.