Giter VIP home page Giter VIP logo

fmiexport.jl's People

Contributors

github-actions[bot] avatar stoljarjo avatar thummeto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

fmiexport.jl's Issues

problem with fmu when using fluent

when I use fluent to simulate by using fmu,there is something wrong with it and show me some message:
From test-0: stepping - Error test_fmi2DoStep: Current communication point ( 5.999999865889549255e-02 s) does not match last evaluation time ( 0.000000000000000000e+00 s) within tolerance 9.999999999999999547e-08. Time rollback is not allowed
and fluent cannot send data to fmu model

BouncingBall FMU export example fails in Ubuntu

I am really excited about the possibilities with the FMIExport julia library. I wanted to quickly try to out the BouncingBall example. But got into some trouble while running the example.

image

I am running

  • Ubuntu 18.04
  • Julia 1.8. 3 (I even tried Julia 1.6.7, but with no luck)

I appreciate any your support from your side

simple_fmi2Instantiate fails on compiled FMU

Updated all packages. Turned out I was using a local dev package to try and diagnose the issue. Now the issue is:
MethodError(f=FMICore.FMU2Component{F} where F, args=(), world=0x0000000000007a7c) jl_method_error_bare at /cygdrive/c/buildbot/worker/package_win64/build/src\gf.c:1821 jl_method_error at /cygdrive/c/buildbot/worker/package_win64/build/src\gf.c:1839 jl_lookup_generic_ at /cygdrive/c/buildbot/worker/package_win64/build/src\gf.c:2410 jl_apply_generic at /cygdrive/c/buildbot/worker/package_win64/build/src\gf.c:2425 simple_fmi2Instantiate at D:\Julia\Packages\packages\FMIExport\1ciLm\src\FMI2_simple.jl:156 unknown function (ip: 0000023b28c7c618) ...

Originally posted by @markilg in #14 (comment)

Provide simple example

Hi all,

is it possible to provide a simple example of a julia generated model exchange fmu that i could include to my Modelica model.

The input should be u and the output y = asin(bu). The values a and b are constant parameters.

kind regards
Simon

Error when running BouncingBall example

When I try to run the bouncing ball example from here, I get the error message below. Disclaimer: I am new to Julia :)

I am on Julia 1.9 on windows.

ERROR: BoundsError: attempt to access Tuple{Float64, Vector{Float64}, Vector{Float64}, Vector{Any}, Vector{Float64}} at index [6]
Stacktrace:
[1] indexed_iterate(t::Tuple{Float64, Vector{Float64}, Vector{Float64}, Vector{Any}, Vector{Float64}}, i::Int64, state::Int64)
@ Base .\tuple.jl:88
[2] fmi2CreateSimple(; initializationFct::Function, evaluationFct::Function, outputFct::Function, eventFct::Function)
@ FMIExport C:\Users\seberlein.julia\packages\FMIExport\j8bGN\src\FMI2_simple.jl:548
[3] (::var"#51#52")(resPath::String)
@ Main d:\User\seberlein\Julia\FMI\bouncing_ball_example_from_github_FMIExport.jl:80
[4] (::var"#51#52")()
@ Main d:\User\seberlein\Julia\FMI\bouncing_ball_example_from_github_FMIExport.jl:80
[5] top-level scope
@ d:\User\seberlein\Julia\FMI\bouncing_ball_example_from_github_FMIExport.jl:111

EDIT: Here is the solution:
"Now I see! You copied the file and placed it in a different location! FMIExport compiles on basis of packages, so the file must be part f a Julia package structure (e.g. you need the Project.toml and so on). If you want to do your own thing, just copy the entire package named "BaouncingBall" instead of just the single file!"

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

Create FMU with simple PT1 model

I don't want to bombard you with issues, you can also guide me to some documents to improve my general understanding of the FMI if they are helpful for the practical implementation in FMIExport.

I'm trying to create an FMU with a simple PT1 model. I tried to stay as close as possible to the bouncing ball example. I added an event although there are no events, but if I don't define an eventFct then an error is thrown. There are also no discrete states.

From the error message (below) I figure that there might be something wrong with FMU_FCT_OUTPUT, but I don't understand what exactly is happening. Help is much appreciated.

Code:

using FMIExport 
using FMIExport.FMICore: fmi2True, fmi2False 

FMU_FCT_INIT = function()
    T = 1.0         # time constant 
    t = 0.0       
    x = [0.0]      
    ẋ = [0.0]
    x_d = [] 
    u = [0.0]
    p = [T]

    return (t, x, ẋ, x_d, u, p)
end

FMU_FCT_EVALUATE = function(t, x, ẋ, x_d, u, p, eventMode)
    T = (p...,)
    old_state = (x...,)

    derivative = (u[0] - old_state)/T

    x = [old_state]
    ẋ = [derivative]
    p = [T]
    x_d = [] 

    return (x, ẋ, x_d, p)
end

FMU_FCT_OUTPUT = function(t, x, ẋ, x_d, u, p)
    state = (x...,)
    y = [state]
    return y
end

FMU_FCT_EVENT = function(t, x_c, ẋ_c, x_d, u, p)
    return [0.0]
end

FMIBUILD_CONSTRUCTOR = function(resPath=".")
    fmu = fmi2CreateSimple(initializationFct=FMU_FCT_INIT,
                        evaluationFct=FMU_FCT_EVALUATE,
                        outputFct=FMU_FCT_OUTPUT,
                        eventFct=FMU_FCT_EVENT)

    fmu.modelDescription.modelName = "PT1"
    # modes 
    fmi2ModelDescriptionAddModelExchange(fmu.modelDescription, "PT1")

    fmi2AddStateAndDerivative(fmu, "PT1.state"; stateDescr="state", derivativeDescr="state derivative")
    fmi2AddRealOutput(fmu, "PT1.state"; description="state")
    fmi2AddRealParameter(fmu, "T";     description="Time constant")

    fmi2AddEventIndicator(fmu)

    return fmu
end

tmpDir = mktempdir(; prefix="fmibuildjl_test_", cleanup=false) 
@info "Saving example files at: $(tmpDir)"
fmu_save_path = joinpath(tmpDir, "BouncingBall.fmu")  

fmu = FMIBUILD_CONSTRUCTOR()

Error:
ERROR: MethodError: Cannot convert an object of type
Tuple{Float64} to an object of type
Union{Float64, Int32}

Closest candidates are:
convert(::Type{T}, ::Union{Static.StaticBool{N}, Static.StaticFloat64{N}, Static.StaticInt{N}} where N) where T<:Number
@ Static C:\Users\seberlein.julia\packages\Static\dLrtk\src\Static.jl:414
convert(::Type{<:Number}, ::SciMLOperators.AddedScalarOperator)
@ SciMLOperators C:\Users\seberlein.julia\packages\SciMLOperators\hFLNz\src\scalar.jl:243
convert(::Type{T}, ::AbstractChar) where T<:Number
@ Base char.jl:185
...

Stacktrace:
[1] setindex!(h::Dict{UInt32, Union{Float64, Int32}}, v0::Tuple{Float64}, key::UInt32)
@ Base .\dict.jl:369
[2] applyValues(_component::Ptr{Nothing}, xc::Vector{Float64}, ẋc::Vector{Float64}, xd::Vector{Any}, u::Vector{Float64}, y::Vector{Tuple{Float64}}, p::Vector{Float64})
@ FMIExport C:\Users\seberlein.julia\packages\FMIExport\j8bGN\src\FMI2_simple.jl:113
[3] reset(_component::Ptr{Nothing})
@ FMIExport C:\Users\seberlein.julia\packages\FMIExport\j8bGN\src\FMI2_simple.jl:45
[4] simple_fmi2Instantiate(instanceName::Ptr{UInt8}, fmuType::UInt32, fmuGUID::Ptr{UInt8}, fmuResourceLocation::Ptr{UInt8}, functions::Ptr{FMICore.fmi2CallbackFunctions}, visible::Int32, loggingOn::Int32)
@ FMIExport C:\Users\seberlein.julia\packages\FMIExport\j8bGN\src\FMI2_simple.jl:170
[5] fmi2Instantiate(cfunc::Ptr{Nothing}, instanceName::Ptr{UInt8}, fmuType::UInt32, fmuGUID::Ptr{UInt8}, fmuResourceLocation::Ptr{UInt8}, functions::Ptr{FMICore.fmi2CallbackFunctions}, visible::Int32, loggingOn::Int32)
@ FMICore C:\Users\seberlein.julia\packages\FMICore\l1OAc\src\FMI2\cfunc.jl:20
[6] (::FMIImport.var"#74#75"{String, UInt32, Bool, Bool, Bool, FMU2, String, FMICore.fmi2CallbackFunctions, FMICore.FMU2ComponentEnvironment})()
@ FMIImport C:\Users\seberlein.julia\packages\FMIImport\7xJzL\src\FMI2\ext.jl:509
[7] lock(f::FMIImport.var"#74#75"{String, UInt32, Bool, Bool, Bool, FMU2, String, FMICore.fmi2CallbackFunctions, FMICore.FMU2ComponentEnvironment}, l::ReentrantLock)
@ Base .\lock.jl:229
[8] fmi2Instantiate!(fmu::FMU2; instanceName::String, type::UInt32, pushComponents::Bool, visible::Bool, loggingOn::Bool, externalCallbacks::Bool, logStatusOK::Bool, logStatusWarning::Bool, logStatusDiscard::Bool, logStatusError::Bool, logStatusFatal::Bool, logStatusPending::Bool)
@ FMIImport C:\Users\seberlein.julia\packages\FMIImport\7xJzL\src\FMI2\ext.jl:506
[9] fmi2Instantiate!
@ C:\Users\seberlein.julia\packages\FMIImport\7xJzL\src\FMI2\ext.jl:447 [inlined]
[10] (::FMIImport.var"#12#13"{Nothing, Bool, typeof(FMIImport.handleEvents), FMU2, UInt32, Nothing, Float64, Float64, Nothing})()
@ FMIImport C:\Users\seberlein.julia\packages\FMIImport\7xJzL\src\FMI2\prep.jl:67
[11] ignore_derivatives
@ C:\Users\seberlein.julia\packages\ChainRulesCore\7MWx2\src\ignore_derivatives.jl:26 [inlined]
[12] #prepareSolveFMU#11
@ C:\Users\seberlein.julia\packages\FMIImport\7xJzL\src\FMI2\prep.jl:39 [inlined]
[13] fmi2SimulateME(fmu::FMU2, c::Nothing, tspan::Tuple{Float64, Float64}; tolerance::Nothing, dt::Nothing, solver::Nothing, customFx::Nothing, recordValues::Nothing, recordEventIndicators::Nothing, recordEigenvalues::Bool, saveat::Nothing, x0::Nothing, setup::Nothing, reset::Nothing, instantiate::Nothing, freeInstance::Nothing, terminate::Nothing, inputValueReferences::Nothing, inputFunction::Nothing, parameters::Nothing, dtmax::Float64, callbacksBefore::Vector{Any}, callbacksAfter::Vector{Any}, showProgress::Bool, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ FMI C:\Users\seberlein.julia\packages\FMI\iK3kv\src\FMI2\sim.jl:453
[14] fmi2SimulateME
@ C:\Users\seberlein.julia\packages\FMI\iK3kv\src\FMI2\sim.jl:363 [inlined]
[15] #fmi2SimulateME#8
@ C:\Users\seberlein.julia\packages\FMI\iK3kv\src\FMI2\comp_wraps.jl:38 [inlined]
[16] fmi2SimulateME
@ C:\Users\seberlein.julia\packages\FMI\iK3kv\src\FMI2\comp_wraps.jl:37 [inlined]
[17] #fmiSimulateME#292
@ C:\Users\seberlein.julia\packages\FMI\iK3kv\src\FMI.jl:851 [inlined]
[18] top-level scope
@ d:\User\seberlein\Julia\FMI\src\simple_PT1_example.jl:68

Exporting a trained neural network as an FMU

Hi,
Let us assume I have the parameters of a neural network that I have trained using the neural ODE framework. Is it possible for me to use this package to export it as an FMU?

I have spent some time trying to understand the examples. I think the NeuralFMU example is more complicated than what I need. I think I might need to make my code from a mix of the bouncing ball example and the neural FMU example.

I have not yet figured out how I would load the parameters into the code and export it as an FMU. (Any advice is appreciated!)

But before I attempt to work further on it, I wanted to verify if I can even accomplish my requirement with the package 😄

Looking forward to your response!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.