title: Python minimize function: passing additional arguments to constraint dictionary
body: <p>I don't know how to pass additional arguments through the minimize function to the constraint dictionary.  I can successfully pass additional arguments to the objective function.</p>
  
  <p>Documentation on minimize function is here: <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html#scipy.optimize.minimize" rel="noreferrer">http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html#scipy.optimize.minimize</a></p>
  
  <p>The constraints argument is a dict that has a field 'args', where args is a sequence.  I'm sure this is where I need to pass in the additional arguments but I don't know the syntax.  The closest I have got is below:</p>
  
  <pre><code>from scipy.optimize import minimize
  def f_to_min (x, p):
      return (p[0]*x[0]*x[0]+p[1]*x[1]*x[1]+p[2])
  
  f_to_min([1,2],[1,1,1]) # test function to minimize
  
  p=[] # define additional args to be passed to objective function
  f_to_min_cons=({'type': 'ineq', 'fun': lambda x, p : x[0]+p[0], 'args': (p,)}) # define constraint
  
  p0=np.array([1,1,1])
  minimize(f_to_min, [1,2], args=(p0,), method='SLSQP', constraints=f_to_min_cons)
  </code></pre>
  
  <p>I get the following error</p>
  
  <pre><code>---------------------------------------------------------------------------
  IndexError                                Traceback (most recent call last)
  &lt;ipython-input-19-571500063c9e&gt; in &lt;module&gt;()
        1 p0=np.array([1,1,1])
  ----&gt; 2 minimize(f_to_min, [1,2], args=(p0,), method='SLSQP', constraints=f_to_min_cons)
  
  C:\Python27\lib\site-packages\scipy\optimize\_minimize.pyc in minimize(fun, x0, args,     method, jac, hess, hessp, bounds, constraints, tol, callback, options)
      356     elif meth == 'slsqp':
      357         return _minimize_slsqp(fun, x0, args, jac, bounds,
  --&gt; 358                                constraints, **options)
      359     else:
      360         raise ValueError('Unknown solver %s' % method)
  
  C:\Python27\lib\site-packages\scipy\optimize\slsqp.pyc in _minimize_slsqp(func, x0,     args, jac, bounds, constraints, maxiter, ftol, iprint, disp, eps, **unknown_options)
      298     # meq, mieq: number of equality and inequality constraints
      299     meq = sum(map(len, [atleast_1d(c['fun'](x, *c['args'])) for c in     cons['eq']]))
  --&gt; 300     mieq = sum(map(len, [atleast_1d(c['fun'](x, *c['args'])) for c in     cons['ineq']]))
      301     # m = The total number of constraints
      302     m = meq + mieq
  
  &lt;ipython-input-18-163ef1a4f6fb&gt; in &lt;lambda&gt;(x, p)
  ----&gt; 1 f_to_min_cons=({'type': 'ineq', 'fun': lambda x, p : x[0]+p[0], 'args': (p,)})
  
  IndexError: list index out of range
  </code></pre>
  
  <p>I'm accessing the first element of the additional parameter so I shouldn't have an out of range error.</p>
  
  <p>If you remove the constraints=f_to_min_cons argument from the minimize function then the code above works.</p>