code: def get_experiment_fitnesses(experiments, optimizer, config, logger):
      with model.get_db_provider() as db:
          progbar = Progbar(len(experiments), interval=0.0)
          logger.info(
              "Waiting for fitnesses from %s experiments"
              % len(experiments)
          )
  
          bad_line_dicts = [dict() for x in range(len(experiments))]
          has_result = [False for i in range(len(experiments))]
          fitnesses = [0.0 for i in range(len(experiments))]
          behaviors = [None for i in range(len(experiments))]
          term_criterion = config["optimizer"]["termination_criterion"]
          skip_gen_thres = term_criterion["skip_gen_thres"]
          skip_gen_timeout = term_criterion["skip_gen_timeout"]
          result_timestamp = time.time()
  
          while sum(has_result) < len(experiments):
              for i, experiment in enumerate(experiments):
                  if (
                      float(sum(has_result)) / len(experiments)
                      >= skip_gen_thres
                      and time.time() - result_timestamp
                      > skip_gen_timeout
                  ):
                      logger.warn(
                          "Skipping to next gen with %s of solutions evaled"
                          % (float(sum(has_result)) / len(experiments))
                      )
                      has_result = [True] * len(experiments)
                      break
                  if has_result[i]:
                      continue
                  returned_experiment = db.get_experiment(
                      experiment.key, getinfo=True
                  )
                  output = db._get_experiment_logtail(
                      returned_experiment
                  )
                  if output is None:
                      continue
  
                  for j, line in enumerate(output):
                      if (
                          line.startswith(
                              "Traceback (most recent call last):"
                          )
                          and j not in bad_line_dicts[i]
                      ):
                          logger.warn(
                              "Experiment %s: error"
                              " discovered in output"
                              % returned_experiment.key
                          )
                          logger.warn("".join(output[j:]))
                          bad_line_dicts[i][j] = True
  
                      if line.startswith("Behavior") or line.startswith(
                          "behavior"
                      ):
                          try:
                              behavior = eval(
                                  line.rstrip().split(":")[1]
                              )
                              if isinstance(behavior, np.ndarray):
                                  pass
                              elif isinstance(behavior, list):
                                  behavior = np.array(behavior)
                              else:
                                  raise
  
                          except BaseException:
                              util.check_for_kb_interrupt()
                              if j not in bad_line_dicts[i]:
                                  logger.warn(
                                      "Experiment %s: error parsing or invalid"
                                      " behavior"
                                      % returned_experiment.key
                                  )
                                  logger.warn(line)
                                  bad_line_dicts[i][j] = True
                          else:
                              behaviors[i] = behavior
  
                      if line.startswith("Fitness") or line.startswith(
                          "fitness"
                      ):
                          try:
                              fitness = float(
                                  line.rstrip().split(":")[1]
                              )
                              # assert fitness >= 0.0
                          except BaseException:
                              util.check_for_kb_interrupt()
                              if j not in bad_line_dicts[i]:
                                  logger.warn(
                                      "Experiment %s: error parsing or invalid"
                                      " fitness"
                                      % returned_experiment.key
                                  )
                                  logger.warn(line)
                                  bad_line_dicts[i][j] = True
                          else:
                              if fitness < 0.0:
                                  logger.warn(
                                      "Experiment %s: returned"
                                      " fitness is less than zero,"
                                      " setting it to zero"
                                      % returned_experiment.key
                                  )
                                  fitness = 0.0
  
                              fitnesses[i] = fitness
                              has_result[i] = True
                              progbar.add(1)
                              result_timestamp = time.time()
                              break
  
              time.sleep(config["sleep_time"])
          return fitnesses, behaviors
  
imports: import copy
  import sys
  import argparse
  import re
  import os
  import uuid
  import importlib
  import time
  import six
  import numpy
  from studio.credentials.credentials import KEY_CREDENTIALS
  from studio.hyperparameter import HyperparameterParser
  from studio.extra_util import Progbar, rsync_cp
  from studio.experiments.experiment import create_experiment
  from studio.experiment_submitter import submit_experiments
  from studio import model
  from studio import git_util
  from studio import local_worker
  from studio import fs_tracker
  from studio.dependencies_policies.studio_dependencies_policy import StudioDependencyPolicy
  from studio.util import logs, util
label_desc: Use image node_id 3 for calling a global function with example usage: get_experiment_fitnesses(experiments, optimizer, config, logger) and returns: fitnesses,  behaviors