Opened 9 years ago

Last modified 6 years ago

#3792 accepted defect

Variable override not working with restart

Reported by: crupp@… Owned by: Lennart Ochel
Priority: critical Milestone: Future
Component: Run-time Version:
Keywords: Cc:

Description

I tried this on an old version and it used to work, but got broken at some point. I haven't tried it with -overrideFile, but it may have the same issue.

loadString("
model restartOverrideBug
  parameter Real a = 1;
  Real x(start=1);
  Real y;
equation
  y = der(x);
  der(y) = a * x;
end restartOverrideBug;
");
getErrorString();

// Standard run: returns a=1
simulate(restartOverrideBug, simflags="-output a,y");

// Restart without override: returns a=1
simulate(restartOverrideBug, simflags="-r=tmp.mat -iit=1.0 -iif=restartOverrideBug_res.mat -iim=none -output a,y");

// Restart with override gives the same answer: returns a=1 (incorrect)
simulate(restartOverrideBug, simflags="-r=tmp.mat -iit=1.0 -iif=restartOverrideBug_res.mat -iim=none -output a,y -override a=2");

// No restart, but with override: returns a=2 (correct override)
simulate(restartOverrideBug, simflags="-r=tmp.mat -output a,y -override a=2");

Change History (15)

comment:1 by Adrian Pop, 9 years ago

I guess the order in which we apply the -iif and -override is to blame here. It seems that -iif is always done after -override.

comment:2 by Lennart Ochel, 9 years ago

Not sure if this is an error. Should there rather be a higher priority on the override flag than on the imported result file?

in reply to:  2 comment:3 by crupp@…, 9 years ago

Replying to lochel:

Not sure if this is an error. Should there rather be a higher priority on the override flag than on the imported result file?

If you want to change a parameter for your restart (I do this frequently) then a higher priority on the imported result file would require you to change it in the .mat file. There is no mechanism to do this. Higher priority on the override flag allows this with no extra effort.

comment:4 by Lennart Ochel, 9 years ago

Owner: changed from somebody to Lennart Ochel
Status: newaccepted

comment:5 by anonymous, 9 years ago

@crup by the way restart with system-appi is more efficiently, because don't compile the model again.

// Standard run: returns a=1
simulate(restartOverrideBug, simflags="-output a,y");

// Restart without override: returns a=1
system("./restartOverrideBug.exe-r=tmp.mat -iit=1.0 -iif=restartOverrideBug_res.mat -iim=none -output a,y");

comment:6 by Lennart Ochel, 9 years ago

@adrpo Is it allowed to override simulation settings, e.g. stopTime, with both flags –overrideFile and –override?

comment:7 by crupp@…, 9 years ago

I thought -overrideFile and -override were mutually exclusive. Is that not correct?

comment:8 by Adrian Pop, 9 years ago

Yes, override and overrideFile should be mutually exclusive.

comment:9 by Lennart Ochel, 9 years ago

The question was if it is possible to use the -overrideFile flag for all the attributes that one can use with the -override flag.

comment:10 by crupp@…, 9 years ago

If you couldn't override stopTime in -overrideFile then there would be no mechanism to do so since -override and -overrideFile are mutually exclusive. Therefore I think it should be allowed.

comment:11 by Lennart Ochel, 9 years ago

This makes sense to me.

comment:12 by Lennart Ochel, 9 years ago

What if there would be a variable stopTime or tolerance in a model that should be overridden? I think that wouldn't be possible with the current approach, right?

Basically, the override/overrideFile options can be used to override both simulation settings and values (parameters/start values). Maybe this should be split up into a flag, e.g. overrideSettings, that can be used to override simulation settings and the current flags (override/overrideFile) that should be restricted to override parameters/start values.

comment:13 by crupp@…, 9 years ago

Good point. I never thought of that.

I support your suggestion. It is probably a different ticket, though.

comment:14 by RSchiemann, 6 years ago

Hi all, sorry for reviving this old ticket, but I just found out that this issue is also meaningful for my work.
I want to do exactly the same thing as the original poster but just realized that all overrides (except starttime and stoptime) are ignored when restarting from a .mat file.

What is the suggested solution for restarting a simulation with a different parameter value? Is that behavior still deemed non-erroneous?

in reply to:  14 comment:15 by RSchiemann, 6 years ago

I found a workaround which at least for now allows me to do the analyses I need.

The solution was simply to make parameters a Modelica.Blocks.Interfaces.RealInput. I am not sure if this works for the general case of a parameter, but in my case, I only needed to change PID Setpoints, which can be connected to RealInput. Originally, I had a Modelica.Blocks.Sources.Constant for each Setpoint that I wanted to change via override, which did not work.

Hope this helps other people as well.

Note: See TracTickets for help on using tickets.