Menu

Error using 'cada/adigatorVarAnalyzer'

Help
2017-01-26
2017-01-26
  • Uday Phutane

    Uday Phutane - 2017-01-26

    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

     
  • Stuart Rogers

    Stuart Rogers - 2017-02-19

    Does your code use conditional statements (like if ... else ... statements) to assign variables?

     
  • Matthew J. Weinstein

    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:

    function z = myfun(x,a)
    
    b = mysubfunc(x,a);
    
    c = mysubfunc(x,x);
    
    z = b+c;
    
    end
    
    function y = mysubfunc(x,a)
    
    y = x + a;
    end
    

    with this driver:

    in = adigatorCreateDerivInput([1 1],'x');
    a = adigatorCreateAuxInput([1 1]);
    adigator('myfun',{in,a},'myder',adigatorOptions('overwrite',1));
    

    produces a similar error:

    Error using cada/adigatorVarAnalyzer (line 111)
    variable 'cadainput2_2' is either an auxiliary or
    global variable which was re-assigned to have
    derivative information - this is not allowed.
    
    Error in adigatortempfunc1 (line 20)
    cadainput2_2 = adigatorVarAnalyzer('cadainput2_2 =
    x(1);',cadainput2_2,'cadainput2_2',0);
    
    Error in adigator (line 541)
      FunctionInfo =
      adigatortempfunc1(FunctionInfo,UserFunInputs);
    
    Error in test (line 5)
    adigator('myfun',{in,a},'myder',adigatorOptions('overwrite',1)); 
    

    You can work around it by just adding a temporary input that does some superfluous operation prior to the first call. For example

    function z = myfun(x,a)
    
    tmp = a + 0;
    
    b = mysubfunc(x,tmp);
    
    c = mysubfunc(x,x);
    
    z = b+c;
    
    end
    
    function y = mysubfunc(x,a)
    
    y = x + a;
    end
    

    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

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.