FMIFlux.jl
FMIFlux.jl copied to clipboard
Function must be called in mode continuous time
Hi, currently I encounter an error when calling a ME_NeuralFMU` in loss function
function lossSum(p)
global neuralFMU, x₀, params, counter
params = Dict(zip(Vector{String}(modified_Variables), Vector{Float64}(p.value)))
solution = neuralFMU(x₀; parameters=params, p=p, showProgress=true, saveat=tSave, recordValues=vrs) #** this asserts the error message**
if !solution.success
return Inf
end
# id_Net, iq_Net = extractData(solution)
id_Net = fmi2GetSolutionValue(solution, 1; isIndex=true)
iq_Net = fmi2GetSolutionValue(solution, 2; isIndex=true)
loss_value = FMIFlux.Losses.mse(id_Net, id_Data) + FMIFlux.Losses.mse(iq_Net, iq_Data)
return loss_value
end
The error message is:
ERROR: AssertionError: condition!(...): 5 != 3
Function must be called in mode continuous time!
This is most probably because the FMU errored before. If no melected during export) and follow the message printing instru
After tracing the code, I found that this error caused by the assertion in https://github.com/ThummeTo/FMIFlux.jl/blob/main/src/neural.jl#L378, where c.state=5
but fmi2ComponentStateContinuousTimeMode=3
thus I trace the code to find when the c.state is been changed from 3 to 5, and I found that it occurs at https://github.com/ThummeTo/FMIImport.jl/blob/main/src/FMI2/c.jl#L1937 because the status
returned by fmi2CompletedIntegratorStep!(c.fmu.cCompletedIntegratorStep, c.addr, noSetFMUStatePriorToCurrentPoint, enterEventMode, terminateSimulation,)
is 3
and thus trigger the c.state = fmi2ComponentStateError
in https://github.com/ThummeTo/FMIImport.jl/blob/main/src/FMI2/c.jl#L132 to assign 5
to c.state
I am not sure why the status
returned by fmi2CompletedIntegratorStep!
is 3
, is there any suggestion to solve this issue?
If more information is needed, please tell me, thanks!