This example for NonLinearSystemNeuralNetworkFMU.jl is using DrWatson to make a reproducible example named SimpleLoop.
Authors: Andreas Heuermann, Philip Hannebohm.
These scripts were used to generate the plots and animations for the presentation Accelerating the simulation of equation based models by replacing non linear algebraic loops with error controlled machine learning surrogates at MODPROD 2023.
Warning
Only tested on Ubuntu. It is very unlikely that these scripts will work on Windows and impossible on MacOS.
Note
The dependencies are a nightmare. While this could work with later versions of dependent packages most likely it's easier to install the exact versions specified in Manifest.toml.
To (locally) reproduce this project, do the following:
-
Make sure you have local Julia package NaiveONNX in ../NaiveONNX.jl. If not update your git submodule with
$ git submodule update --force --init --recursive
-
Open a Julia console and run:
julia> using Pkg julia> Pkg.add("DrWatson") # install globally, for using `quickactivate` julia> Pkg.activate("examples/SimpleLoop/") julia> Pkg.instantiate()
-
To create plots with CairoMakie an X-server has to be available. So the environmental variable
DISPLAY
has to be set.If you are using ssh to connect to a remote machine use
ssh -X [email protected]
. Check your Julia session has the variable available or set it:julia> ENV["DISPLAY"] julia> ENV["DISPLAY"] = "localhost:10.0"
-
OpenModelica: Tested omc version v1.21.0-dev-288-g01b6764df5-cmake with OMSimulator version OMSimulator v2.1.1.post194-g75de4c6-linux-debug.
This will install all necessary packages for you to be able to run the scripts and everything should work out of the box, including correctly finding local paths.
You may notice that most scripts start with the commands:
using DrWatson
@quickactivate "SimpleLoop"
which auto-activate the project and enable local path handling from DrWatson.
The Modelica model SimpleLoop is defined in src/simpleLoop.mo. It describes a moving line and growing circle and has a non-linear system solving for the intersection points of the two.
for unknown coordinates x
and y
.
You can run
include("scripts/runall.jl")
to run all scripts or read along to see what the scripts are doing.
Run script scripts/SimpleLoop_example.jl to generate four
FMU surrogates based on N ∈ {100, 500, 750, 1000}
data points.
julia> include("scripts/SimpleLoop_example.jl")
The resulting FMUs can be found in data/sims/fmus/simpleLoop.onnx_NXXX.fmu.
After the FMUs are generated the plots and animations can be created.
Run script scripts/SimpleLoop_intersection.jl to generate a animation of the circle and line.
julia> include("scripts/SimpleLoop_intersection.jl")
The resulting animation can be found in plots/SimpleLoop_intersection.gif.
Run script scripts/SimpleLoop_dataGenPlots.jl to generate plots showing how the solution of SimpleLoop model isn't unique and how to filter it.
julia> include("scripts/SimpleLoop_dataGenPlots.jl")
The resulting plots can be found in plots/SimpleLoop_data.svg and plots/SimpleLoop_data_filtered.svg.
To compare the results of the four surrogates with the expected results of y
run
the script scripts/SimpleLoop_simresults.jl.
julia> include("scripts/SimpleLoop_simresults.jl")
The generated plot can be found in plots/SimpleLoop_simresults_y.svg.