class_docstr: Creates experiment log directories and runs an experiment.
  
  This class should only be created by calling garage.wrap_experiment.
  Generally, it's used as a decorator like this:
  
      @wrap_experiment(snapshot_mode='all')
      def my_experiment(ctxt, seed, lr=0.5):
          ...
  
      my_experiment(seed=1)
  
  Even though this class could be implemented as a closure in
  wrap_experiment(), it's more readable (and easier to pickle) implemented as
  a class.
  
  Note that the full path that will be created is
  f'{data}/local/{prefix}/{name}'.
  
  Args:
      function (callable or None): The experiment function to wrap.
      log_dir (str or None): The full log directory to log to. Will be
          computed from `name` if omitted.
      name (str or None): The name of this experiment template. Will be
          filled from the wrapped function's name if omitted.
      prefix (str): Directory under data/local in which to place the
          experiment directory.
      snapshot_mode (str): Policy for which snapshots to keep (or make at
          all). Can be either "all" (all iterations will be saved), "last"
          (only the last iteration will be saved), "gap" (every snapshot_gap
          iterations are saved), or "none" (do not save snapshots).
      snapshot_gap (int): Gap between snapshot iterations. Waits this number
          of iterations before taking another snapshot.
      archive_launch_repo (bool): Whether to save an archive of the
          repository containing the launcher script. This is a potentially
          expensive operation which is useful for ensuring reproducibility.
      name_parameters (str or None): Parameters to insert into the experiment
          name. Should be either None (the default), 'all' (all parameters
          will be used), or 'passed' (only passed parameters will be used).
          The used parameters will be inserted in the order they appear in
          the function definition.
      use_existing_dir (bool): If true, (re)use the directory for this
          experiment, even if it already contains data.
      x_axis (str): Key to use for x axis of plots.
docstr: Make a context from the template information and variant args.
  
  Currently, all arguments should be keyword arguments.
  
  Args:
      options (dict): Options to `wrap_experiment` itself. See the
          function documentation for details.
      kwargs (dict): Keyword arguments for the wrapped function. Will be
          logged to `variant.json`
  
  Returns:
      ExperimentContext: The created experiment context.
docstr_tok: ["Make","a","context","from","the","template","information","and","variant","args",".","Currently",",","all","arguments","should","be","keyword","arguments",".","Args",":","options","(","dict",")",":","Options","to","`","wrap_experiment","`","itself",".","See","the","function","documentation","for","details",".","kwargs","(","dict",")",":","Keyword","arguments","for","the","wrapped","function",".","Will","be","logged","to","`","variant.json","`","Returns",":","ExperimentContext",":","The","created","experiment","context","."]
code: def _make_context(cls, options, **kwargs):
      """Make a context from the template information and variant args.
  
      Currently, all arguments should be keyword arguments.
  
      Args:
          options (dict): Options to `wrap_experiment` itself. See the
              function documentation for details.
          kwargs (dict): Keyword arguments for the wrapped function. Will be
              logged to `variant.json`
  
      Returns:
          ExperimentContext: The created experiment context.
  
      """
      name = options["name"]
      if name is None:
          name = options["function"].__name__
      name = cls._augment_name(options, name, kwargs)
      log_dir = options["log_dir"]
      if log_dir is None:
          log_dir = "{data}/local/{prefix}/{name}".format(
              data=os.path.join(os.getcwd(), "data"),
              prefix=options["prefix"],
              name=name,
          )
      if options["use_existing_dir"]:
          os.makedirs(log_dir, exist_ok=True)
      else:
          log_dir = _make_sequential_log_dir(log_dir)
  
      tabular_log_file = os.path.join(log_dir, "progress.csv")
      text_log_file = os.path.join(log_dir, "debug.log")
      variant_log_file = os.path.join(log_dir, "variant.json")
      metadata_log_file = os.path.join(log_dir, "metadata.json")
  
      dump_json(variant_log_file, kwargs)
      git_root_path, metadata = get_metadata()
      dump_json(metadata_log_file, metadata)
      if git_root_path and options["archive_launch_repo"]:
          make_launcher_archive(
              git_root_path=git_root_path, log_dir=log_dir
          )
  
      logger.add_output(dowel.TextOutput(text_log_file))
      logger.add_output(dowel.CsvOutput(tabular_log_file))
      logger.add_output(
          dowel.TensorBoardOutput(log_dir, x_axis=options["x_axis"])
      )
      logger.add_output(dowel.StdOutput())
  
      logger.push_prefix("[{}] ".format(name))
      logger.log("Logging to {}".format(log_dir))
  
      return ExperimentContext(
          snapshot_dir=log_dir,
          snapshot_mode=options["snapshot_mode"],
          snapshot_gap=options["snapshot_gap"],
      )
  
imports: import collections
  import datetime
  import enum
  import functools
  import gc
  import inspect
  import json
  import os
  import pathlib
  import subprocess
  import warnings
  import weakref
  import dateutil.tz
  import dowel
  from dowel import logger
  import numpy
  import __main__
label_desc: Use image node_id 5 for calling the ExperimentTemplate obj's underlying member method code with example usage: obj._make_context(cls, options) and returns: ExperimentContext