Problem using OPTIMOPTIONS with FMINCON for PARALLEL COMPUTING
14 views (last 30 days)
Show older comments
Hi All, I am performing an optimization of parameters of a Simulink model using fmincon The options I am using are the followings
options = optimoptions('fmincon'); % Start with the default options
options = optimoptions(options,'Algorithm', 'interior-point');
options = optimoptions(options,'Display', 'iter-detailed');
options = optimoptions(options,'MaxIter', 1000);
options = optimoptions(options,'PlotFcns', { @optimplotfval });
So far so good, the optimization run and arrives to a minimum with no problems at all However, as the optimization takes few hours to perform I wish to speed up the process by using parallel computing (I have a 2 core processor computer)
Then, I add the following line to the options listed above
options = optimoptions('fmincon','UseParallel',true);
Before I run the optimization with the new line of code, I set the parallel computing on manually using the following command in Matlab Command Line
parpool
Matlab gives the following message
Starting parallel pool (parpool) using the 'local' profile ... connected to 2 workers.
ans =
Pool with properties:
Connected: true
NumWorkers: 2
Cluster: local
AttachedFiles: {}
IdleTimeout: 30 minutes (30 minutes remaining)
SpmdEnabled: true
I then run the optimization but I get this error
Error using optimoptions (line 114)
Invalid value for OPTIONS parameter UseParallel:
must be 'always' or 'never'.
Error in Damper_Optimization_v1 (line 134)
options = optimoptions('fmincon','UseParallel',true);
Please not the Damper_Optimization_v1 is the name of my script (where fmincon is used) and that line 134 is the line of
options = optimoptions('fmincon','UseParallel',true);
Does anybone know why I am getting this error?
I tried to use "always" instead of "true" but this did not work, I got the following error
Undefined function or variable 'always'.
Error in Damper_Optimization_v1 (line 151)
options = optimoptions('fmincon','UseParallel',always);
PS: I noted that when I add the line with the parallel computing option, the word "options" in the previous line is underlined in red and the warning message that I get for it is
The value assigned to variable 'options' might be unused
See below the rest of the code where I use fmincon
options = optimoptions('fmincon'); % Start with the default options options = optimoptions(options,'Algorithm', 'interior-point'); options = optimoptions(options,'Display', 'iter-detailed'); options = optimoptions(options,'MaxIter', 1000); options = optimoptions(options,'PlotFcns', { @optimplotfval }); %options = optimoptions('fmincon','UseParallel',true);
options = optimoptions('fmincon'); % Start with the default options options = optimoptions(options,'Algorithm', 'interior-point'); options = optimoptions(options,'Display', 'iter-detailed'); options = optimoptions(options,'MaxIter', 1000); options = optimoptions(options,'PlotFcns', { @optimplotfval }); %options = optimoptions('fmincon','UseParallel',true);
OPTIMIZATION
tic % Start stopwatch to measure elapsed time
[Optimum_Damper,fun_value,exitflag,output_details] = fmincon(...
@Objective,... % Cost Function
Damper_Parameter_Initial_Guess,...% Initial Guess
A,B,... % Damper Parameters Constrains
[],[],... % Damper Parameters Inequalities
Damper_Parameters_Lower_Bound,... % Damper Parameter Lower Bounds
Damper_Parameters_Upper_Bound,... % Damper Parameter Lower Bounds
[], ... % Non-linear conditions (NONE)
options); % Options
toc
Thanks in advance for your help
G
4 Comments
SHAMSUL FAISAL
on 17 Aug 2016
Good day,
I am a beginner in Simulink Design Optimization toolbox. Currently I am estimating a system that has more than 20 parameters and it takes more than 2 hours to complete the estimation. Therefore, I decided to try utilising the Parallel Computing Toolbox.
I tried to practise the Parallel Computing Toolbox by modifying the existing example given by MATLAB, which is the 'Estimate Model Parameters and Initial States (Code)' example which can be referred in detail in the following link: The original code is as follow:
opt = sdo.OptimizeOptions;
opt.Method = 'lsqnonlin';
The reason why I found this thread is because initially I also made the same mistake like Giuseppe Naselli while using MATLAB R2013b, which is:
opt = sdo.OptimizeOptions;
opt.Method = 'lsqnonlin';
opt.UseParallel = true;
After reading this thread, I made the correction. The complete code is shown below:
opt = sdo.OptimizeOptions;
opt.Method = 'lsqnonlin';
opt.UseParallel = 'always';
opt.OptimizedModel = 'initialcondition';
opt.ParallelPathDependencies = sdo.getModelDependencies('initialcondition');
%parpool
Please take note that I don't use the parpool command because I commented it out. I don't use the parpool because so far I can't see what is the difference between using and not using it.
The source code can be executed without error. However, I noticed that the following message appear while running the 'pOpt = sdo.optimize(estFcn,p,opt)' command:
Failed to get RMI data for fl_lib/Electrical/Electrical Elements/Capacitor. Library "fl_lib" is not loaded.
Failed to get RMI data for elec_lib/Additional
Components/SPICE-Compatible
Components/Sources/DC Voltage Source. Library "elec_lib" is not loaded.
Failed to get RMI data for fl_lib/Electrical/Electrical Elements/Electrical Reference. Library "fl_lib" is not loaded.
Failed to get RMI data for nesl_utility/PS-Simulink
Converter. Library "nesl_utility" is not loaded.
Failed to get RMI data for fl_lib/Electrical/Electrical Elements/Resistor. Library "fl_lib" is not loaded.
Failed to get RMI data for nesl_utility/Solver
Configuration. Library "nesl_utility" is not loaded.
Failed to get RMI data for fl_lib/Electrical/Electrical Sensors/Voltage Sensor. Library "fl_lib" is not loaded.
Configuring parallel workers for optimization...
May I know what did I do wrong until this messages appear? Please feel free to inform me if you would like to see the full script and objective function.
Thank you.
SHAMSUL FAISAL
on 17 Aug 2016
All right. I managed to get rid of those messages by deleting the 'opt.ParallelPathDependencies = sdo.getModelDependencies('initialcondition');' command. Therefore, my latest code is as follow:
opt = sdo.OptimizeOptions;
opt.Method = 'lsqnonlin';
opt.UseParallel = 'always';
opt.OptimizedModel = 'initialcondition';
%parpool
However, I still need some time to study what is the purpose of the 'parpool' command. I noticed that the simulation elapsed time is faster whenever I don't use the parpool command (90 seconds when not using vs 60 seconds when using).
Please advice if I miss any other setting that I should use for this Parrallel Computing Toolbox.
Thank you.
Accepted Answer
Alan Weiss
on 1 Apr 2014
I think there might be two issues here.
- The value true for UseParallel was added in R2014a. If you use an earlier version, set UseParallel to 'always'. Include the single quotes.
- In your fmincon call, do you pass options? I mean, does your call look like this:
[x,fval,exitflag] = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options)
Alan Weiss
MATLAB mathematical toolbox documentation
9 Comments
More Answers (0)
See Also
Categories
Find more on Systems of Nonlinear Equations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!