code: def optimize(cost, lower, upper, nbins):
      from mystic.tools import random_seed
      from pathos.pools import ProcessPool as Pool
  
      random_seed(123)
  
      # generate arrays of points defining a grid in parameter space
      grid_dimensions = len(lower)
      bins = []
      for i in range(grid_dimensions):
          step = abs(upper[i] - lower[i]) / nbins[i]
          bins.append(
              [lower[i] + (j + 0.5) * step for j in range(nbins[i])]
          )
  
      # build a grid of starting points
      from pool_helper import local_optimize
      from mystic.math.grid import gridpts
  
      initial_values = gridpts(bins)
  
      # run optimizer for each grid point
      lb = [lower for i in range(len(initial_values))]
      ub = [upper for i in range(len(initial_values))]
      cf = [cost for i in range(len(initial_values))]
      nnodes = len(lb)
  
      # map:: params, energy, func_evals = local_optimize(cost,x0,lb,ub)
      results = Pool(nnodes).map(
          local_optimize, cf, initial_values, lb, ub
      )
      # print("results = %s" % results)
  
      # get the results with the lowest energy
      best = list(results[0][0]), results[0][1]
      func_evals = results[0][2]
      for result in results[1:]:
          func_evals += result[2]  # add function evaluations
          if result[1] < best[1]:  # compare energy
              best = list(result[0]), result[1]
  
      # return best
      print("solved: %s" % best[0])
      scale = 1.0
      diameter_squared = -best[1] / scale  # XXX: scale != 0
      return diameter_squared, func_evals
  
imports: from surrogate import ballistic_limit
label_desc: Use image node_id 2 for calling a global function with example usage: optimize(cost, lower, upper, nbins) and returns: diameter_squared,  func_evals