What does useParallel doesn't work with Automatic Differentiation means and how do I fix it?
2 views (last 30 days)
I am coding a p-median problem as an NLP. Code is below. Code is working by itseld and produces good results. But I want to speed up the computation by parallel processing. When I try to use useParallel = True it gives me the warning: SOLVE ignores UseParallel when derivatives calculated using Automatic Differentiation. Can you please help me understand this problem and how can I fix it? I would love to speed up computation.
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", ...
% Display problem information
% Solve problem
[solution,objectiveValue,reasonSolverStopped] = solve(problem,initialPoint,...
Alan Weiss on 21 Aug 2022
This is not a problem, this is a notification from internal algorithms. You are using the problem-based approach with supported objective and constraints. Internally, the software calculates the associated gradients analytically using Automatic Differentiation. Therefore, there is generally no benefit to estimating derivatives any other way. If you want to estimated derivatives using finite differences in parallel, well, you can by setting the 'ObjectiveDerivative' argument of solve to 'finite-differences' along with the 'UseParallel' option set to true. But I don't believe that this will give you much, if any benefit, and will likely be slower simply from parallel overhead.
MATLAB mathematical toolbox documentation