Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function must be called in mode continuous time #156

Open
awecefil opened this issue Sep 26, 2024 · 1 comment
Open

Function must be called in mode continuous time #156

awecefil opened this issue Sep 26, 2024 · 1 comment

Comments

@awecefil
Copy link

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!

@ThummeTo
Copy link
Owner

ThummeTo commented Oct 15, 2024

Good, that you already have a hot trace!

A good FMU prints a helpful error message, when returning fmi2StateError. You can enable displaying logs from the FMU as explained here

using:

myFMU.executionConfig.loggingOn=true
myFMU.executionConfig.externalCallbacks=true

Best!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants