Closed clagms closed 4 years ago
Mu.
Or in longer prose: Given your definition of feedthrough, the question whether FMI 2.0/3.0 co-simulation supports it, trivially cannot be answered since the operations you use are not defined in FMI, and you do not specify - in the definition - whether time may elapse during the combination of get_c(set_c()) or not.
There is no way to update (detectibly) the state of a co-simulation FMU without advancing the time, except for initialization mode.
If time passage is allowed (i.e. a call to fmi3DoStep), then trivially FMI co-simulation supports your definition of feedthrough, if not, then it trivially does not (trivially, because h may not be 0, and thus your inability to query the new state).
So I rather think a different question would have to be asked and discussed, e.g. as discussed in #117.
In the rest of this issue, it seems to me you are sometimes reading generic parts of the standard, which apply to model-exchange as well as to co-simulation, only with co-simulation semantics in focus. Similarly the distinction between model feedthrough and its handling at FMU level seems important.
I would support a PR (or multiple PRs) cleaning up the text to clearly state which definition of feedthrough of what (model vs. FMU) is meant in each place, and clarifying whether a statement applies to ME, CS, or both (and/or the new stuff as well).
As an aside: Any changes to the computational model of FMI for co-simulation would require a full-blown FCP.
Dear @pmai I'm trying my best to detect ambiguities in the standard.
I did not understand that "Mu." means.
Given your definition of feedthrough, the question whether FMI 2.0/3.0 co-simulation supports it, trivially cannot be answered since the operations you use are not defined in FMI, and you do not specify - in the definition - whether time may elapse during the combination of get_c(set_c()) or not.
I'm sorry I did not clarify what these operations do. They are abstractions of the operation in the FMI standard, and not proposals for new operations. The operations make explicit the internal state of the FMU so that the reader is able to tell whether there is a change in the state or not. These are functions in the mathematical sense (i.e., free of side effects). They are inspired by the definition advanced by Broman et al in this paper:
Time is not allowed to pass in the definition of feedthrough. I must stress that this is not my definition of feedthrough. This is just a way to explain what it is wrt to the FMI functions.
If your claim that the FMI standard does not support feedthrough is the position of the FMI standard, then I can propose a few changes to make this clearer to the reader.
Feed-through is pretty common in co-simulation of physical systems. See, for example, the following paper by Martin Arnold, where feedthrough is discussed, and methods are proposed to deal with it:
See also the survey we did on methods for co-simulation (in and outside FMI): -Gomes, Cláudio, Casper Thule, David Broman, Peter Gorm Larsen, and Hans Vangheluwe. “Co-Simulation: A Survey.” ACM Computing Surveys 51, no. 3 (2018): Article 49. https://doi.org/10.1145/3179993.
What I’m saying is that it does not make sense to formulate mathematical functions that trivially don’t match the functions that FMI supports when trying to determine properties of the standard (this goes for all standards). A standard provides a set of axioms, replacing them with different ones is never interesting in that regard.
As to feed through: A model obviously can have feed through in the classical sense, but you will not be able to differentiate that from models without feed through via the FMI co-simulation Interface because there is no access to the model outputs and state after setting the inputs without an intervening fmi3DoStep call, which causes time to advance at least an epsilon.
Which is one reason one might want to inform the master about such “internal” feed through in some other way...
Note that I’m not saying that this is the be all and end all of co-simulation, and that not having other paradigms for co-simulation might not be interesting, but I think discussion of those in the context of FMI have take the definitions of FMI into account, rather that making use of external definitions.
I.e. I would find a discussion along the lines of #117 more helpful...
Another thing I agree we might want to do is throw out all references to scientific papers (at least in the normative section), since they seem to be causing more harm than good (by causing people to place more weight on the whole content of those papers than what is explicitly written in the standard).
I did not understand that "Mu." means.
I did not understand that "Mu." means. https://en.wikipedia.org/wiki/MU_puzzle ?
Do we talk here about (direct) feedthrough in the Co-Simulation (CS) or Hybrid-Co-Simulation (HCS) interface?
My understanding is the following:
in CS: Feedthrough is disallowed: https://fmi-standard.org/docs/3.0-dev/#state-step-mode-co-simulation "It is not allowed to call fmi3Get{VariableType} functions after fmi3Set{VariableType} functions without an fmi3DoStep call in between."
In HCS: Feedthrough is allowed (only!) in Event mode https://fmi-standard.org/docs/3.0-dev/l#_handling_a_successful_early_return_by_the_co_simulation_master_in_fmi3hybridcosimulation "In Event Mode it is allowed to fmi3Get{VariableType} variable values of the FMU after the call of fmi3NewDiscreteStates and it is allowed to fmi3Set{VariableType} variable values before calling fmi3NewDiscreteStates"
Is my understanding correct?
Then we should focus on what has to clarified to avoid confusion
Also remove from guiding ideas - i.e.
Support many and nested FMUs A simulator may run many FMUs in a single simulation run and/or multiple instances of one FMU. The inputs and outputs of these FMUs can be connected with direct feedthrough. Moreover, an FMU may contain nested FMUs.
Also remove from guiding ideas - i.e.
Support many and nested FMUs A simulator may run many FMUs in a single simulation run and/or multiple instances of one FMU. The inputs and outputs of these FMUs can be connected with direct feedthrough. Moreover, an FMU may contain nested FMUs.
I do not agree. I do not think that all requirements have to be fulfilled by all FMU types. And ME, HCS (and SES?) support direct feedthrough
So after reading the specification again I see the following: HCS supports feedthrough But it comes with the following implications:
In general, I find the mix of co-simulation with early return, hybrid co-simulation, hybrid co-simulation with clock support confusing. Maybe worth a (small) group discussion...
@CThuleHansen and @clagms: could you please propose a clarification/possible improvement?
@chrbertsch unfortunately we did not have time to cover this at the FMI design meeting in Berlin. We have discussed with @APillekeit that he will present the difference between clocks and events at the next fmi design WEB meeting.
I think we need this information before we can provide a sufficient clarification and possible improvement.
How can we go on with this? @IZacharias : could you perhaps take up from @APillekeit regarding "the difference between clocks and events?"
@clagms and @CThuleHansen : could you please also add "(direct) Feedthrough" to the glossary? (see https://github.com/modelica/fmi-standard/pull/962#issuecomment-623358886)
@clagms and @CThuleHansen : could you please also add "(direct) Feedthrough" to the glossary? (see #962 (comment))
I added this to clagms/glossary_model_exchange PR #941.
The original intend of this ticket is solved. Reopen if you do not agree.
What IMHO is still to be clarified:
HCS:
fmi3Set{VariableType}
-> fmi3NewDiscreteStates
- fmi3Get{VariableType}
fmi3NewDiscreteStates
to fmi3DoHyperDenseTimeStep
? I consider the name misleading, as also continuous states might change due to this calculation. (related issue https://github.com/modelica/fmi-standard/issues/94#issuecomment-629697288 if evaluation of outputs is allowed after setting inputs in xCS for the purpose of nonlinear state estimation and if settging of continuous states is allowed in event model of HCS)outputs
of the modelstructure description to define which inputs have direct feedthrough to which outputs at event times in HCS? I think yes. Then we have to update the text thereSCS:
fmi3NewDiscreteStates
between set and get functions. There the fmi3ActivateModelPartition
has the role of the fmi3DoStep
in BCS, but with the difference that the fmi3ActivateModelPartition
does not necessarily advance the FMU in time.
So why do we in https://fmi-standard.org/docs/3.0-dev/#_computation_in_scheduled_co_simulation forbid to calling fmi3ActivateModelPartition
several times with the same activation time?It is not allowed to call fmi3ActivateModelPartition for a clockReference and clockElementIndex (i.e. valueReference of clock variable and element index into that for arrays) more than once for the same activationTime ti.
Please comment!
I don't understand why this cannot be supported for BCS just as well as HCS. The argument that i have seen is:
some vendors might have problem, well we have plenty of optional features already.
It could be inefficient for real time system, well don't use it then.
It is not as mathematically robust as model exchange, true but more than current BCS as you could do something to deal with the issue.
With IVA you can do partial support (abuse?) of this feature by asking for new input at the end of the step, only limitation becomes that the fmu will have to request it and you cannot iterate a, but if you already can do this once, the iteration shouldn't be that hard. To avoid such semi solution wouldn't proper support be better?
Or am i missing something?
Isn't a basic property of FMI 2.0 CS that (typically or mandatorily?) unlike in FMI 2.0 the computations are triggered by the doStep, while in FMI2.0 ME they are triggered by fmi2getXXX. Doesn't this significantly simplify things for the exporting tools regarding an efficient implementation (not having to care much about caching etc. )
So why do we in https://fmi-standard.org/docs/3.0-dev/#_computation_in_scheduled_co_simulation forbid to calling `fmi3ActivateModelPartition` several times with the same activation time?
Please comment!
I am not sure about the modelPartitions for plant models, but for vECUs I can explain this: Calling a task may advance the internal (discrete) time (like a counter) of the control algorithm (most of them have no access to "time" but only know ticks).
With IVA you can do partial support (abuse?) of this feature by asking for new input at the end of the step, only limitation becomes that the fmu will have to request it and you cannot iterate a, but if you already can do this once, the iteration shouldn't be that hard. To avoid such semi solution wouldn't proper support be better?
Or am i missing something?
Similar to my comment in #991: intermediateUpdate is not to propagate values between FMUs - communication points are for that. So intermediateUpdate is not supposed to (and I think cannot if we describe it right) allow for direct feedthrough outside of the FMU.
I think we should keep things simple inside intermediateUpdate - if you need more information, you can always stop the doStep with earlyReturn and then properly exchange values.
The final argument that comes to mind: if you need ultimate control, do ME. xCS is supposed to be simpler. If we allow all kinds of variants and complications, we will have ME2 - and we do not need another).
I am not sure about the modelPartitions for plant models, but for vECUs I can explain this: Calling a task may advance the internal (discrete) time (like a counter) of the control algorithm (most of them have no access to "time" but only know ticks).
That makes sense.
So to clarify: in HCS for an event we have the idea of super dense time, so one can iterate without advancing in time by setting inputs, calling fmi3NewDiscreteStates, getting outputs several times. We had the idea that a SCS FMU can be wrapped as a HCS FMU. But if we map a modelPartition activation to a clock to a fmi3NewDiscreteStates
call, we must prevent that this could be called several times. How?
I am not sure about the modelPartitions for plant models, but for vECUs I can explain this: Calling a task may advance the internal (discrete) time (like a counter) of the control algorithm (most of them have no access to "time" but only know ticks).
That makes sense.
So to clarify: in HCS for an event we have the idea of super dense time, so one can iterate without advancing in time by setting inputs, calling fmi3NewDiscreteStates, getting outputs several times. We had the idea that a SCS FMU can be wrapped as a HCS FMU. But if we map a modelPartition activation to a clock to a
fmi3NewDiscreteStates
call, we must prevent that this could be called several times. How?
You have to do the same kind of book keeping any OS scheduler has to do that works with activation flags (aka triggers, activate calls,...). OS schedulers do this implicitly when operate on priorities and resources etc. So I am sure this can be done, and should be as much as we should care about here now. Right?
(Discussion Andreas J, Christian B)
In SCS, there should be no direct feedthrough.
We should create an example for an event iteration with direct feedthrough for a "Coupled clutches example" split into multiple HCS FMUs in reference FMUs. There the decision which clutch is open or not depends on the other clutch and must be iterated at an event. This will showcase the use case for direct feedthrough at events in HCS. @KarlWernersson : could you perhaps prepare such an example?
Dsicussion during web design meeting: Karl: I will try to see if the coupled clutches will work in our old prototype. It is harder to provide 3.0 FMUs for the coupled clutches. Klaus: Please have a look at examples for 2.0 ME with a more abstract content that would likely also work in showing the ideas.
Irina: We will discuss internally if SCS can have direct feedthrough. Andreas: Please come up with an example if you have one and make it ready for the Reference FMUs.
This issue is an adaptation of https://github.com/modelica/fmi-standard/issues/623#issuecomment-536629923 for fmi3.
First we need a definition of feedthrough.
Given an Co-simulation FMU instance $c$ , the input $u_c$ feeds-through to output $y_c$ when there exist two different values $v_1, v_2$ and FMU state $s_c$, such that $$get_c(set_c(s_c, u_c, v_1), y_c) \neq get_c(set_c(s_c, u_c, v_2), y_c)$$
where:
Here are some properties of the feed-through:
Note that this definition of feed-through is well accepted, and it means the exact same thing as "algebraic dependency between y_c and u_c".
Also note that any ODE that has an output equation of the form: $$\dot{x} = F(x, u)$$ $$y = G(x, u)$$
has feed-through.
This definition is therefore consistent with [Kubler2000], that the fmi3 document claims to be consistent with.
Now let's look at the the FMI text regarding feedthrough.
Right at the beginning, it says:
Setting aside the fact that "direct feedthrough" is redundant with "feedthrough", this induces the reader into thinking that FMI CS supports feedthrough. I would argue that supporting feedthrough is a necessary feature to export Modelica models, in
Then, in the definition of the causality attribute, the words algebraic relationship are used:
Leading the reader to believe that any dependency declared in the ModelStructure, is a feedthrough dependency, and therefore satisfies the definition I put above.
In fact, in the definition of the ModelStructure, it says:
Again, the reader might think that this means there is an algebraic (an instant) dependency between knowns and unknowns.
Thankfully, in the mathematical definition of the FMU for co-simulation, we observe:
Which tells the reader that there is no feedthrough in that model (i.e., the output $y{i+1}$ does not depend algebraically on the input $u{i+1}$).
However, the text immediately after says
which is not true. Equation (4.1) clearly forbids feedthrough, and [Kubler2000] has the equation:
(apologies for the scribbles).
This equation clearly shows the feed-through.
Moreover, later in the standard, there is a remark:
Which makes it clear that feedthrough is not supported, which is also claimed in https://github.com/modelica/fmi-standard/issues/117#issuecomment-430378201.
If indeed the intent is not to support feedthrough in the FMI co-simulation, then I suggest that the parts I've highlighted above be rewritten to avoid giving this idea. On the other hand, feedthrough support can be standardized fairly easily (unless I don't see the full picture) by just re-defining the meaning the of the ModelStructure. If a tool provider does not want to implement feedthrough, he can just specify in the model structure that every output variable is independent of every input variable. If an FMU supports feedthrough, then the burden is on the master algorithm to comply to that restriction. This is also not hard to do (see paper below, or contact me for details).
What should we go for? Feedthrough or no feedthrough. I have a list of sections in the document that are affected by this change.
Some examples:
The FMI provides the necessary features that Modelica®
should maybe be restricted to FMI Model Exchange, as I would argue that having feedthrough is an essential feature of Modelica. Even the simplest coupled mechanical models (such as a mass-spring-damper) need feedthrough to be more accurately co-simulated.The FMI provides explicit methods (called by the FMU environment) for setting properties that invalidate cached data. An FMU that chooses to implement a cache may maintain a set of "dirty" flags, hidden from the simulator. A get method, for example to a state, will then either trigger a computation, or return cached data, depending on the value of these flags.
is in favor of feedthrough, but needs to be rewritten in case there is no feedthrough.I hope this helps! :)
PS - This issue has been discussed with, and approved by @CThuleHansen .
Refs:
[Kubler2000] - Kübler, R., and W. Schiehlen. 2000. “Two Methods of Simulator Coupling.” Mathematical and Computer Modelling of Dynamical Systems 6 (2): 93–113. https://doi.org/10.1076/1387-3954(200006)6:2;1-M;FT093.
Gomes, Cláudio, Casper Thule, Levi Lucio, Hans Vangheluwe, and Peter Gorm Larsen. 2019. “Generation of Co-Simulation Algorithms Subject to Simulator Contracts.” In 3rd Workshop on Formal Co-Simulation of Cyber-Physical Systems, to be published. Oslo, Norway. Download: cosimcpspaper.pdf