class_docstr: Object that handles running Dopamine experiments.
  
  This is mostly the same as discrete_domains.Runner, but is written solely for
  JAX/Flax agents.
class_docstr_tok: ["Object","that","handles","running","Dopamine","experiments",".","This","is","mostly","the","same","as","discrete_domains.Runner",",","but","is","written","solely","for","JAX\/Flax","agents","."]
docstr: Initialize the Runner object in charge of running a full experiment.
  
  Args:
    base_dir: str, the base directory to host all required sub-directories.
    create_agent_fn: A function that takes as argument an environment, and
      returns an agent.
    create_environment_fn: A function which receives a problem name and
      creates a Gym environment for that problem (e.g. an Atari 2600 game).
    checkpoint_file_prefix: str, the prefix to use for checkpoint files.
    logging_file_prefix: str, prefix to use for the log files.
    log_every_n: int, the frequency for writing logs.
    num_iterations: int, the iteration number threshold (must be greater than
      start_iteration).
    training_steps: int, the number of training steps to perform.
    evaluation_steps: int, the number of evaluation steps to perform.
    max_steps_per_episode: int, maximum number of steps after which an episode
      terminates.
    clip_rewards: bool, whether to clip rewards in [-1, 1].
    use_legacy_logger: bool, whether to use the legacy Logger. This will be
      deprecated soon, replaced with the new CollectorDispatcher setup.
  
  This constructor will take the following actions:
  - Initialize an environment.
  - Initialize a logger.
  - Initialize an agent.
  - Reload from the latest checkpoint, if available, and initialize the
    Checkpointer object.
docstr_tok: ["Initialize","the","Runner","object","in","charge","of","running","a","full","experiment",".","Args",":","base_dir",":","str",",","the","base","directory","to","host","all","required","sub-directories",".","create_agent_fn",":","A","function","that","takes","as","argument","an","environment",",","and","returns","an","agent",".","create_environment_fn",":","A","function","which","receives","a","problem","name","and","creates","a","Gym","environment","for","that","problem","(","e.g",".","an","Atari","2600","game",")",".","checkpoint_file_prefix",":","str",",","the","prefix","to","use","for","checkpoint","files",".","logging_file_prefix",":","str",",","prefix","to","use","for","the","log","files",".","log_every_n",":","int",",","the","frequency","for","writing","logs",".","num_iterations",":","int",",","the","iteration","number","threshold","(","must","be","greater","than","start_iteration",")",".","training_steps",":","int",",","the","number","of","training","steps","to","perform",".","evaluation_steps",":","int",",","the","number","of","evaluation","steps","to","perform",".","max_steps_per_episode",":","int",",","maximum","number","of","steps","after","which","an","episode","terminates",".","clip_rewards",":","bool",",","whether","to","clip","rewards","in","[","-1",",","1","]",".","use_legacy_logger",":","bool",",","whether","to","use","the","legacy","Logger",".","This","will","be","deprecated","soon",",","replaced","with","the","new","CollectorDispatcher","setup",".","This","constructor","will","take","the","following","actions",":","-","Initialize","an","environment",".","-","Initialize","a","logger",".","-","Initialize","an","agent",".","-","Reload","from","the","latest","checkpoint",",","if","available",",","and","initialize","the","Checkpointer","object","."]
code: def __init__(
      self,
      base_dir,
      create_agent_fn,
      create_environment_fn=gym_lib.create_gym_environment,
      checkpoint_file_prefix="ckpt",
      logging_file_prefix="log",
      log_every_n=1,
      num_iterations=200,
      training_steps=250000,
      evaluation_steps=125000,
      max_steps_per_episode=1000,
      clip_rewards=False,
      use_legacy_logger=True,
  ):
      """Initialize the Runner object in charge of running a full experiment.
  
      Args:
        base_dir: str, the base directory to host all required sub-directories.
        create_agent_fn: A function that takes as argument an environment, and
          returns an agent.
        create_environment_fn: A function which receives a problem name and
          creates a Gym environment for that problem (e.g. an Atari 2600 game).
        checkpoint_file_prefix: str, the prefix to use for checkpoint files.
        logging_file_prefix: str, prefix to use for the log files.
        log_every_n: int, the frequency for writing logs.
        num_iterations: int, the iteration number threshold (must be greater than
          start_iteration).
        training_steps: int, the number of training steps to perform.
        evaluation_steps: int, the number of evaluation steps to perform.
        max_steps_per_episode: int, maximum number of steps after which an episode
          terminates.
        clip_rewards: bool, whether to clip rewards in [-1, 1].
        use_legacy_logger: bool, whether to use the legacy Logger. This will be
          deprecated soon, replaced with the new CollectorDispatcher setup.
  
      This constructor will take the following actions:
      - Initialize an environment.
      - Initialize a logger.
      - Initialize an agent.
      - Reload from the latest checkpoint, if available, and initialize the
        Checkpointer object.
      """
      assert base_dir is not None
      self._legacy_logger_enabled = use_legacy_logger
      self._logging_file_prefix = logging_file_prefix
      self._log_every_n = log_every_n
      self._num_iterations = num_iterations
      self._training_steps = training_steps
      self._evaluation_steps = evaluation_steps
      self._max_steps_per_episode = max_steps_per_episode
      self._base_dir = base_dir
      self._clip_rewards = clip_rewards
      self._create_directories()
      self._summary_writer = tensorboard.SummaryWriter(base_dir)
      self._environment = create_environment_fn()
      self._agent = create_agent_fn(
          self._environment, summary_writer=self._summary_writer
      )
      self._initialize_checkpointer_and_maybe_resume(
          checkpoint_file_prefix
      )
  
      # Create a collector dispatcher for metrics reporting.
      self._collector_dispatcher = (
          collector_dispatcher.CollectorDispatcher(self._base_dir)
      )
      set_collector_dispatcher_fn = getattr(
          self._agent, "set_collector_dispatcher", None
      )
      if callable(set_collector_dispatcher_fn):
          set_collector_dispatcher_fn(self._collector_dispatcher)
  
imports: from typing import Optional
  from absl import logging
  from dopamine.discrete_domains import gym_lib
  from dopamine.discrete_domains import iteration_statistics
  from dopamine.discrete_domains import run_experiment
  from dopamine.jax.agents.dqn import dqn_agent
  from dopamine.jax.agents.sac import sac_agent
  from dopamine.labs.sac_from_pixels import deepmind_control_lib
  from dopamine.metrics import collector_dispatcher
  from dopamine.metrics import statistics_instance
  from flax.metrics import tensorboard
  import gin
  from gym import spaces
label_desc: Use image node_id 1 to create a new ContinuousRunner object from inherited base classes: base_run_experiment with example: obj = ContinuousRunner(base_dir, create_agent_fn, create_environment_fn, checkpoint_file_prefix, logging_file_prefix, log_every_n, num_iterations, training_steps, evaluation_steps, max_steps_per_episode, clip_rewards, use_legacy_logger)