What does useParallel doesn't work with Automatic Differentiation means and how do I fix it?

2 visualizaciones (últimos 30 días)
Yagiz Dereboy el 21 de Ag. de 2022
Respondida: Alan Weiss el 21 de Ag. de 2022
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 = 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 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Respuestas (1)

Alan Weiss el 21 de Ag. de 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.
Alan Weiss
MATLAB mathematical toolbox documentation
0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Categorías

Más información sobre Solver Outputs and Iterative Display en Help Center y File Exchange.

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by