NeuralFMU: Towards Structural Integration of FMUs into Neural Networks

Tobias Thummerer, Josef Kircher, Lars MikelsonsarXiv 2021 · DOI

Abstract

This paper covers two major subjects: First, the presentation of a new open-source library called FMI.jl for integrating FMI into the Julia programming environment by providing the possibility to load, parameterize and simulate FMUs. Further, an extension to this library called FMIFlux.jl is introduced, that allows the integration of FMUs into a neural network topology to obtain a NeuralFMU. This structural combination of an industry typical black-box model and a data-driven machine learning model combines the different advantages of both modeling approaches in one single development environment. This allows for the usage of advanced data driven modeling techniques for physical effects that are difficult to model based on first principles.

Introduction

In industrial engineering, physical systems are traditionally modeled using specialized tools like Modelica or Simulink and exported as Functional Mock-up Units (FMUs). While these models are highly accurate for known physics, they often struggle with "unmodeled dynamics"—complex, non-linear effects like friction or wear-and-tear that are difficult to capture with first-principles equations.

Conversely, pure Machine Learning (ML) models excel at fitting data but frequently ignore physical laws, resulting in "black boxes" that fail to generalize. This paper introduces NeuralFMU, a framework that bridges this gap by integrating industry-standard FMUs directly into neural network architectures. This enables "hybrid modeling," where data-driven components learn missing physical effects while maintaining the structural integrity of the known physical system.

The NeuralFMU Framework

The authors address the challenge of structural integration through two open-source Julia libraries:

  1. FMI.jl: A wrapper that enables the Julia environment to load, parameterize, and simulate FMUs.
  2. FMIFlux.jl: An extension that allows these FMUs to function as layers within the Flux.jl machine learning ecosystem.

To make these hybrid models trainable, the framework leverages Differentiable Programming. Since FMUs are often compiled binaries (black boxes), the authors use Julia’s Zygote.jl to define custom "adjoints." These mathematical shortcuts allow gradients to flow through the simulation binary during backpropagation, treating the entire simulation pipeline as a single differentiable program.

Architecture and Implementation

The paper describes two primary configurations for integration:

  • Model Exchange (ME-NeuralFMU): The FMU provides state derivatives, which are then integrated by a high-performance numerical solver (e.g., Tsit5). This setup is ideal for continuous-time learning.
  • Co-Simulation (CS-NeuralFMU): The FMU handles its own integration steps. While common in industry, this is more challenging to train because the internal solver remains opaque.
Architecture of a Model Exchange (ME) NeuralFMU, integrating neural network layers with a physical FMU component.

As illustrated in the architecture above, neural networks can be placed strategically around the FMU—for instance, to correct state offsets before the physics engine or to approximate missing forces like friction after the FMU output.

Experimental Evaluation

The framework was evaluated using a synthetic benchmark consisting of a mass-spring-damper system featuring complex, discontinuous Stribeck friction.

  • The "Gap": The FMU used in the test was intentionally "broken"—it lacked the friction model and contained an incorrect position offset.
  • Training: Using 400 data points of position and velocity, the NeuralFMU was trained to compensate for these deficiencies.
  • Results: After approximately 22.5 minutes of training on a standard desktop CPU, the NeuralFMU successfully learned to compensate for the 0.1m position offset and accurately approximated the complex friction curve.

Unlike a pure FMU (which failed due to missing physics) or a pure NN (which might overfit), the hybrid NeuralFMU demonstrated strong generalization, performing well on test cases with initial states unseen during training.

Conclusion and Future Work

NeuralFMU demonstrates that black-box physical models can be treated as standard layers in a neural network stack, provided the FMI standard offers directional derivatives. This avoids the computational overhead of "finite differences" typically used for gradient estimation in black-box models.

Future development aims to address the challenges of Co-Simulation (CS) FMUs, where opaque internal solvers make gradient calculation difficult. Additionally, the authors plan to expand the framework into NeuralSSP, allowing for the integration of entire multi-model system structures into neural networks, and exploring hardware acceleration to move these hybrid loops onto GPUs.

Summary updated

BibTeX
@misc{thummerer2021neuralfmu,
  author = {Tobias Thummerer and Josef Kircher and Lars Mikelsons},
  title = {{NeuralFMU: Towards Structural Integration of FMUs into Neural Networks}},
  year = {2021},
  eprint = {2109.04351},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2109.04351},
}
Figure