Opened 4 years ago

Closed 4 years ago

#6296 closed defect (fixed)

FMI export recently fails with array outputs

Reported by: Rüdiger Franke Owned by: arunkumar palanisamy
Priority: blocker Milestone: 1.16.3
Component: FMI Version: 1.16.0
Keywords: Cc: Adrian Pop, arunkumar palanisamy

Description (last modified by Rüdiger Franke)

This is a modified version of testArrayEquations, reduced by many features, but extended with a vector output yx1:

model ArrayEquationsTest
  parameter Integer n = 10;
  input Real[n] u(start = 1:n);
  Real[n] x1(each start = 1);
  output Real[n] yx1;
  output Real y1;
equation
  when Clock(0.1) then
    // for eqation
    for i in 1:n loop
      x1[i] = if firstTick(x1[i]) then previous(x1[i]) else previous(x1[i]) + u[i];
      yx1[i] = x1[i];
    end for;
  end when;
  y1 = sum(x1);
end ArrayEquationsTest;

Attempting to export this model as FMU with:

setCommandLineOptions("--std=3.3"); getErrorString();
setCommandLineOptions("-d=newInst,-nfScalarize,disableFMIDependency"); getErrorString();
setCommandLineOptions("--simCodeTarget=Cpp"); getErrorString();
loadFile("ArrayEquationsTest.mo"); getErrorString();
translateModelFMU(ArrayEquationsTest, version = "2.0"); getErrorString();

gives the error:

[/home/rfranke/OpenModelica/OMCompiler/Compiler/Template/Tpl.mo:2027:8-2027:159:writable] Error: Internal error Stack overflow when evaluating function:
[bt] #1 /home/rfranke/OpenModelica/build/bin/../lib/x86_64-linux-gnu/omc/libOpenModelicaRuntimeC.so(mmc_setStacktraceMessages_threadData)
[bt] #2 /home/rfranke/OpenModelica/build/bin/../lib/x86_64-linux-gnu/omc/libOpenModelicaRuntimeC.so(mmc_do_stackoverflow)
[bt] #3 /home/rfranke/OpenModelica/build/bin/../lib/x86_64-linux-gnu/omc/libOpenModelicaCompiler.so(CodegenCppInit.fun_87)
[bt] #4 /home/rfranke/OpenModelica/build/bin/../lib/x86_64-linux-gnu/omc/libOpenModelicaCompiler.so(CodegenCppInit.ScalarVariableTypeStartAttribute)
[bt] #5 /home/rfranke/OpenModelica/build/bin/../lib/x86_64-linux-gnu/omc/libOpenModelicaCompiler.so(CodegenCppInit.fun_83)
[bt] #6 /home/rfranke/OpenModelica/build/bin/../lib/x86_64-linux-gnu/omc/libOpenModelicaCompiler.so(CodegenCppInit.ScalarVariableType)
[bt] #7 /home/rfranke/OpenModelica/build/bin/../lib/x86_64-linux-gnu/omc/libOpenModelicaCompiler.so(CodegenCppInit.fun_73)
[bt] #8 /home/rfranke/OpenModelica/build/bin/../lib/x86_64-linux-gnu/omc/libOpenModelicaCompiler.so(CodegenCppInit.fun_76)
[bt] #9 /home/rfranke/OpenModelica/build/bin/../lib/x86_64-linux-gnu/omc/libOpenModelicaCompiler.so(CodegenCppInit.scalarVariableXML)
[bt] #10 /home/rfranke/OpenModelica/build/bin/../lib/x86_64-linux-gnu/omc/libOpenModelicaCompiler.so(CodegenCppInit.lm_74)
[bt] #11 /home/rfranke/OpenModelica/build/bin/../lib/x86_64-linux-gnu/omc/libOpenModelicaCompiler.so(CodegenCppInit.fun_76)
[bt] #12 /home/rfranke/OpenModelica/build/bin/../lib/x86_64-linux-gnu/omc/libOpenModelicaCompiler.so(CodegenCppInit.scalarVariableXML)
...
[bt] #1024 /home/rfranke/OpenModelica/build/bin/../lib/x86_64-linux-gnu/omc/libOpenModelicaCompiler.so(CodegenCppInit.lm_74)
[bt] #1025 [...]
Error: Template error: A template call failed (/home/rfranke/OpenModelica/build/bin/../lib/x86_64-linux-gnu/omc/libOpenModelicaCompiler.so: (null)). One possible reason could be that a template imported function call failed (which should not happen for functions called from within template code; templates assert pure 'match'/non-failing semantics).

It was working with OM 1.14. It is not working with 1.16 and 1.17 anymore.

Change History (18)

comment:1 by Rüdiger Franke, 4 years ago

Description: modified (diff)

comment:2 by Rüdiger Franke, 4 years ago

Component: Cpp Run-timeFMI
Owner: changed from Rüdiger Franke to Lennart Ochel

That's the diff between CodegenCppInit.tpl of master vs v1.14

245c245
< template jacobianMatrixXML(Integer indexJacobian, list<JacobianColumn> jacobianColumn, list<SimVar> seedVars, String matrixName, SparsityPattern sparsepattern, list<list<Integer>> colorList, Integer maxColor)
---
> template jacobianMatrixXML(Integer indexJacobian, list<JacobianColumn> jacobianColumn, list<SimVar> seedVars, String matrixName, list<tuple<Integer,list<Integer>>> sparsepattern, list<list<Integer>> colorList, Integer maxColor)

So, hardly the reason for the malfunction. This is why I'm reassigning the ticket to FMI.

comment:3 by Rüdiger Franke, 4 years ago

Description: modified (diff)

comment:4 by Rüdiger Franke, 4 years ago

Cc: arunkumar palanisamy added

It appears that the following commit clear up $cse variables for FMI modelDescription.xml (#640) by @arun3688 broke the function SimCodeUtil.getScalarElements with the introduction of fmi_index.
The function now returns the array, resulting in an endless loop when called from templates such as CodegenFMUCommon.ScalarVariable.

comment:5 by arunkumar palanisamy, 4 years ago

@rfranke, the immediate fix for this problem is to use the config flag fmiFilter as none
should work eg. omc --fmiFilter=none testArrayEquation

comment:6 by Rüdiger Franke, 4 years ago

Thank you for this workaround!

comment:7 by Adrian Pop, 4 years ago

I guess we could activate the --fmiFilter=none if -d=-nfScalarize is on.

Last edited 4 years ago by Adrian Pop (previous) (diff)

comment:8 by Rüdiger Franke, 4 years ago

I'd love to understand the root cause first. It's model outputs that should not be filtered out. Maybe a fix if the filter functionality is possible?

comment:9 by Francesco Casella, 4 years ago

Milestone: 1.16.21.17.0

@rfranke, we released 1.16.2 today. I would reschedule this for 1.17.0, due end of January. I hope that is fine for you, we could make a 1.16.3 mid-January, but it's probably not worth it. Feel free to comment on this

comment:10 by Rüdiger Franke, 4 years ago

Priority: blockercritical

Fine with me. Actually it's not a blocker anymore since a workaround is known.

Last edited 4 years ago by Rüdiger Franke (previous) (diff)

comment:11 by Rüdiger Franke, 4 years ago

Priority: criticalblocker

I'm afraid I need to escalate this ticket again. The flag --fmiFilter=none works for me with the current master under Linux. It seems to be ignored by the newly released 1.16.2 Win32bit though. No matter if I specify it or not under Tools->Options->Simulation Additional Translation Flags, OMEdit just disappears during FMI export. This makes any version released after 1.14 unusable.

Same with OMEdit under Linux: --fmiFilter does not take effect. So please, release 1.16.3!

Last edited 4 years ago by Rüdiger Franke (previous) (diff)

comment:12 by Francesco Casella, 4 years ago

Owner: changed from Lennart Ochel to arunkumar palanisamy
Status: newassigned

comment:13 by arunkumar palanisamy, 4 years ago

@rfranke, This PR https://github.com/OpenModelica/OpenModelica/pull/7067 should fix the issue

comment:14 by Adrian Pop, 4 years ago

Thanks Arun! I will cherry-pick this to maintenance/v1.16 for 1.16.3.

in reply to:  14 comment:15 by Francesco Casella, 4 years ago

Milestone: 1.17.01.16.3

Replying to adrpo:

Thanks Arun! I will cherry-pick this to maintenance/v1.16 for 1.16.3.

Please close the ticket once you've done it

comment:16 by arunkumar palanisamy, 4 years ago

Resolution: fixed
Status: assignedclosed

comment:17 by Francesco Casella, 4 years ago

Resolution: fixed
Status: closedreopened

Sorry @arun3688, let's keep this open as a reminder until the commit is merged into maintenance/1.16, it still isn't.

comment:18 by Adrian Pop, 4 years ago

Resolution: fixed
Status: reopenedclosed
Note: See TracTickets for help on using tickets.