code: def optimizer(op, search, cost_metric, perf_metric):
      totex = op.num_experiments()
      rs = np.random.RandomState(123)
      if totex > 1:
          experiments = rs.permutation(totex - 2) + 1
          experiments = [0, totex - 1] + list(experiments)
      else:
          experiments = [0]
  
      print(f"total nb experiments {totex}, running {len(experiments)}")
  
      for cno in experiments:
          key = op.cno_to_key(cno)
          parameters = op.get_parameters(key)
  
          (max_perf, min_cost) = op.predict_bounds(key)
          if not op.is_pareto_optimal(max_perf, min_cost):
              logger.info(
                  f"{cno=:4d} {str(parameters):50}: SKIP, {max_perf=:.3f} {min_cost=:.3f}",
              )
              continue
  
          logger.info(f"{cno=:4d} {str(parameters):50}: RUN")
          cost, perf, requires = search(
              parameters,
              cost_metric,
              perf_metric,
          )
          if requires is not None:
              return requires
          logger.info(
              f"{cno=:4d} {str(parameters):50}: DONE, {cost=:.3f} {perf=:.3f}"
          )
          op.add_operating_point(key, perf, cost)
      return None
  
imports: import logging
  from copy import copy
  from dataclasses import dataclass
  from operator import itemgetter
  from statistics import median, mean
  from typing import Any, Dict, List, Optional
  from .utils import dict_merge
  from .index import Index, IndexFromCodec, IndexFromFactory
  from .descriptors import DatasetDescriptor, IndexDescriptor
  import faiss
  import numpy
  from scipy.optimize import curve_fit
label_desc: Use image node_id 2 for calling a global function with example usage: optimizer(op, search, cost_metric, perf_metric) and returns: None, requires