GithubHelp home page GithubHelp logo

thummeto / fmiimport.jl Goto Github PK

View Code? Open in Web Editor NEW
17.0 5.0 15.0 667 KB

FMIImport.jl implements the import functionalities of the FMI-standard (fmi-standard.org) for the Julia programming language. FMIImport.jl provides the foundation for the Julia packages FMI.jl and FMIFlux.jl.

License: MIT License

Julia 99.27% C++ 0.24% C 0.31% CMake 0.18%
fmi fmu import julia

fmiimport.jl's People

Contributors

adribrune avatar stoljarjo avatar thummeto avatar ven-k avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar

fmiimport.jl's Issues

Option to set log level

I'm using FMI.jl (and therefore FMIImport.jl) to simulate OpenModelica FMUs.
When running fmu = FMI.fmiLoad(fmuPath) I'm getting a bunch of info messages about empty files.

julia> fmu = FMI.fmiLoad(fmuPath)
[ Info: fmi2Unzip(...): Written file `binaries/linux64/simpleLoop_FMU.libs`, but file is empty.
[ Info: fmi2Unzip(...): Written file `sources/simpleLoop_11mix.h`, but file is empty.
[ Info: fmi2Unzip(...): Written file `sources/simpleLoop_includes.h`, but file is empty.
[ Info: fmi2Unzip(...): Written file `sources/simpleLoop_FMU.libs`, but file is empty.
[ Info: fmi2Unzip(...): Written file `sources/isfmi2`, but file is empty.
[ Info: fmi2Unzip(...): Successfully unzipped 229 files at `/tmp/fmijl_HTprAI/simpleLoop.interface`.
[ Info: fmi2Load(...): FMU resources location is `file:////tmp/fmijl_HTprAI/simpleLoop.interface/resources`

It would be nice to get the option to disable info prints from all and/or specific parts of FMImport.jl with some setting in FMI.jl.

My workaround for the moment is to use Suppressor.jl

local fmu
Suppressor.@suppress begin
  fmu = FMI.fmiLoad(fmuPath)
end

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!

Bug: prepareValue for non-standard vectors

Hi, I'm using FMIImport in part of my simulations, and ran into some issues here. I'm running my own simulation loop (so not the standard fmiSimulate function) but I copied parts of that loop in FMI.jl. To set the inputs when calling the fmu I use something akin to the following:

sim!(fmu::FMU2, c::FMU2Component, u::AbstractArray, t::Real, dt::Real)
    md = fmu.modelDescription
    fmi2SetReal(c, md.inputValueReferences, u)
    fmi2DoStep(c, dt; currentCommunicationPoint=t)
    return fmi2GetReal(fmu, md.outputValueReferences)
end

The issue is that fmi2SetReal only works with non-abstract vectors for the values argument. In my case, values is a view of an array, then the call fmi2SetReal(c::FMUComponent, vr::Vector{UInt32}, values::SubArray{Float64, 1, ...}) throws the following error

AssertionError: fmi2SetReal(...): `vr` (4) and `values` (1) need to be the same length.

The culprit is the[prepareValue function in FMIImport.jl, which transforms values::SubArray to a vector with 1 element values::Vector{SubArray}. values fails the check isa(values, Array). When I override this implementation (see below) my sim! function runs perfectly. Note that Array has been replaced by AbstractArray

function FMIImport.prepareValue(value)
    if isa(value, AbstractArray) && length(size(value)) == 1
        return value
    else
        return [value]
    end

    @assert false "prepareValue(...): Unknown dimension of structure `$dim`."
end 

A multiple dispatch solution may be a bit more elegant though.

FMIImport.prepareValue(value) = [value]
FMIImport.prepareValue(value::AbstractVector) = value

Return type of `fmi2GetNames`

fmi2GetNames returns a vector of Any. It should return a vector of strings as they are list of names. This affects for simulating as well.

MWE:

using FMI
using FMIImport

fmu = FMI.fmi2Load("CoupledClutches.fmu")
output_names = FMIImport.fmi2GetOutputNames(fmu)
sol = FMI.fmi2Simulate(fmu; recordValues=output_names)

gives an error:

ERROR: TypeError: in keyword argument recordValues, expected Union{Nothing, Int64, UInt32, AbstractVector{Int64}, AbstractVector{String}, AbstractVector{UInt32}, String, Symbol}, got a value of type Vector{Any}

Here output_names should return a vector of strings

Incremental compilation fatally broken

When pre-compiling my package I get warnings that method definitions are overwritten:

WARNING: Method definition fmi2GetStartValue(FMICore.FMU2Component, Union{Nothing, Int64, UInt32, AbstractArray{Int64, 1}, AbstractArray{String, 1}, AbstractArray{UInt32, 1}, String, Symbol}) in module FMIImport at /path/to/FMIImport/snZaf/src/FMI2_int.jl:706 overwritten at path/to/FMIImport/snZaf/src/FMI2_ext.jl:708.
  ** incremental compilation may be fatally broken for this module **

And indeed there are two definitions for fmi2GetStartValue: https://github.com/ThummeTo/FMIImport.jl/blob/main/src/FMI2_ext.jl#L690 and https://github.com/ThummeTo/FMIImport.jl/blob/main/src/FMI2_int.jl#L706.

Same issue for fmi2GetNamesAndInitials

WARNING: Method definition fmi2GetNamesAndInitials(FMICore.fmi2ModelDescription) in module FMIImport at /path/to/FMIImport/snZaf/src/FMI2_md.jl:1055 overwritten at /path/to/FMIImport/snZaf/src/FMI2_md.jl:1068.
  ** incremental compilation may be fatally broken for this module **

Error while loading FMI3 FMU

While trying to load an fmu get the following error

ERROR: UndefVarError: fmi3ProvidesDirectionalDerivatives not defined
Stacktrace:
 [1] fmi3Load(pathToFMU::String; unpackPath::Nothing)
   @ FMIImport ~/.julia/packages/FMIImport/jYeff/src/FMI3_ext.jl:161
 [2] fmi3Load(pathToFMU::String)
   @ FMIImport ~/.julia/packages/FMIImport/jYeff/src/FMI3_ext.jl:20
 [3] top-level scope
   @ REPL[2]:1

It seems a typo here

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.