class_docstr: PPO for policy learning.
code: def train(
      self,
      env_fn,
      hparams,
      simulated,
      save_continuously,
      epoch,
      sampling_temp=1.0,
      num_env_steps=None,
      env_step_multiplier=1,
      eval_env_fn=None,
      report_fn=None,
      model_save_fn=None,
  ):
      assert (
          sampling_temp == 1.0 or hparams.learning_rate == 0.0
      ), "Sampling with non-1 temperature does not make sense during training."
  
      if not save_continuously:
          # We do not save model, as that resets frames that we need at restarts.
          # But we need to save at the last step, so we set it very high.
          hparams.save_models_every_epochs = 1000000
  
      if simulated:
          simulated_str = "sim"
      else:
          simulated_str = "real"
      name_scope = "ppo_{}{}".format(simulated_str, epoch + 1)
      event_dir = os.path.join(
          self.base_event_dir,
          "ppo_summaries",
          str(epoch) + simulated_str,
      )
  
      with tf.Graph().as_default():
          with tf.name_scope(name_scope):
              with tf.variable_scope(
                  tf.get_variable_scope(), reuse=tf.AUTO_REUSE
              ):
                  env = env_fn(in_graph=True)
                  (
                      train_summary_op,
                      eval_summary_op,
                      initializers,
                  ) = _define_train(
                      env,
                      hparams,
                      eval_env_fn,
                      sampling_temp,
                      distributional_size=self._distributional_size,
                      distributional_subscale=self._distributional_subscale,
                      distributional_threshold=self._distributional_threshold,
                      epoch=epoch if simulated else -1,
                      frame_stack_size=self.frame_stack_size,
                      force_beginning_resets=simulated,
                  )
  
              if num_env_steps is None:
                  iteration_increment = hparams.epochs_num
              else:
                  iteration_increment = int(
                      math.ceil(
                          num_env_steps
                          / (env.batch_size * hparams.epoch_length)
                      )
                  )
              iteration_increment *= env_step_multiplier
  
              self._num_completed_iterations += iteration_increment
  
              restarter = Restarter(
                  "policy",
                  self.agent_model_dir,
                  self._num_completed_iterations,
              )
              if restarter.should_skip:
                  return
  
              if hparams.lr_decay_in_final_epoch:
                  if epoch != self.total_num_epochs - 1:
                      # Extend the warmup period to the end of this epoch.
                      hparams.learning_rate_warmup_steps = (
                          restarter.target_global_step
                      )
                  else:
                      if self._lr_decay_start is None:
                          # Stop the warmup at the beginning of this epoch.
                          self._lr_decay_start = (
                              restarter.target_global_step
                              - iteration_increment
                          )
                      hparams.learning_rate_warmup_steps = (
                          self._lr_decay_start
                      )
  
              _run_train(
                  hparams,
                  event_dir,
                  self.agent_model_dir,
                  restarter,
                  train_summary_op,
                  eval_summary_op,
                  initializers,
                  epoch,
                  report_fn=report_fn,
                  model_save_fn=model_save_fn,
              )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import math
  import os
  from tensor2tensor.layers import common_layers
  from tensor2tensor.models.research.rl import get_policy
  from tensor2tensor.rl import ppo
  from tensor2tensor.rl.envs.tf_atari_wrappers import StackWrapper
  from tensor2tensor.rl.envs.tf_atari_wrappers import WrapperBase
  from tensor2tensor.rl.policy_learner import PolicyLearner
  from tensor2tensor.rl.restarter import Restarter
  from tensor2tensor.utils import trainer_lib
  import tensorflow.compat.v1
  import tensorflow_probability
label_desc: Use image node_id 2 for calling the PPOLearner obj's underlying member method code with example usage: obj.train(env_fn, hparams, simulated, save_continuously, epoch, sampling_temp, num_env_steps, env_step_multiplier, eval_env_fn, report_fn, model_save_fn) without return types