ThummeTo / FMIFlux.jl

FMIFlux.jl is a free-to-use software library for the Julia programming language, which offers the ability to place FMUs (fmi-standard.org) everywhere inside of your ML topologies and still keep the resulting model trainable with a standard (or custom) FluxML training process.
MIT License
57 stars 15 forks source link

Concatenate multiple FMUs with NN #139

Closed awecefil closed 4 months ago

awecefil commented 4 months ago

Problem Description:

I want to know if FMIFlux can currently chain multiple FMUs and NNs together. For example, I have constructed a circuit system in OpenModelica that includes a voltage source and a resistor. Using OpenModelica, I split this system into three subsystems (voltage source, resistor, and ground), and exported each as an independent FMU. I then tried importing these three subsystem FMUs into OpenModelica and connecting their inputs/outputs for simulation. Unsurprisingly, the simulation results were the same as the original circuit system. Diagram as follow, from left to right, it sequentially shows the Voltage Source FMU, Resistor FMU, and Ground FMU: image

Now, I want to know two things:

  1. Is it possible to achieve the same functionality described above in FMIFlux or other FMI packages?
  2. Is it possible in FMIFlux to chain NNs and multiple FMUs together? For example, I want to replace the original linear resistor with an NN and use training data to simulate a nonlinear resistor.

Current Attempts:

I found that FMIFlux currently supports using Parallel to chain multiple FMUs and NNs (via Chain). However, after looking into it in detail, I discovered that the Parallel function allows multiple FMUs to run concurrently and produce results. We can then concatenate the results or perform other operations like summation. However, this is different from sequentially chaining multiple subsystem FMUs as I intend.

If there is any misunderstanding on my part, please correct me. Thank you.

ThummeTo commented 4 months ago

Exactly, there are two to different operation modes:

As you correctly noticed, the parallel example simulates the FMUs in CS-mode. From the text, it sounds like you want to do "model-integration", but importing FMUs in OpenModelica and simulate them together sounds like co-simulation to me....

Can you specify: (a) if you want to operate in CS or ME mode? (b) if ME: if you want to use the same solver for both FMUs (model integration) or different solvers for every FMU. (c) do you want to connect states/state derivatives or inputs/outputs

In any case I think there is a solution for your problem, but it is easier to discuss if we further specify.

Best regards!

PS: I convert this to discussion :-)