- Pre-load and set up your model for Fast Restart.
- Adjusting the loop structure for parameter sweeos and scenario simulations.
how to use FAST RESTART for different simulink model instances?
11 views (last 30 days)
Show older comments
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.)
0 Comments
Answers (1)
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:
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!
See Also
Categories
Find more on DSP Algorithm Acceleration in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!