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

Usage of an input-function in the FMU-layer of a Chain is not possible, yet #132

Open
juguma opened this issue Mar 11, 2024 · 1 comment

Comments

@juguma
Copy link

juguma commented Mar 11, 2024

Please provide an example (and presumably missing functionality) to include an input-function into the FMU-layer of an FMIFlux.Chain.
This is crucial when you work with FMUs that only create reasonable output with nonzero input.

Remark:

  1. I know there are several options to define an input-function to an FMU:
    inputFunction!(t::T, u::AbstractArray{<:T})
    inputFunction!(comp::FMU2Component, t::T, u::AbstractArray{<:T})
    inputFunction!(comp::FMU2Component, x::Union{AbstractArray{<:T,1}, Nothing}, u::AbstractArray{<:T})
    inputFunction!(x::Union{AbstractArray{<:T,1}, Nothing}, t::T, u::AbstractArray{<:T})
    inputFunction!(comp::FMU2Component, x::Union{AbstractArray{<:T,1}, Nothing}, t::T, u::AbstractArray{<:T})
    However I am not sure, if support of the more complex function types (i.e. those which do not only depend on t) are actually relevant for many users.
    I would be happy, if a purely time-dependent input function was supported.

  2. When extending functionality, please keep in mind that in batched training one might want to use different inputs on different batches. (..as we discussed for the batch-wise parameters. This might be worth a second ticket, once this one is finished).

@juguma
Copy link
Author

juguma commented Jun 3, 2024

As an update: I found a workaround for this one.
If you are the owner of the FMU, you can export this FMU with a variable being equal to the (simulation) time.
E.g. in Modelica:
Real mytime = time:
Export this variable together with the FMU.
Then, in julia, you can "use" this variable via fmiGetReal(fmu.components[end],"mytime"), e.g. to define the "t" in the FMU-call:
myFMU(;x=x,dx_refs=:all, t = fmiGetReal(fmu.components[end],"mytime"))
or, to define an input function:
myFMU(;x=x,dx_refs=:all,u_refs = my_input_refs, u = inputFctOOP(fmiGetReal(fmu.components[end],"mytime"))
Remark (for myself 😏): For this, the inputFct which you define for your FMU (which by the FMI.jl-requirements should be in-place, see above), has to be rewritten as its out of place (OOP) variant.

One should be very well aware that this is really only a workaround (an ugly but working one).
It's no excuse for not implementing this feature 🙃.

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

1 participant