Opened 7 years ago

Closed 7 years ago

#4570 closed defect (fixed)

State-machines translation error

Reported by: Andrea Bartolini Owned by: Bernhard Thiele
Priority: critical Milestone: 1.12.0
Component: *unknown* Version: v1.13.0-dev-nightly
Keywords: Cc: Lennart Ochel, Olena Rogovchenko, berger@…

Description

Please consider the following state-machines basic-model:

model TwoStatesMachine1
  inner Integer i(start=0);

  block State1
    outer output Integer i;
  equation
    i = previous(i)+2;
  end State1;
  State1 state1;

  block State2
    outer output Integer i;
  equation
    i = previous(i)-1;
  end State2;
  State2 state2;

equation
    initialState(state1);
    transition(state1, state2, i>10, immediate=false, reset=true);
    transition(state2, state1, i<1, immediate=false, reset=true);

end TwoStatesMachine1;

Checking this model from OMEdit will produce the following error:

[1] 15:12:08 Translation Error
[StateMachines: 20:5-20:25]: Failed to elaborate expression: initialState(state1).

[2] 15:12:08 Translation Error
Error occurred while flattening model StateMachines.TwoStatesMachine1

if you comment-out the line "initialState(state1);" and retry to check the model, the following error is returned:

[1] 15:15:46 Translation Error
[StateMachines: 21:5-21:66]: Failed to elaborate expression: transition(state1, state2, i > 10, immediate = false, reset = true).

[2] 15:15:46 Translation Error
Error occurred while flattening model StateMachines.TwoStatesMachine1

Is there some flags or setting to be changed in order to activate the state-machines semantics in OMC?

OMEdit 1.13.0~dev-18-gf627d10
Connected to OpenModelica 1.13.0~dev-192-gd3b895d
SysOp: Linux Ubuntu 16.04 - 64 bit

Attachments (4)

dialog.png (75.7 KB ) - added by Bernhard Thiele 7 years ago.
StateMachine.png (17.8 KB ) - added by Andrea Bartolini 7 years ago.
plot_cppruntime.png (30.2 KB ) - added by Bernhard Thiele 7 years ago.
TwoStatesMachine1.mos (198 bytes ) - added by Bernhard Thiele 7 years ago.

Download all attachments as: .zip

Change History (19)

comment:1 by Bernhard Thiele, 7 years ago

Yes, try to give OMC the flag "+std=3.3" to enforce Modelica 3.3.
Otherwise, if the MSL is loaded first, OM probably switches to Modelica 3.2.

Following is an example of how Modelica 3.3 can be enforced by adding the flag in the simulation options dialog of OMEdit.


by Bernhard Thiele, 7 years ago

Attachment: dialog.png added

comment:2 by Andrea Bartolini, 7 years ago

Thanks for quick reply,

I put the flag +std=3.3 in the OMEdit options, and now the check of the model rises the following error:

[1] 17:38:40 Translation Error
Internal error Check of StateMachines.TwoStatesMachine1 failed with no error message

which is a little obscure for me...

comment:3 by Bernhard Thiele, 7 years ago

Yes, checks for state machines are not (yet) supported. I should look into the checking code and add meaningful diagnostics. However, simulation should work.

comment:4 by Andrea Bartolini, 7 years ago

I confirm, the simulation works properly.

The only unexpected behavior (for me) is the obtained value of "previous(i)".... see the attached plot.

by Andrea Bartolini, 7 years ago

Attachment: StateMachine.png added

comment:5 by Martin Sjölund, 7 years ago

@bthiele - stop using +d=... and +std=...; use -d= and --std= before they get deprecated ;)

comment:6 by Bernhard Thiele, 7 years ago

Cc: Lennart Ochel added

@sjoelund.se - ok, good to know.

The plot for previous(i) is wrong and really weird. This seems to be an issue with the standard C run-time. If I simulate the model using the Cpp run-time, it looks fine, see the attached files.

@sjoelund.se - If I try to use the Cpp run-time with the standard nightly-build for Linux, I get a build error. I need to use my self-compiled omc version to get Cpp support. Do we only have support for the C run-time in the nightly-builds?

by Bernhard Thiele, 7 years ago

Attachment: plot_cppruntime.png added

by Bernhard Thiele, 7 years ago

Attachment: TwoStatesMachine1.mos added

in reply to:  6 comment:7 by Martin Sjölund, 7 years ago

Replying to bthiele:

@sjoelund.se - If I try to use the Cpp run-time with the standard nightly-build for Linux, I get a build error. I need to use my self-compiled omc version to get Cpp support. Do we only have support for the C run-time in the nightly-builds?

Try: sudo apt install libomccpp

comment:8 by Bernhard Thiele, 7 years ago

Ah, thanks. I needed to also do sudo apt install libomp-dev, otherwise there was a compilation error. Which is a bit strange, since the compilation error was complaining about a missing omp library and libomp5 is already in the package dependencies (I'm using Ubuntu 16.04).

comment:9 by Bernhard Thiele, 7 years ago

Cc: Olena Rogovchenko berger@… added

As discussed above I added support for state machines in the checkModel(..) function (https://github.com/OpenModelica/OMCompiler/pull/1916).

in reply to:  1 ; comment:10 by Francesco Casella, 7 years ago

Replying to bthiele:

Yes, try to give OMC the flag "+std=3.3" to enforce Modelica 3.3.
Otherwise, if the MSL is loaded first, OM probably switches to Modelica 3.2.

@bthiele two questions:

  • why isn't +std=3.3 switched on by default? Is it still buggy to the point of being considered experimental?
  • although adding this flag is obvious in hindsight, it is absolutely not the average user; consider that Andrea is now quite seasoned at using OMC and OMEdit for professional work, so he's not representative of the average user. If there are good reasons not to make +std=3.3 default, please add an indication to set this flag if you want to use state machines in the documentation

in reply to:  5 comment:11 by Francesco Casella, 7 years ago

Replying to sjoelund.se:

@bthiele - stop using +d=... and +std=...; use -d= and --std= before they get deprecated ;)

If we don't phase them out anytime soon with *errors*, people will go on using them forever :)

in reply to:  10 ; comment:12 by Martin Sjölund, 7 years ago

Replying to casella:

@bthiele two questions:

  • why isn't +std=3.3 switched on by default? Is it still buggy to the point of being considered experimental?
  • although adding this flag is obvious in hindsight, it is absolutely not the average user; consider that Andrea is now quite seasoned at using OMC and OMEdit for professional work, so he's not representative of the average user. If there are good reasons not to make +std=3.3 default, please add an indication to set this flag if you want to use state machines in the documentation

--std=3.3 is enabled by default. Loading an MSL version of 3.2.x sets it to --std=3.2.

comment:13 by Bernhard Thiele, 7 years ago

Replying to casella:

  • why isn't +std=3.3 switched on by default? Is it still buggy to the point of being considered experimental?

If I remember correctly there are models named Clock in the MSL, which conflicts with the Clock type. Dymola handles this by first searching for classes named Clock and if it doesn't find one it assumes it is a predefined Clock type.

I will have look at the documentation and add a remark about it.

Last edited 7 years ago by Bernhard Thiele (previous) (diff)

in reply to:  12 comment:14 by Francesco Casella, 7 years ago

Replying to sjoelund.se:

  • why isn't +std=3.3 switched on by default? Is it still buggy to the point of being considered experimental?

--std=3.3 is enabled by default. Loading an MSL version of 3.2.x sets it to --std=3.2.

OK, but there is no MSL 3.3.x, so as soon as you use the MSL, which is pretty likely, it will fall back to 3.2, so this default is probably not very meaningful.

comment:15 by Bernhard Thiele, 7 years ago

Resolution: fixed
Status: newclosed

Added a note about --std=3.3 in the documentation (https://github.com/OpenModelica/OpenModelica-doc/pull/59).

I guess I can close this ticket now.

Note: See TracTickets for help on using tickets.