Opened 12 years ago

Last modified 4 years ago

#2174 assigned enhancement

Allow for modifiers in translateModel() and simulate() API functions

Reported by: Francesco Casella Owned by: Adrian Pop
Priority: high Milestone: Future
Component: Frontend Version: trunk
Keywords: Cc:

Description

It is often the case that one wants to run batches of simulations where some parameters are changed, in order to explore the configuration space. For this purpose, it would be nice if one could write modifiers directly in the simulate() and translateModel() functions, e.g.:

simulate(MySystem(component2(T = 10)))

This feature is provided by Dymola and it is indeed very useful in such cases.

Change History (16)

comment:1 by Martin Sjölund, 12 years ago

Resolution: worksforme
Status: newclosed

How about:

loadString("model M
  parameter Real p=1;
  Real x1(start=p);
equation
  der(x1) = 1.0;
end M;");getErrorString();
simulate(M,simflags="-override p=5");getErrorString();
plot(x1);

comment:2 by Francesco Casella, 12 years ago

Resolution: worksforme
Status: closedreopened

This is nice, but it doesn't work for structural parameters, e.g.

loadString("model M
   parameter Integer N = 4;
   Real x[N](start = linspace(1,N,N), each fixed = true);
 equation
   der(x) = x;
 end M;");getErrorString()

simulate(M,simflags="-override N=10")

plot(x[10])

An important application is when you need to change the number of nodes/volumes in a distributed parameter model, and see how many nodes are enough to get an accurate result.

comment:3 by Adrian Pop, 11 years ago

Owner: changed from somebody to Adrian Pop
Status: reopenedassigned

comment:4 by Adrian Pop, 11 years ago

I'll be taking care of this.

comment:5 by Francesco Casella, 9 years ago

Milestone: Future1.9.4

comment:6 by Martin Sjölund, 9 years ago

Milestone: 1.9.41.9.5

Milestone pushed to 1.9.5

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

Milestone: 1.9.51.10.0

Milestone renamed

comment:8 by Martin Sjölund, 8 years ago

Milestone: 1.10.01.11.0

Ticket retargeted after milestone closed

comment:9 by Francesco Casella, 8 years ago

I understand you can implement

simulate(M(p=10, redeclare M2 m), ...);

where p is a structural parameter, by doing this:

loadString("
model M_modified;
  extends M(p=10, redeclare M2 m);
end M_modified;

simulate(M_modified, ....);

which is only slightly inconvenient because

  • you need to know this programming pattern
  • the default name for the simulation results is X_res.mat and not M_res.mat

Could we implement this trick internally in the simulate() API, making it transparent to the user? You just need to take the content of the model name input, build the string that declares the modified model, load it and use it to generate the simulation code, and use the original model name as a default for the -r option. Seems quite easy to do.

The only tricky part I see would be that the filenames of all generated code will not refer to M but rather to M_modified. Maybe that's not a big deal, and maybe that can also be taken care of easily.

comment:10 by Adrian Pop, 8 years ago

The name can be changed with simulate(M_modified, simflags="-r Model_res.mat");

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

in reply to:  10 comment:11 by Martin Sjölund, 8 years ago

Replying to adrpo:

The name can be changed with simulate(M_modified, simflags="-r Model_res.mat");

More common I suspect is simulate(M_modified, fileNamePrefix="Model");, which causes all files generated to have the prefix of "Model".

comment:12 by Francesco Casella, 8 years ago

So it seems that

simulate(M(p=10, redeclare M2 m), ...);

can be obtained by running

loadString("
model X;
  extends M(p=10, redeclare M2 m);
end X;

simulate(X, ....);

In fact this is almost true, save that the experiment annotation of model M is lost when extending it, which is of course critical.

Suggestions?

comment:13 by Martin Sjölund, 8 years ago

Milestone: 1.11.01.12.0

Milestone moved to 1.12.0 due to 1.11.0 already being released.

comment:14 by Francesco Casella, 7 years ago

Moved to milestone 1.13.0 as milestone 1.12.0 was closed

comment:15 by Francesco Casella, 7 years ago

Milestone: 1.12.0Future

The milestone of this ticket has been reassigned to "Future".

If you think the issue is still valid and relevant for you, please select milestone 1.13.0 for back-end, code generation and run-time issues, or 2.0.0 for front-end issues.

If you are aware that the problem is no longer present, please select the milestone corresponding to the version of OMC you used to check that, and set the status to "worksforme".

In both cases, a short informative comment would be welcome.

comment:16 by Francesco Casella, 4 years ago

See discussion in #6014

Note: See TracTickets for help on using tickets.