Error using 'cada/adigatorVarAnalyzer'
A MATLAB Automatic Differentiation Tool
Brought to you by:
anilvrao2,
weinstein87
Hello,
I am trying to use Adigator to calculate gradients for an optimization problem using 'fmincon'. After solving a number of parsing problems, I am stuck at a place which gives me the following set of errors:
====================================================
Error using cada/adigatorVarAnalyzer (line 111)
variable 'cadainput7_2' is either an auxiliary or global variable
which was re-assigned to have derivative information - this is not
allowed.
Error in adigatortempfunc1 (line 114)
cadainput7_2 = adigatorVarAnalyzer('cadainput7_2 =
q(:,j-1);',cadainput7_2,'cadainput7_2',0);
Error in adigator (line 539)
FunctionInfo = adigatortempfunc1(FunctionInfo,UserFunInputs);
Error in adigatorGenFiles4Fmincon (line 186)
conout1 = adigator(ConFunName,Inputs,ConD1FileName,opts);
Error in optimize_adi (line 86)
adifuncs = adigatorGenFiles4Fmincon(setup);
====================================================
Could you provide me any hint(s) as to where I can begin to solve this error? I would be happy to provide as much information as possible (except for the source code, apologies in advance).
Thank you very much,
Uday
Does your code use conditional statements (like if ... else ... statements) to assign variables?
Hi Uday
Sorry for the late reply. I think what is happening is that you are calling a sub-function twice within the same code, one time it is using an auxiliary input (flowed down from either the main function call or a global) and then calling the same function later with a non-auxiliary input.
The algorithm treats these auxiliary variables differently (doesn't turn them into a structure with .f .dx fields) which can mess some things up - it is something I struggled with for awhile and it still isn't very clean. For example, using this function code:
with this driver:
produces a similar error:
You can work around it by just adding a temporary input that does some superfluous operation prior to the first call. For example
Will get rid of the error as the "tmp" variable will no longer be flagged as auxiliary.
Matt
Last edit: Matthew J. Weinstein 2017-03-06