Git Product home page Git Product logo

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

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!

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

fmi2SetDebugLogging is not working properly

The FMIImport-function fmi2SetDebugLogging can't be used to activate logging - the type of the last argument is ::Ptr{Nothing} which is at least not very intuitive to fill.

Furthermore, the fmi2ModelDescription in FMIImport lacks the info about the logCategories, even if they exist in the modelDescription.

Below and attached are a script and an FMU which demonstrate and solve the problem. The FMU was explicitly prepared to print messages for the different logcategories and with a different fmi2Status (to show that the printed fmi2Status and the logCategories work independently). All the extra Messages were added to "fmi2SetupExperiment", hence this function is run several time.

using FMI
using FMIImport
using FMIImport: fmi2SetDebugLogging
import FMIImport.FMICore: FMUComponent

FMUPath = "LorenzTwice.fmu"
fmu = fmiLoad(FMUPath)

fmu.modelDescription.logCategories = ["logStatusOKInfo", "logStatusWarning", "logStatusOKDebug","logStatusError","logAll"]  
#<-further down: proposal how to fill these values from modelDescription during fmiLoad

fmu.executionConfig.loggingOn = false
c = fmi2Instantiate!(fmu; type=UInt32(0))

#the FMIImport-function:
#fmi2SetDebugLogging(c,1,1,["LogStatusOKWarning"])
#can't be used to activate logging - the type of the last argument is ::Ptr{Nothing} which is at least not very intuitive to fill

#go more low-level (in FMICore):
#status = fmi2SetDebugLogging(c.fmu.cSetDebugLogging, c.compAddr, logginOn, nCategories, categories)

# set all categories to false:
status = fmi2SetDebugLogging(c.fmu.cSetDebugLogging, c.compAddr, Int32(0), UInt64(0), [pointer("this argument is not used here")])
#<-works

#switch on one category at once and see the output:
lcs = fmu.modelDescription.logCategories
for lc in lcs
    @info lc
    status = fmi2SetDebugLogging(c.fmu.cSetDebugLogging, c.compAddr, Int32(1), UInt64(1), [pointer(lc)])
    fmi2SetupExperiment(c,0.0,0.1)
    status = fmi2SetDebugLogging(c.fmu.cSetDebugLogging, c.compAddr, Int32(0), UInt64(1), [pointer(lc)])
end
#<-this works as expected


#hence modify the last argument of the FMIImport-function
#proposal:
function FMIImport.fmi2SetDebugLogging(c::FMU2Component, loggingOn::fmi2Boolean, nCategories::Unsigned, categories::Vector{String})
    @info "This is the redefined fmi2SetDebugLogging from FMIImport"
    #<remove this line prior to commit
    status = fmi2SetDebugLogging(c.fmu.cSetDebugLogging, c.compAddr, loggingOn, nCategories, [pointer(cat) for cat in categories])      
end

#such that the following call sequence returns the same output:
status = fmi2SetDebugLogging(c, Int32(0), UInt64(0), ["this argument is not used here"])

#switch on one category at once and see the output:
for lc in lcs
    @info lc
    status = fmi2SetDebugLogging(c, Int32(1), UInt64(1), [lc])
    fmi2SetupExperiment(c,0.0,0.1)
    status = fmi2SetDebugLogging(c, Int32(0), UInt64(1), [lc])
end
#<- this works :-)

#######
# what remains:
# how to add logCategories to fmu.modelDescription
# node logCatgegories can contain an array of "Category" (0..n), each Category having a "name" and a "description"
# extend function fmi2LoadModelDescription(pathToModelDescription::String) from FMIImport
using FMI: fmi2ModelDescription
using FMIImport: parseNodeString


md = fmu.modelDescription
using EzXML
pathToModelDescription = fmu.path*"\\modelDescription.xml"
doc = readxml(pathToModelDescription)
root = doc.root

# defaults
 md.logCategories = nothing
#<- add this line to fmi2LoadModelDescription (not necessary, since already set to nothing in struct constructor)

#->define the function parseLogCategories (Variants 2 and 3 below)
#Variant 1: only return category names as an array(, least informative but sufficient)
#advantage:cheapest to write, easiest to read names from
#disadvantage: no description info
function parseLogCategories(nodes::EzXML.Node, md::fmi2ModelDescription)
    categories = Array{String, 1}()

    for node in eachelement(nodes)
        push!(categories,node["name"])
    end
    categories
end


for node in eachelement(root)
    if node.name == "LogCategories" 
        md.logCategories = parseLogCategories(node,md)
    end
end
#<-add case in loop over nodes in fmi2LoadModelDescription


##################################################################
# alternatives for parseLogCategories:

#Variant 2: return names and description as a Dictionary
#advantage: all information, nicely ordered, names to get via keys(a)
#disadvantage: fmi2ModelDescription: logCategories type needs to be changed
function parseLogCategories(nodes::EzXML.Node, md::fmi2ModelDescription)
    categories = Dict{String, String}()

    for node in eachelement(nodes)
        categories[node["name"]]=node["description"]
    end
    categories
end



#Variant 3: defining a separate struct.
#advantage: no need to change fmi2ModelDescription struct (since an Array of Category(es) is returned)
#disatvantage: hard to read "names" later on
mutable struct Category
    # mandatory
    name::Union{String, Nothing}
    # optional
    description::Union{String, Nothing}

    function Category()
        inst = new()
        inst.name = nothing 
        inst.description = nothing
        return inst
    end
end
function parseLogCategories(nodes::EzXML.Node, md::fmi2ModelDescription)
    categories = Array{Category, 1}()
    for node in eachelement(nodes)
        category = Category()
        # mandatory 
        category.name = node["name"]
        # optional
        category.description = parseNodeString(node, "description")       
        push!(categories,category)
    end
    categories
end

Based on what you prefer and the status of upcomping package updates, feel free to simply add the proposed modifications yourself (since at least Variant 2 would involve modifications in FMI as well), or let me know if you prefer a pull request.

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

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

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

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 **

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.