class_docstr: Tool for running many experiments given hyperparameter ranges.
class_docstr_tok: ["Tool","for","running","many","experiments","given","hyperparameter","ranges","."]
docstr: Run each variant in the grid with function 'thunk'.
  
  Note: 'thunk' must be either a callable function, or a string. If it is
  a string, it must be the name of a parameter whose values are all 
  callable functions.
  
  Uses ``call_experiment`` to actually launch each experiment, and gives
  each variant a name using ``self.variant_name()``. 
  
  Maintenance note: the args for ExperimentGrid.run should track closely
  to the args for call_experiment. However, ``seed`` is omitted because
  we presume the user may add it as a parameter in the grid.
docstr_tok: ["Run","each","variant","in","the","grid","with","function","'thunk","'",".","Note",":","'thunk","'","must","be","either","a","callable","function",",","or","a","string",".","If","it","is","a","string",",","it","must","be","the","name","of","a","parameter","whose","values","are","all","callable","functions",".","Uses","``","call_experiment","``","to","actually","launch","each","experiment",",","and","gives","each","variant","a","name","using","``","self.variant_name","(",")","``",".","Maintenance","note",":","the","args","for","ExperimentGrid.run","should","track","closely","to","the","args","for","call_experiment",".","However",",","``","seed","``","is","omitted","because","we","presume","the","user","may","add","it","as","a","parameter","in","the","grid","."]
code: def run(self, thunk, num_cpu=1, data_dir=None, datestamp=False):
      """
      Run each variant in the grid with function 'thunk'.
  
      Note: 'thunk' must be either a callable function, or a string. If it is
      a string, it must be the name of a parameter whose values are all
      callable functions.
  
      Uses ``call_experiment`` to actually launch each experiment, and gives
      each variant a name using ``self.variant_name()``.
  
      Maintenance note: the args for ExperimentGrid.run should track closely
      to the args for call_experiment. However, ``seed`` is omitted because
      we presume the user may add it as a parameter in the grid.
      """
  
      # Print info about self.
      self.print()
  
      # Make the list of all variants.
      variants = self.variants()
  
      # Print variant names for the user.
      var_names = set([self.variant_name(var) for var in variants])
      var_names = sorted(list(var_names))
      line = "=" * DIV_LINE_WIDTH
      preparing = colorize(
          "Preparing to run the following experiments...",
          color="green",
          bold=True,
      )
      joined_var_names = "\n".join(var_names)
      announcement = f"\n{preparing}\n\n{joined_var_names}\n\n{line}"
      print(announcement)
  
      if WAIT_BEFORE_LAUNCH > 0:
          delay_msg = (
              colorize(
                  dedent(
                      """
              Launch delayed to give you a few seconds to review your experiments.
  
              To customize or disable this behavior, change WAIT_BEFORE_LAUNCH in
              spinup/user_config.py.
  
              """
                  ),
                  color="cyan",
                  bold=True,
              )
              + line
          )
          print(delay_msg)
          wait, steps = WAIT_BEFORE_LAUNCH, 100
          prog_bar = trange(
              steps,
              desc="Launching in...",
              leave=False,
              ncols=DIV_LINE_WIDTH,
              mininterval=0.25,
              bar_format="{desc}: {bar}| {remaining} {elapsed}",
          )
          for _ in prog_bar:
              time.sleep(wait / steps)
  
      # Run the variants.
      for var in variants:
          exp_name = self.variant_name(var)
  
          # Figure out what the thunk is.
          if isinstance(thunk, str):
              # Assume one of the variant parameters has the same
              # name as the string you passed for thunk, and that
              # variant[thunk] is a valid callable function.
              thunk_ = var[thunk]
              del var[thunk]
          else:
              # Assume thunk is given as a function.
              thunk_ = thunk
  
          call_experiment(
              exp_name,
              thunk_,
              num_cpu=num_cpu,
              data_dir=data_dir,
              datestamp=datestamp,
              **var,
          )
  
imports: from spinup.user_config import DEFAULT_DATA_DIR, FORCE_DATESTAMP, DEFAULT_SHORTHAND, WAIT_BEFORE_LAUNCH
  from spinup.utils.logx import colorize
  from spinup.utils.mpi_tools import mpi_fork, msg
  from spinup.utils.serialization_utils import convert_json
  import base64
  from copy import deepcopy
  import cloudpickle
  import json
  import numpy
  import os
  import os.path
  import psutil
  import string
  import subprocess
  from subprocess import CalledProcessError
  import sys
  from textwrap import dedent
  import time
  from tqdm import trange
  import zlib
label_desc: Use image node_id 9 for calling the ExperimentGrid obj's underlying member method code with example usage: obj.run(thunk, num_cpu, data_dir, datestamp) without return types