title: Objective function(black-box function) evaluation by an optimization solver irrespective of the algorithms it uses?
body: <p>The main idea here is to know how black-box functions are used in objective function definition and how optimization algorithms call these functions.</p>
  
  <p>Let' assume that we have a function defined as follows:</p>
  
  <p>f is an objective function to be minimized for a given problem.Lets say:</p>
  
  <p>f(Xi,Yi)=(Ai.Xi)+(Bi.Xi.Yi) for i=1,2...n</p>
  
  <p>where Yi= N(X1,X2,...Xn) is a blackbox function(a simulation) whose analytical form is unknown which takes all Xi's as inputs</p>
  
  <p>N refers to a network being simulated.</p>
  
  <p>Ai and Bi are constants</p>
  
  <p>The problem has the following constraints:</p>
  
  <p>X1+X2+...+Xn = C</p>
  
  <p>The below function definition is just to show how I've called my simulation results and used it in my optimization objective. I'm also open to suggestions if it could be made even better. (But my main question follows my function definition)</p>
  
  <pre><code>def fun(X): 
     sim_inpfile(X)  # function that has been already defined which is called now by taking x as arguments to write the input file to a simulation
     Popen('python Test02.py')  # running a python code to execute the simulation       
     jn.output.Results  # Extracting results of simulation by importing a custom made python module called jn 
     Y=[] # Simulation Result
     for i in range(len(jn.output.Results.res)):
        if jn.output.Results.res[i].name in nodes:
            y += [(jn.output.Results.res[i].pr)]  # extracting y as a list from the simulation results
     sum = 0 # optimization objective
     for i in range(len(a)):  # len[a]=len[b]=len[X]=len[Y]
        sum += a[i]*X[i]+ b[i]*X[i]*Y[i] #a and b are constants which are lists with the same size as x and y
    return sum   #the ultimate objective function that takes y(simulation results) as arguments to return the optimization objective value
  </code></pre>
  
  <p>I call a python optimization solver now.</p>
  
  <pre><code>res = scipy.optimize.minimize(fun, x0, method='SLSQP', bounds=bnds, constraints=cons)    # x0=initial x values, bounds= Variable bounds on X, Constraint =equality constraint 
  </code></pre>
  
  <p>Qns: </p>
  
  <ul>
  <li><p>For each iteration of the algorithm, will the objective function be
  called for evaluation?</p></li>
  <li><p>If yes, is the way I've coded, an appropriate way to return my objective<br>
  function with the black-box function evaluation at each iteration of
  the solver?</p></li>
  <li><p>Also if there or similar problems in any of python optimization packages or similar questions and examples, please share their links or threads.</p></li>
  </ul>
  
  <p>I appreciate you for your time and your experience may help me solve this problem.</p>