code: def optimize(
      solver, func, maximize=True, max_evals=0, pmap=map, decoder=None
  ):
      """Optimizes func with given solver.
  
      :param solver: the solver to be used, for instance a result from :func:`optunity.make_solver`
      :param func: the objective function
      :type func: callable
      :param maximize: maximize or minimize?
      :type maximize: bool
      :param max_evals: maximum number of permitted function evaluations
      :type max_evals: int
      :param pmap: the map() function to use, to vectorize use :func:`optunity.parallel.pmap`
      :type pmap: function
  
      Returns the solution and a namedtuple with further details.
      Please refer to docs of optunity.maximize_results
      and optunity.maximize_stats.
  
      """
  
      if max_evals > 0:
          f = fun.max_evals(max_evals)(func)
      else:
          f = func
  
      f = fun.logged(f)
      num_evals = -len(f.call_log)
  
      time = timeit.default_timer()
      try:
          solution, report = solver.optimize(f, maximize, pmap=pmap)
      except fun.MaximumEvaluationsException:
          # early stopping because maximum number of evaluations is reached
          # retrieve solution from the call log
          report = None
          if maximize:
              index, _ = max(
                  enumerate(f.call_log.values()),
                  key=operator.itemgetter(1),
              )
          else:
              index, _ = min(
                  enumerate(f.call_log.values()),
                  key=operator.itemgetter(1),
              )
          solution = list(f.call_log.keys())[index]._asdict()
      time = timeit.default_timer() - time
  
      # TODO why is this necessary?
      if decoder:
          solution = decoder(solution)
  
      optimum = f.call_log.get(**solution)
      num_evals += len(f.call_log)
  
      # use namedtuple to enforce uniformity in case of changes
      stats = optimize_stats(num_evals, time)
  
      call_dict = f.call_log.to_dict()
      return solution, optimize_results(
          optimum, stats._asdict(), call_dict, report
      )
  
imports: import timeit
  import sys
  import operator
  from .None import functions
  from .None import solvers
  from .None import search_spaces
  from .solvers import solver_registry
  from .util import DocumentedNamedTuple
  from .constraints import wrap_constraints
label_desc: Use image node_id 7 for calling a global function with example usage: optimize(solver, func, maximize, max_evals, pmap, decoder) and returns: solution,  optimize_results