# Errors Encountered While Running Examples from FMIFlux.jl Documentation

**URL:** <https://discourse.julialang.org/t/errors-encountered-while-running-examples-from-fmiflux-jl-documentation/116905>\
**Category:** General Usage\
**Tags:** package, flux, differentialequation, fmiexport, modelling\
**Created:** [July 11, 2024, 11:55am UTC](https://discourse.julialang.org/t/errors-encountered-while-running-examples-from-fmiflux-jl-documentation/116905 "2024-07-11T11:55:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![CurioMath](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/curiomath/32/43603_2.png) [@CurioMath](https://discourse.julialang.org/u/CurioMath)\
**Post date:** [July 11, 2024, 11:55am UTC](https://discourse.julialang.org/t/errors-encountered-while-running-examples-from-fmiflux-jl-documentation/116905/1 "2024-07-11T11:55:13Z")

</div>

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:

```julia
# 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,

```julia
# 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!

---

<div class="post-metadata">

**Author:** ![ThummeTo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thummeto/32/26105_2.png) [@ThummeTo](https://discourse.julialang.org/u/ThummeTo)\
**Post date:** [July 12, 2024, 11:36am UTC](https://discourse.julialang.org/t/errors-encountered-while-running-examples-from-fmiflux-jl-documentation/116905/2 "2024-07-12T11:36:06Z")

</div>

Dear @CurioMath,

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

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

```julia
  [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](https://github.com/ThummeTo/FMIFlux.jl/issues/141).

Best regards!
