code: def fmin_powell(
      cost,
      x0,
      args=(),
      bounds=None,
      xtol=1e-4,
      ftol=1e-4,
      maxiter=None,
      maxfun=None,
      full_output=0,
      disp=1,
      retall=0,
      callback=None,
      direc=None,
      **kwds,
  ):
      """Minimize a function using modified Powell's method.
  
      Uses a modified Powell Directional Search algorithm to find the minimum of a
      function of one or more variables. This method only uses function values,
      not derivatives. Mimics the ``scipy.optimize.fmin_powell`` interface.
  
      Powell's method is a conjugate direction method that has two loops. The outer
      loop simply iterates over the inner loop, while the inner loop minimizes over
      each current direction in the direction set. At the end of the inner loop,
      if certain conditions are met, the direction that gave the largest decrease
      is dropped and replaced with the difference between the current estimated x
      and the estimated x from the beginning of the inner-loop. The conditions for
      replacing the direction of largest increase is that: (a) no further gain can
      be made along the direction of greatest increase in the iteration, and (b) the
      direction of greatest increase accounted for a large sufficient fraction of
      the decrease in the function value from the current iteration of the inner loop.
  
      Args:
          cost (func): the function or method to be minimized: ``y = cost(x)``.
          x0 (ndarray): the initial guess parameter vector ``x``.
          args (tuple, default=()): extra arguments for cost.
          bounds (list(tuple), default=None): list of pairs of bounds (min,max),
              one for each parameter.
          xtol (float, default=1e-4): acceptable relative error in ``xopt`` for
              convergence.
          ftol (float, default=1e-4): acceptable relative error in ``cost(xopt)``
              for convergence.
          gtol (float, default=2): maximum iterations to run without improvement.
          maxiter (int, default=None): the maximum number of iterations to perform.
          maxfun (int, default=None): the maximum number of function evaluations.
          full_output (bool, default=False): True if fval and warnflag are desired.
          disp (bool, default=True): if True, print convergence messages.
          retall (bool, default=False): True if allvecs is desired.
          callback (func, default=None): function to call after each iteration. The
              interface is ``callback(xk)``, with xk the current parameter vector.
          direc (tuple, default=None): the initial direction set.
          id (int, default=None): the ``id`` of the solver used in logging.
          handler (bool, default=False): if True, enable handling interrupt signals.
          itermon (monitor, default=None): override the default GenerationMonitor.
          evalmon (monitor, default=None): override the default EvaluationMonitor.
          constraints (func, default=None): a function ``xk' = constraints(xk)``,
              where xk is the current parameter vector, and xk' is a parameter
              vector that satisfies the encoded constraints.
          penalty (func, default=None): a function ``y = penalty(xk)``, where xk is
              the current parameter vector, and ``y' == 0`` when the encoded
              constraints are satisfied (and ``y' > 0`` otherwise).
          tightrange (bool, default=None): impose bounds and constraints concurrently.
          cliprange (bool, default=None): bounding constraints clip exterior values.
  
      Returns:
          ``(xopt, {fopt, iter, funcalls, warnflag, direc}, {allvecs})``
  
      Notes:
          - xopt (*ndarray*): the minimizer of the cost function
          - fopt (*float*): value of cost function at minimum: ``fopt = cost(xopt)``
          - iter (*int*): number of iterations
          - funcalls (*int*): number of function calls
          - warnflag (*int*): warning flag
              - ``1 : Maximum number of function evaluations``
              - ``2 : Maximum number of iterations``
          - direc (*tuple*): the current direction set
          - allvecs (*list*): a list of solutions at each iteration
      """
      # FIXME: need to resolve "direc"
      #        - should just pass 'direc', and then hands-off ?  How return it ?
      # XXX: enable use of imax?
  
      handler = kwds["handler"] if "handler" in kwds else False
  
      from mystic.monitors import Monitor
  
      stepmon = kwds["itermon"] if "itermon" in kwds else Monitor()
      evalmon = kwds["evalmon"] if "evalmon" in kwds else Monitor()
  
      gtol = 2  # termination generations (scipy: 2, default: 10)
      if "gtol" in kwds:
          gtol = kwds["gtol"]
      if gtol:  # if number of generations is provided, use NCOG
          from mystic.termination import (
              NormalizedChangeOverGeneration as NCOG,
          )
  
          termination = NCOG(ftol, gtol)
      else:
          from mystic.termination import VTRChangeOverGeneration
  
          termination = VTRChangeOverGeneration(ftol)
  
      solver = PowellDirectionalSolver(len(x0))
      solver.SetInitialPoints(x0)
      solver.SetEvaluationLimits(maxiter, maxfun)
      solver.SetEvaluationMonitor(evalmon)
      solver.SetGenerationMonitor(stepmon)
      if "id" in kwds:
          solver.id = int(kwds["id"])
      if "penalty" in kwds:
          solver.SetPenalty(kwds["penalty"])
      if "constraints" in kwds:
          solver.SetConstraints(kwds["constraints"])
      if bounds is not None:
          minb, maxb = unpair(bounds)
          tight = kwds["tightrange"] if "tightrange" in kwds else None
          clip = kwds["cliprange"] if "cliprange" in kwds else None
          solver.SetStrictRanges(minb, maxb, tight=tight, clip=clip)
  
      if handler:
          solver.enable_signal_handler()
      solver.Solve(
          cost,
          termination=termination,
          xtol=xtol,
          ExtraArgs=args,
          callback=callback,
          disp=disp,
          direc=direc,
      )  # XXX: last two lines use **kwds
      solution = solver.Solution()
  
      # code below here pushes output to scipy.optimize.fmin_powell interface
      # x = list(solver.bestSolution)
      x = solver.bestSolution
      fval = solver.bestEnergy
      warnflag = 0
      fcalls = solver.evaluations
      iterations = solver.generations
      allvecs = stepmon.x
      direc = solver._direc
  
      if fcalls >= solver._maxfun:
          warnflag = 1
      elif iterations >= solver._maxiter:
          warnflag = 2
  
      x = squeeze(x)  # FIXME: write squeezed x to stepmon instead?
  
      if full_output:
          retlist = x, fval, iterations, fcalls, warnflag, direc
          if retall:
              retlist += (allvecs,)
      else:
          retlist = x
          if retall:
              retlist = (x, allvecs)
  
      return retlist
  
imports: from mystic.tools import wrap_function, unpair, wrap_nested
  from mystic.tools import wrap_bounds, wrap_penalty, reduced
  import numpy
  from numpy import eye, zeros, shape, asarray, absolute, asfarray
  from numpy import clip, squeeze
  from mystic._scipy060optimize import brent
  from mystic.abstract_solver import AbstractSolver
label_desc: Use image node_id 3 for calling a global function with example usage: fmin_powell(cost, x0, args, bounds, xtol, ftol, maxiter, maxfun, full_output, disp, retall, callback, direc) and returns: retlist