How can I fix SOLVE ignores UseParallel when derivatives calculated automatic differentiation warning for parallel computing?
1 view (last 30 days)
Show older comments
I coded an NLP version of the p-median problem which I am solving by fmincon. I wanted to use UseParallel to speed up the process. But I get the fallowing warning: SOLVE ignores UseParallel when derivatives calculated using Automatic Differentiation. Could you please show me how to use parallel computing with such a code?
A = readmatrix("Iris.csv");
A = A(:,1:5);
A = normalize(A);
dist_mat = pdist(A);
dist_mat = squareform(dist_mat);
x0x = zeros(150,150) + 1/150;
x0y = zeros(150,1) + 1/150;
% Create optimization variables
x = optimvar("x",150,150,"LowerBound",0,"UpperBound",1);
y = optimvar("y",150,1,"LowerBound",0,"UpperBound",1);
% Set initial starting point for the solver
initialPoint.x = x0x;
initialPoint.y = x0y;
% Create problem
problem = optimproblem;
% Define problem objective
problem.Objective = sum(dist_mat.*x,...
'all')+ sum(50.*(y.^2)./((y.^2) + 0.001));
% Define problem constraints
problem.Constraints.Xeq = sum(x,2)==1;
problem.Constraints.Yeq = sum(y)==2;
problem.Constraints.XYineq = x - repmat(y',150,1) <= 0;
% Set nondefault solver options
options = optimoptions("fmincon","Algorithm","interior-point", ...
"HessianApproximation","lbfgs","UseParallel",true,"MaxIterations",10000,"MaxFunctionEvaluations",10000,"Display","iter");
% Display problem information
%show(problem);
% Solve problem
[solution,objectiveValue,reasonSolverStopped] = solve(problem,initialPoint,...
"Solver","fmincon","Options",options);
0 Comments
Answers (1)
Matt J
on 21 Aug 2022
It's not something to fix. It's what you want. Analytical differentiation is the fastest option, when it is available.
2 Comments
Matt J
on 21 Aug 2022
You might be able to do a little better if you use fmincon directly and use SpecifyObjectiveGradient=true. I wouldn't expect a huge improvement.
In either case, UseParallel is not the path to optimal speed here. Your gradients are nice and simple and can be computed analytically.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!