code: def learn(
      *,
      network,
      env,
      total_timesteps,
      seed=None,
      eval_env=None,
      replay_strategy="future",
      policy_save_interval=5,
      clip_return=True,
      demo_file=None,
      override_params=None,
      load_path=None,
      save_path=None,
      **kwargs,
  ):
      override_params = override_params or {}
      if MPI is not None:
          rank = MPI.COMM_WORLD.Get_rank()
          num_cpu = MPI.COMM_WORLD.Get_size()
  
      # Seed everything.
      rank_seed = seed + 1000000 * rank if seed is not None else None
      set_global_seeds(rank_seed)
  
      # Prepare params.
      params = config.DEFAULT_PARAMS
      env_name = env.spec.id
      params["env_name"] = env_name
      params["replay_strategy"] = replay_strategy
      if env_name in config.DEFAULT_ENV_PARAMS:
          params.update(
              config.DEFAULT_ENV_PARAMS[env_name]
          )  # merge env-specific parameters in
      params.update(
          **override_params
      )  # makes it possible to override any parameter
      with open(
          os.path.join(logger.get_dir(), "params.json"), "w"
      ) as f:
          json.dump(params, f)
      params = config.prepare_params(params)
      params["rollout_batch_size"] = env.num_envs
  
      if demo_file is not None:
          params["bc_loss"] = 1
      params.update(kwargs)
  
      config.log_params(params, logger=logger)
  
      if num_cpu == 1:
          logger.warn()
          logger.warn("*** Warning ***")
          logger.warn(
              "You are running HER with just a single MPI worker. This will work, but the "
              + "experiments that we report in Plappert et al. (2018, https://arxiv.org/abs/1802.09464) "
              + "were obtained with --num_cpu 19. This makes a significant difference and if you "
              + "are looking to reproduce those results, be aware of this. Please also refer to "
              + "https://github.com/openai/baselines/issues/314 for further details."
          )
          logger.warn("****************")
          logger.warn()
  
      dims = config.configure_dims(params)
      policy = config.configure_ddpg(
          dims=dims, params=params, clip_return=clip_return
      )
      if load_path is not None:
          tf_util.load_variables(load_path)
  
      rollout_params = {
          "exploit": False,
          "use_target_net": False,
          "use_demo_states": True,
          "compute_Q": False,
          "T": params["T"],
      }
  
      eval_params = {
          "exploit": True,
          "use_target_net": params["test_with_polyak"],
          "use_demo_states": False,
          "compute_Q": True,
          "T": params["T"],
      }
  
      for name in [
          "T",
          "rollout_batch_size",
          "gamma",
          "noise_eps",
          "random_eps",
      ]:
          rollout_params[name] = params[name]
          eval_params[name] = params[name]
  
      eval_env = eval_env or env
  
      rollout_worker = RolloutWorker(
          env, policy, dims, logger, monitor=True, **rollout_params
      )
      evaluator = RolloutWorker(
          eval_env, policy, dims, logger, **eval_params
      )
  
      n_cycles = params["n_cycles"]
      n_epochs = (
          total_timesteps
          // n_cycles
          // rollout_worker.T
          // rollout_worker.rollout_batch_size
      )
  
      return train(
          save_path=save_path,
          policy=policy,
          rollout_worker=rollout_worker,
          evaluator=evaluator,
          n_epochs=n_epochs,
          n_test_rollouts=params["n_test_rollouts"],
          n_cycles=params["n_cycles"],
          n_batches=params["n_batches"],
          policy_save_interval=policy_save_interval,
          demo_file=demo_file,
      )
  
file_path: baselines/baselines/her/her.py
imports: import os
  import click
  import numpy
  import json
  from mpi4py import MPI
  from baselines import logger
  from baselines.common import set_global_seeds, tf_util
  from baselines.common.mpi_moments import mpi_moments
  import baselines.her.experiment.config
  from baselines.her.rollout import RolloutWorker
label_desc: Use image node_id 3 for calling a global function with example usage: learn() and returns: train