Why am I getting the error 'An UndefinedFunction error was thrown on the workers for...' whenever I try to use parallel processing with FMINCON to estimate numerical gradients?

5 views (last 30 days)
My constrained non linear optimization problem has 2 state variables V_1 and V_2 each containing 6 scalar components(position and velocity) and associated propagation times t_1 and t_2 in a dynamical system. My vector for optimization is thus X = {V_1;V_2;t_1;t_2} It has a total of 14 variables.
In the constraint function I separate out the appropriate state V_1 and V_2 into a matlab variable 'leginit' by using a 'for' loop in a simple way
for i = 1:2 leginit(i,:)=X(6*(i-1)+1:6*i); end
Now leginit contains the initial conditions for propagation which I do it in another 'for' loop using ODE45 for the stipulated integration time t_1 and t_2 respectively. Then the constraint equation is that the final states of propagation are equal to each other
i.e c(x) = V_1_t_1(final state of propagation of V_1 for t_1 time) - V_2_t_2(final state of propagation of V_1 for t_1 time).
I am not providing any analytical derivatives for the constraint equation and instead would like to use the default numerical derivatives. Plus I wish to use parallel processing to speed up the process, but when I set my optim options to 'UseParallel' to 'always' and execute my program I always get the same error as follows
An UndefinedFunction error was thrown on the workers for 'leginit'. This might be because the file containing 'leginit' is not accessible on the workers. Use addAttachedFiles(pool, files) to specify the required files to be attached. See the documentation for 'parallel.Pool/addAttachedFiles' for more details.
I used the above addAttachedFiles(pools,files) function in my main program but it does not seem to rectify my problem. Could you please suggest what might be the issue and hot to overcome it?
P.S : The code works perfectly fine without parallel processing.

Answers (0)

Categories

Find more on Get Started with Optimization Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!