code: def main():
      parser = argparse.ArgumentParser()
      parser.add_argument(
          "--outdir",
          type=str,
          default="results",
          help="Directory path to save output files."
          " If it does not exist, it will be created.",
      )
      parser.add_argument(
          "--env",
          type=str,
          default="Hopper-v2",
          help="OpenAI Gym MuJoCo env to perform algorithm on.",
      )
      parser.add_argument(
          "--seed", type=int, default=0, help="Random seed [0, 2 ** 32)"
      )
      parser.add_argument(
          "--gpu",
          type=int,
          default=0,
          help="GPU to use, set to -1 if no GPU.",
      )
      parser.add_argument(
          "--load",
          type=str,
          default="",
          help="Directory to load agent from.",
      )
      parser.add_argument(
          "--steps",
          type=int,
          default=10**6,
          help="Total number of timesteps to train the agent.",
      )
      parser.add_argument(
          "--eval-n-runs",
          type=int,
          default=10,
          help="Number of episodes run for each evaluation.",
      )
      parser.add_argument(
          "--eval-interval",
          type=int,
          default=5000,
          help="Interval in timesteps between evaluations.",
      )
      parser.add_argument(
          "--replay-start-size",
          type=int,
          default=10000,
          help="Minimum replay buffer size before "
          + "performing gradient updates.",
      )
      parser.add_argument(
          "--batch-size", type=int, default=100, help="Minibatch size"
      )
      parser.add_argument(
          "--render",
          action="store_true",
          help="Render env states in a GUI window.",
      )
      parser.add_argument(
          "--demo",
          action="store_true",
          help="Just run evaluation, not training.",
      )
      parser.add_argument(
          "--load-pretrained", action="store_true", default=False
      )
      parser.add_argument(
          "--pretrained-type",
          type=str,
          default="best",
          choices=["best", "final"],
      )
      parser.add_argument(
          "--monitor",
          action="store_true",
          help="Wrap env with gym.wrappers.Monitor.",
      )
      parser.add_argument(
          "--logger-level",
          type=int,
          default=logging.INFO,
          help="Level of the root logger.",
      )
      args = parser.parse_args()
  
      logging.basicConfig(level=args.logger_level)
  
      args.outdir = experiments.prepare_output_dir(
          args, args.outdir, argv=sys.argv
      )
      print("Output files are saved in {}".format(args.outdir))
  
      # Set a random seed used in ChainerRL
      misc.set_random_seed(args.seed, gpus=(args.gpu,))
  
      def make_env(test):
          env = gym.make(args.env)
          # Unwrap TimeLimit wrapper
          assert isinstance(env, gym.wrappers.TimeLimit)
          env = env.env
          # Use different random seeds for train and test envs
          env_seed = 2**32 - 1 - args.seed if test else args.seed
          env.seed(env_seed)
          # Cast observations to float32 because our model uses float32
          env = chainerrl.wrappers.CastObservationToFloat32(env)
          if args.monitor:
              env = chainerrl.wrappers.Monitor(env, args.outdir)
          if args.render and not test:
              env = chainerrl.wrappers.Render(env)
          return env
  
      env = make_env(test=False)
      timestep_limit = env.spec.max_episode_steps
      obs_space = env.observation_space
      action_space = env.action_space
      print("Observation space:", obs_space)
      print("Action space:", action_space)
  
      action_size = action_space.low.size
  
      winit = chainer.initializers.LeCunUniform(3**-0.5)
  
      policy = chainer.Sequential(
          L.Linear(None, 400, initialW=winit),
          F.relu,
          L.Linear(None, 300, initialW=winit),
          F.relu,
          L.Linear(None, action_size, initialW=winit),
          F.tanh,
          chainerrl.distribution.ContinuousDeterministicDistribution,
      )
      policy_optimizer = optimizers.Adam().setup(policy)
  
      def make_q_func_with_optimizer():
          q_func = chainer.Sequential(
              concat_obs_and_action,
              L.Linear(None, 400, initialW=winit),
              F.relu,
              L.Linear(None, 300, initialW=winit),
              F.relu,
              L.Linear(None, 1, initialW=winit),
          )
          q_func_optimizer = optimizers.Adam().setup(q_func)
          return q_func, q_func_optimizer
  
      q_func1, q_func1_optimizer = make_q_func_with_optimizer()
      q_func2, q_func2_optimizer = make_q_func_with_optimizer()
  
      # Draw the computational graph and save it in the output directory.
      fake_obs = chainer.Variable(
          policy.xp.zeros_like(obs_space.low, dtype=np.float32)[None],
          name="observation",
      )
      fake_action = chainer.Variable(
          policy.xp.zeros_like(action_space.low, dtype=np.float32)[
              None
          ],
          name="action",
      )
      chainerrl.misc.draw_computational_graph(
          [policy(fake_obs)], os.path.join(args.outdir, "policy")
      )
      chainerrl.misc.draw_computational_graph(
          [q_func1(fake_obs, fake_action)],
          os.path.join(args.outdir, "q_func1"),
      )
      chainerrl.misc.draw_computational_graph(
          [q_func2(fake_obs, fake_action)],
          os.path.join(args.outdir, "q_func2"),
      )
  
      rbuf = replay_buffer.ReplayBuffer(10**6)
  
      explorer = explorers.AdditiveGaussian(
          scale=0.1, low=action_space.low, high=action_space.high
      )
  
      def burnin_action_func():
          """Select random actions until model is updated one or more times."""
          return np.random.uniform(
              action_space.low, action_space.high
          ).astype(np.float32)
  
      # Hyperparameters in http://arxiv.org/abs/1802.09477
      agent = chainerrl.agents.TD3(
          policy,
          q_func1,
          q_func2,
          policy_optimizer,
          q_func1_optimizer,
          q_func2_optimizer,
          rbuf,
          gamma=0.99,
          soft_update_tau=5e-3,
          explorer=explorer,
          replay_start_size=args.replay_start_size,
          gpu=args.gpu,
          minibatch_size=args.batch_size,
          burnin_action_func=burnin_action_func,
      )
  
      if len(args.load) > 0 or args.load_pretrained:
          # either load or load_pretrained must be false
          assert not len(args.load) > 0 or not args.load_pretrained
          if len(args.load) > 0:
              agent.load(args.load)
          else:
              agent.load(
                  misc.download_model(
                      "TD3", args.env, model_type=args.pretrained_type
                  )[0]
              )
  
      eval_env = make_env(test=True)
      if args.demo:
          eval_stats = experiments.eval_performance(
              env=eval_env,
              agent=agent,
              n_steps=None,
              n_episodes=args.eval_n_runs,
              max_episode_len=timestep_limit,
          )
          print(
              "n_runs: {} mean: {} median: {} stdev {}".format(
                  args.eval_n_runs,
                  eval_stats["mean"],
                  eval_stats["median"],
                  eval_stats["stdev"],
              )
          )
      else:
          experiments.train_agent_with_evaluation(
              agent=agent,
              env=env,
              steps=args.steps,
              eval_env=eval_env,
              eval_n_steps=None,
              eval_n_episodes=args.eval_n_runs,
              eval_interval=args.eval_interval,
              outdir=args.outdir,
              train_max_episode_len=timestep_limit,
          )
  
file_path: chainerrl/examples/mujoco/reproduction/td3/train_td3.py
imports: import argparse
  import logging
  import os
  import sys
  import chainer
  from chainer import functions
  from chainer import links
  from chainer import optimizers
  import gym
  import gym.wrappers
  import numpy
  import chainerrl
  from chainerrl import experiments
  from chainerrl import explorers
  from chainerrl import misc
  from chainerrl import replay_buffer
label_desc: Use image node_id 2 for calling a global function with example usage: main() and returns: env, q_func,  q_func_optimizer, np