Error with using a Simulink model as the objective function in ParetoSearch with options.UseParallel set to True (Global Optimization Tool Box)

1 回表示 (過去 30 日間)
Hi, I currently have an optimization problem which involves identifying a set of parameters in a Simulink model that finds the minimum of the model output. The output is the average of a time series data. I an currently using pareto search (it is a multi objective optimization problem) from the Global Optimization Toolbox.
I have a function handle (run_simulink_model()) that calls the simulink model and once the model runs based on the inputs (parameters of the model) given by the pareto search algo and then there is a bit of post processing that involves using the output from the model to compute the target for optimization. Now the whole thing runs fine when the options.UseParallel is set to . When I set options.UseParallel to the pareto search fails. In the case when parallel is set to I use parsim inside the function handle and it still doesnt seem to work. I would like to understand if parallel computing is possible in pareto search when a simulink model is used.
function fval = run_simulink_model(model_params_fr_optimization, nameSimulinkModel, save_location, evaluation, parallel)
batchSize = size(model_params_fr_optimization, 1);
fval = nan(batchSize, 3);
save_system(nameSimulinkModel);
simulationModelIn(batchSize) = Simulink.SimulationInput;
for idx1 = 1:batchSize
simulationModelIn(idx1).ModelName = nameSimulinkModel;
simulationModelIn(idx1) = simulationModelIn(idx1).setVariable(...
'param_name', model_params_fr_optimization(idx1,:));
end
if parallel == false
youts = sim(simulationModelIn);
elseif parallel == true
youts = parsim(simulationModelIn, 'ShowProgress', 'on', 'TransferBaseWorkspaceVariables','on');
end
fval = post_processing(youts) % Post processing in this section to return the multiple outputs to be optimized
end
%% Function handle and the script for paretosearch
f = @(x)run_simulink_model(x, nameSimulinkModel, save_location, evaluation, parallel_run);
ptions = optimoptions('paretosearch');
options.Display = 'iter';
options.MaxFunctionEvaluations = 10;
options.MaxIterations = 5;
options.InitialPoints.X0 = X; %initial data points
options.ParetoSetSize = 4;
options.UseParallel = true;
[X,fval,exitflag,output,residuals] = paretosearch(f, 2, [], [], [], [], lb, ub, [], options)
Following is the error message i get:
Invalid Simulink object name: simpleSimulinkModel.
The block diagram 'simpleSimulinkModel' is not loaded.
If you need nay further info please do let me know. :) TIA

回答 (1 件)

Avadhoot
Avadhoot 2024 年 1 月 23 日
Hi Jyotirmaya,
This issue appears because MATLAB cannot find your model in the base workspace before simulating it. You can solve this problem using any of the following steps:
  1. Load the model: Use the following line to explicitly load the model file in the base workspace:
load_system(nameSimulinkModel);
Insert this line instead of the following line
save_system(nameSimulinkModel);
2. Check if the model is on the MATLAB path: Execute the following command to add the model to the MATLAB path
addpath('path_to_the_model');
3. If both of the options don't work, ensure the file is open by excuting the following command:
open_system(nameSimulinkModel);
If the file opens without any issuesd then try re-running your script.
I hope it helps.

カテゴリ

Help Center および File ExchangeDirect Search についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by