how to use FAST RESTART for different simulink model instances?

11 views (last 30 days)
Hi together,
I'm having a problem with fast restart. The problem is stated as following: I have a Simulink model for a parameter sweep study. For each parameter value, the model will be tested under six different scenarios. To avoid repetitive compiling process, I would like to utilize fast restart to speed up the iteration of parameter sweep. The pseudo code can look like this:
simIN(1:6) = Simulink.SimulationInput("my_model"); % generate six model instances, corresponding to six test scenarios
for id = 1:6
simIn(id) = simIn(id).setVariable(trajectory_id); % modify each instance to simulate test scenario 1-6
end
for it = 1:100
simIn(1:6) = simIn(1:6).setVariable(parameter_it); %parameter sweep
out = parsim(simIN,'UseFastRestart','on'); % parallel simulation for six scenarios
cost = J(out); % calculate cost function
parameter(it+1) = decide_next_parameter_to_evaluate;
end
min(J(out)) % get the optimum parameter with min cost function
I have noticed that, with the FASTRESTART, actually the process of the parallel simulation of scenario 1-6 was sped up. But during the parameter sweep (for it = 1:100), the model was constantly recompiled and terminated. What I want to achieve is to enable FASTRESTART for each model instance during its parameter sweep. To put it more intuitively, each model instance is compiled once and get an "individual" FASTRESTART during the parameter sweep. Do you have any recommendations? Thanks a lot in advance!
(In addition, the parameters of the sweep study cannot be generated in advance (due to bayesian dependency), so that I could not directly do parallel simulation to the 100 parameters. That means, the six scenarios have to be tested as a bundle, and after that, continue with the next parameter.)

Answers (1)

Ayush
Ayush on 14 Mar 2024
Edited: Ayush on 14 Mar 2024
Hey,
To efficiently use "Fast Restart" in your Simulink model for parameter sweeps across different scenarios without recompiling the model every time, you can follow the following steps:
  1. Pre-load and set up your model for Fast Restart.
  2. Adjusting the loop structure for parameter sweeos and scenario simulations.
Here is the revised pseudo code for the above approach:
load_system('my_model'); % Load the model into memory
set_param('my_model', 'FastRestart', 'on'); % Enable Fast Restart
for it = 1:100
parameter_it = decide_next_parameter_to_evaluate(); % Determine the next parameter value
for id = 1:6
simIn(id) = Simulink.SimulationInput('my_model');
simIn(id) = simIn(id).setVariable('trajectory_id', id); % Set scenario-specific variable
simIn(id) = simIn(id).setVariable('parameter_it', parameter_it); % Set parameter for current iteration
end
out = parsim(simIn, 'UseFastRestart', 'on'); % Run simulations in parallel with Fast Restart
cost = J(out); % Calculate cost function
end
% Clean up by turning off Fast Restart
set_param('my_model', 'FastRestart', 'off');
For more information on "Fast Restart" in Simulink, refer to the following MathWorks documentation link: https://in.mathworks.com/help/simulink/run-individual-simulations.html
Hope this helps!
  1 Comment
stdrj
stdrj on 18 Mar 2024
Hi Ayush,
thanks for the answer. But this would not solve my problem, because parsim must be reinitialized for each iteration and "forgets" what the model is. Actually I found another solution, which is to
  1. generate six hard copies of a model
  2. give them the proper parameter for the scenario simulation
  3. and enable fast restart for each of them
During the iteration, I just simulate with six copies of models with the efficiency guaranteed by Fast Restart. This is fast enough for me.

Sign in to comment.

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!