Giter VIP home page Giter VIP logo

fmicore.jl's People

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

fmicore.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!

FMU throws unjustified assert when called with and without y_refs in a sequence (presumably same for ec_idcs and dx_refs)

When you call your loaded fmu with different arguments for y_refs in a sequence (first call with y_refs, second without y_refs), an assert is thrown claiming that the lenghts of y_refs and y should be equal.
The first call enters the if-condition (if length(y_refs)>0) and allocates the c.default_y and sets y equal to it. The second does not enter this condition, hence does not re-allocate c.default_y, but then compares y (the old y=c.default_y!?) to the new y_refs' length.
Since y is used again later (e.g. in 274) if length(y)>0, it should be allocated in every call correctly, i.e.

  1. y_refs exists, y exist <- check lengths, assert if unequal
  2. y_refs exist, no y in arguments <- allocate y with length of y_refs
  3. no y_refs, but y <-assert that no y_refs is there, that is basically 1.
  4. no y_refs, no y <- allocate y with length zero, i.e. like 2.

So what about:

if length(y) > 0
    @assert (length(y) == length(y_refs)) "Length of `y` must match length of `y_refs`."
else
    y = zeros(fmi2Real, length(y_refs))
    if length(y_refs)>0
        logInfo(c.fmu, "Automatically allocated `y` for given `y_refs`")
    end 
end

I have to admit, I didn't get the point of having default_y, so my proposal might be nonsense.
Here's a minimal example:

using FMI
using FMI:fmi2ValueReference
using FMIZoo

tSave = 0.0:0.01:8.0
fmu = fmiLoad("SpringPendulumExtForce1D", "Dymola", "2022x"; type=:ME) 
fmiSimulate(fmu,(tStart,tStop)) #<-you need this (or something smarter) to generate a fmu-component before calling the fmu below. That's another bug in my opinion.

outputVRs = UInt32[]
for vr in fmu.modelDescription.outputValueReferences
    push!(outputVRs, vr)
end

#1st call, with y_refs
fmu(;y_refs=outputVRs)

#2nd call, w/o y_refs -> assert
fmu()

#workaround...
length(fmu.components[1].default_y)
fmu.components[1].default_y=zeros(fmi2Real,0)
fmu()

function Base.getindex(out::FMU2EvaluationOutput, ind) is not prepared when ind is a vector of indices

Base.getindex is called when the input arguments are an FMU2EvaluationOutput (out) and anything but not a CartesianIndex{A}.
In the example below, ind is a vector of indices.

Minimal example

import FMI: Base.getindex
fmi = fmiLoad("SpringPendulumExtForce1D", "Dymola", "2022x"; type=:ME)
fmiSimulate(fmi) #<-since no FMU2Component allocated <-and I will make a ticket rightaway for that.
Base.getindex(fmu(;dx_refs=:all),[1,2])

You need this when you want to make a Flux.Chain which uses a substet of the FMU-derivatives, e.g.

inputN = [2,9,10,12,17,24,25]
net = Chain(x -> myFMU(; x=x,dx_refs=:all),
            dx -> cache(dx),                     
            dx -> dx[inputN],
		…)

There is a workaround (if you only have dx-Output): One can use myFMU(...).dx as output of the first layer.

Proposed solution!?
Dispatch for ind::AbstractVector{<:Integer}
If that's okay for you, I can make a draft.

Evaluation of FMU not possible when no component exists (assert not helpful for non-experts)

When you call the fmu without having it simulated first, you get an assert that no FMU2Component is allocated.

fmi = fmiLoad("SpringPendulumExtForce1D", "Dymola", "2022x"; type=:ME)
fmu()

The description in eval.jl says that if no component is allocated, a component will by allocated. Hence I wonder if this used to work in the past but not anymore, further if there is a good reason why you are not allocating it, and finally: if there is a good reason for not allocating, I would wish for a more meaningful explanation for non-FMU-component-structure-experts (e.g. "Please call fmiInstantiate to allocate a component." <-I don't know what is actually the shortest/most reasonable way to get one).
If there is no good reason to not create one in the eval-function, this should be added.
Happy to discuss (and to learn).

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.