code: def optimize(solver, mapper, nodes, target="rosen", **kwds):
      if target == "rosen":  # 3d-rosenbrock
          # Rosenbrock function
          from dejong import rosen as the_model
  
          ndim = 3
          actual_coeffs = [1.0] * ndim
          pprint = list
      else:  # 4th-order chebyshev
          # Chebyshev cost function
          from poly import chebyshev4cost as the_model
          from poly import chebyshev4coeffs as actual_coeffs
  
          ndim = len(actual_coeffs)
          from mystic.math import poly1d as pprint
  
      # number of trials
      N = nodes
      print("Number of trials: %s" % N)
      print("===============")
  
      # initial guess
      import random
  
      x0 = (
          [random.uniform(-100, 100) for i in range(ndim)]
          for i in range(N)
      )
      model = (the_model for i in range(N))
  
      # minimize the function
      results = mapper(nodes).map(the_solver, model, x0)
  
      # find the results with the lowest energy
      from optimize_helper import best_results
  
      solution = best_results(results)
  
      print("===============")
      print("Actual params:\n %s" % pprint(actual_coeffs))
      print("Solved params:\n %s" % pprint(solution[0]))
      print("Function value: %s" % solution[1])
      print("Total function evals: %s" % solution[4])
      return
  
imports: from optimize_helper import fmin_powell
  from pathos.serial import SerialPool
  from pathos.parallel import ParallelPool
  from pathos.multiprocessing import ProcessPool
  from pyina.launchers import Mpi
label_desc: Use image node_id 1 for calling a global function with example usage: optimize(solver, mapper, nodes, target) without return types