Towards Integration of PeN-ODEs in a Modelica-based workflow

Andreas Hofmann, Lars MikelsonsLinköping 2025 · DOI

TL;DR

This paper tackles the challenge of integrating machine learning (ML) models with traditional physics-based models within the Modelica environment, a popular tool for system simulation. They propose a framework for "Physics-enhanced Neural Ordinary Differential Equations" (PeN-ODEs) that leverages Modelica's object-oriented strengths for reusability and presents a case study of a SCARA robot to demonstrate a partially integrated workflow.

What Problem Does This Paper Address?

System simulation often relies on first-principle models (FPMs) that are based on physical laws. While accurate, these models can be complex to develop and may struggle to capture unmodeled physics or complex behaviors. Machine learning (ML) models, on the other hand, excel at learning from data but often lack interpretability and extrapolation capabilities, and can be data-hungry. Hybrid models, combining FPMs and ML, offer a promising solution by leveraging the strengths of both.

However, integrating these hybrid models into existing simulation workflows, particularly those using Modelica, presents significant hurdles. Modelica's object-oriented nature, with its emphasis on modularity and reusability, is not easily compatible with current ML training environments (often Python-based) and the way ML models are typically integrated. This paper aims to bridge this gap, enabling the development and deployment of hybrid models within a Modelica-centric workflow, specifically focusing on PeN-ODEs.

Methods

The core contribution is the exploration of approaches for integrating PeN-ODEs into Modelica. This involves addressing three key challenges:

  • Architecture Definition: Defining how FPMs and ML components interact within Modelica's object-oriented structure. The paper discusses two architectural approaches:
  • Parallel Architecture: Directly augmenting an existing physical equation with an ML function placeholder.
  • Universal Architecture: Splitting a physical equation into known and unknown parts, where the unknown part is handled by an ML function. This allows for more flexible integration of ML components.
  • Training Environment: Bridging the gap between Modelica and ML training frameworks. The authors focus on Julia and its SciML ecosystem, highlighting packages like ModelingToolkit.jl for symbolic manipulation and DifferentialEquations.jl for solving ODEs. They also discuss the use of FMIFlux.jl and FMI.jl for working with Functional Mockup Units (FMUs).
  • Reintegration: Incorporating the trained ML component back into the Modelica model. The paper suggests defining minimal interfaces in Modelica and processing the ML model in the external environment, leveraging Modelica's "external C" feature or standardized formats like ONNX.

The paper also distinguishes between two training strategies:

  • Closed-loop training: Gradients are computed through the entire ODE solution process, requiring careful handling of time and state events.
  • Open-loop training: Focuses on training the ML part based on the right-hand side (RHS) of the ODE, which is computationally less demanding.

Datasets

The paper uses a simulated dataset generated from a SCARA robot model. This dataset is created by simulating the robot's behavior with a Stribeck friction model and then using the motor currents as the primary measurement signals for training. The word "train" is used for training data, and the word "validate" is used for testing.

Key Insights and Ideas

  • Modelica's object-oriented nature is a double-edged sword: While it promotes reusability, it also necessitates careful consideration of how ML components are integrated without breaking encapsulation.
  • Bridging Modelica and Julia is crucial: The paper highlights Julia's SciML ecosystem as a promising avenue for developing and training hybrid models, but acknowledges the ongoing challenges in seamless integration.
  • PeN-ODEs offer a flexible framework: The proposed architecture allows for tailoring the hybrid model to specific use cases, learning unmodeled physics or complex behaviors.
  • Reusability of trained components is key: By defining minimal interfaces in Modelica, trained ML components can be reused across different simulation scenarios, justifying the effort in training.
  • Standardized formats like ONNX are valuable: They offer a way to integrate complex neural networks into Modelica without impacting the compiler's performance.

Key Results

The paper demonstrates a partially integrated workflow for a SCARA robot. The trained PeN-ODE model achieved a significant reduction in error metrics:

  • Mean Absolute Error (MAE): Reduced by a factor greater than 4 for combined model states.
  • Mean Squared Error (MSE): Reduced by a factor greater than 11 for combined model states.
  • Specific motor states: Table 1 shows substantial reductions in MAE and MSE for individual motor states, with trained errors being orders of magnitude lower than the original model's errors.

Qualitatively, the trained model's trajectory for writing the word "validate" closely matches the reference data, particularly in capturing the effects of friction.

Limitations and Future Work

  • Partial Integration: The presented workflow is described as "partially integrated," indicating that a fully seamless end-to-end solution is still under development.
  • Training Challenges: The paper notes that only single-step solvers could be employed for gradient calculation due to discontinuous setpoint data and a bug in DAE initialization.
  • Limited Hyperparameter Tuning: The authors state that no extensive hyperparameter analysis was performed, suggesting that further optimization could yield even better results.
  • Friction Modeling: The model still shows some limitations in accurately representing friction forces, particularly in the x-direction, possibly due to the scalar gate. Further investigation into the impact of partially implementing physical effects is suggested.
  • Tool Vendor Support: The paper acknowledges that tool vendor-specific implementations of Modelica compilers and simulation capabilities might pose challenges.
  • Future Work: The authors suggest investigating the potential of the BaseModelica.jl initiative for translating Modelica models to Julia and exploring further integration with tools like ModelingToolkit.jl. They also emphasize the need for research into the optimal ratio of embedded physics-based models versus learned components for various real-world problems.

Summary updated

Abstract

Hybrid modeling – the combination of first-principle modelsand machine learning – offers the potential to increasemodel accuracy while reducing modeling effort. Althoughapproaches for creating hybrid models from systemsimulation models exist, the unique characteristics ofModelica-based, object-oriented models – such as modularityand reusability – can, as of today, not be utilized. Inthis contribution, we explore approaches for bridging thisgap to enable the use of hybrid models with Modelica. Keychallenges of architecture definition, training environmentand reintegration of the trained machine learning partsinto a Modelica model are addressed. To illustrate ourapproach, we present a case study involving a SCARA robot.This example demonstrates a partially integrated workflowfor hybrid modeling, intended to serve as a foundation andmotivation for further research.
BibTeX
@inproceedings{hofmann2025towards,
  author = {Andreas Hofmann and Lars Mikelsons},
  title = {{Towards Integration of PeN-ODEs in a Modelica-based workflow}},
  booktitle = {Linköping},
  year = {2025},
  doi = {10.3384/ecp218435},
}
Figure