Errors Encountered While Running Examples from FMIFlux.jl Documentation

I have been trying to run the examples provided in the documentation of FMIFlux.jl, loading models from FMIZoo.jl. However, I often face errors while executing the following lines of code from the documentation examples.

Consider the below example of Simple ME-NeuralFMU:

# imports
using FMI
using FMIFlux
using FMIFlux.Flux
using FMIZoo
using DifferentialEquations: Tsit5
import Plots

# set seed
import Random
Random.seed!(42);

tStart = 0.0
tStep = 0.01
tStop = 5.0
tSave = collect(tStart:tStep:tStop)
realFMU = fmiLoad("SpringFrictionPendulum1D", "Dymola", "2022x")
fmiInfo(realFMU)
initStates = ["s0", "v0"]
x₀ = [0.5, 0.0]
params = Dict(zip(initStates, x₀))
vrs = ["mass.s", "mass.v", "mass.a", "mass.f"]

realSimData = fmiSimulate(realFMU, (tStart, tStop); parameters=params, recordValues=vrs, saveat=tSave)
fmiPlot(realSimData)
velReal = fmi2GetSolutionValue(realSimData, "mass.v")
posReal = fmi2GetSolutionValue(realSimData, "mass.s")
#After extracting the data, the FMU is cleaned-up.

fmiUnload(realFMU)
simpleFMU = fmiLoad("SpringPendulum1D", "Dymola", "2022x")
fmiInfo(simpleFMU)


vrs = ["mass.s", "mass.v", "mass.a"]
simpleSimData = fmiSimulate(simpleFMU, (tStart, tStop); recordValues=vrs, saveat=tSave, reset=false)
fmiPlot(simpleSimData)
velSimple = fmi2GetSolutionValue(simpleSimData, "mass.v")
posSimple = fmi2GetSolutionValue(simpleSimData, "mass.s")
# loss function for training
function lossSum(p)
    global posReal
    solution = neuralFMU(x₀; p=p)

    posNet = fmi2GetSolutionState(solution, 1; isIndex=true)
    
    FMIFlux.Losses.mse(posReal, posNet) 
end
#every twentieth pass the loss function is called and the average error is printed out.

# callback function for training
global counter = 0
function callb(p)
    global counter += 1
    if counter % 20 == 1
        avgLoss = lossSum(p[1])
        @info "Loss [$counter]: $(round(avgLoss, digits=5))   Avg displacement in data: $(round(sqrt(avgLoss), digits=5))"
    end
end
# NeuralFMU setup
numStates = fmiGetNumberOfStates(simpleFMU)

net = Chain(x -> simpleFMU(x=x, dx_refs=:all),
            Dense(numStates, 16, tanh),
            Dense(16, 16, tanh),
            Dense(16, numStates))
neuralFMU = ME_NeuralFMU(simpleFMU, net, (tStart, tStop), Tsit5(); saveat=tSave);
solutionBefore = neuralFMU(x₀)

This last mentioned line of code throws error:

ERROR: MethodError: no method matching (::FMU2)(; x::Vector{Float64}, dx_refs::Symbol)

Closest candidates are:
(::FMU2)(; dx, y, y_refs, x, u, u_refs, p, p_refs, t) got unsupported keyword argument “dx_refs”
@ FMIImport C:\Users\Jisna.julia\packages\FMIImport\qrNjL\src\FMI2\sens.jl:72
(::Union{FMU2, FMU3, FMU2Component, FMU3Instance})(; t, kwargs…)
@ FMI C:\Users\Jisna.julia\packages\FMI\blXwo\src\FMI.jl:215

My system specifications are as follows:

Windows 10
Julia - 1.9.4+0.x64.w64.mingw32

[14a09403] FMI v0.12.4
[226f0e26] FMIBuild v0.1.16
[31b88311] FMIExport v0.2.0
[fabad875] FMIFlux v0.10.6
[9fcbc62e] FMIImport v0.15.8
[724179cf] FMIZoo v0.2.1
[587475ba] Flux v0.14.15
[f6369f11] ForwardDiff v0.10.36
[033835bb] JLD2 v0.4.49
[91a5bcdd] Plots v1.40.4
[0c46a032] DifferentialEquations v7.13.0

In addition, also consider the below example in which I try to load model from FMIZoo.jl,

# load data (training) from FMIZoo.jl
data = VLDM(:train, dt=dt) 

But this also hits me error as below:
ERROR: UndefVarError: VLDM not defined

Can someone help me with a possible fix? Thanks in advance for any suggestions!

Dear @CurioMath,

feel free to tag me if there are FMI.jl / FMIFlux.jl related questions, so I find them immediately :slight_smile:

My spec is (under Julia 1.9.4) and the posted lines do work in this setup on my machine:

  [14a09403] FMI v0.13.3
⌃ [226f0e26] FMIBuild v0.2.2
⌅ [8af89139] FMICore v0.20.1
  [31b88311] FMIExport v0.3.2
  [fabad875] FMIFlux v0.12.2
⌅ [9fcbc62e] FMIImport v0.16.4
⌃ [724179cf] FMIZoo v0.3.3

Please try updating, to the current releases except for FMIZoo.jl, which is required to be v0.3.3.

For the second question, it’s data = FMIZoo.VLDM(:train, dt=dt) now. I will change that in the examples. Examples need some updates. You can keep track of progress with this issue.

Best regards!