class_docstr: The A2C (Advantage Actor Critic) model class, https://arxiv.org/abs/1602.01783
  
  :param policy: (ActorCriticPolicy or str) The policy model to use (MlpPolicy, CnnPolicy, CnnLstmPolicy, ...)
  :param env: (Gym environment or str) The environment to learn from (if registered in Gym, can be str)
  :param gamma: (float) Discount factor
  :param n_steps: (int) The number of steps to run for each environment per update
      (i.e. batch size is n_steps * n_env where n_env is number of environment copies running in parallel)
  :param vf_coef: (float) Value function coefficient for the loss calculation
  :param ent_coef: (float) Entropy coefficient for the loss calculation
  :param max_grad_norm: (float) The maximum value for the gradient clipping
  :param learning_rate: (float) The learning rate
  :param alpha: (float)  RMSProp decay parameter (default: 0.99)
  :param momentum: (float) RMSProp momentum parameter (default: 0.0)
  :param epsilon: (float) RMSProp epsilon (stabilizes square root computation in denominator of RMSProp update)
      (default: 1e-5)
  :param lr_schedule: (str) The type of scheduler for the learning rate update ('linear', 'constant',
                            'double_linear_con', 'middle_drop' or 'double_middle_drop')
  :param verbose: (int) the verbosity level: 0 none, 1 training information, 2 tensorflow debug
  :param tensorboard_log: (str) the log location for tensorboard (if None, no logging)
  :param _init_setup_model: (bool) Whether or not to build the network at the creation of the instance
                            (used only for loading)
  :param policy_kwargs: (dict) additional arguments to be passed to the policy on creation
  :param full_tensorboard_log: (bool) enable additional logging when using tensorboard
      WARNING: this logging can take a lot of space quickly
  :param seed: (int) Seed for the pseudo-random generators (python, numpy, tensorflow).
      If None (default), use random seed. Note that if you want completely deterministic
      results, you must set `n_cpu_tf_sess` to 1.
  :param n_cpu_tf_sess: (int) The number of threads for TensorFlow operations
      If None, the number of cpu of the current machine will be used.
class_docstr_tok: ["The","A2C","(","Advantage","Actor","Critic",")","model","class",",","https",":","\/\/arxiv.org\/abs\/1602.01783",":","param","policy",":","(","ActorCriticPolicy","or","str",")","The","policy","model","to","use","(","MlpPolicy",",","CnnPolicy",",","CnnLstmPolicy",",","...",")",":","param","env",":","(","Gym","environment","or","str",")","The","environment","to","learn","from","(","if","registered","in","Gym",",","can","be","str",")",":","param","gamma",":","(","float",")","Discount","factor",":","param","n_steps",":","(","int",")","The","number","of","steps","to","run","for","each","environment","per","update","(","i.e",".","batch","size","is","n_steps","*","n_env","where","n_env","is","number","of","environment","copies","running","in","parallel",")",":","param","vf_coef",":","(","float",")","Value","function","coefficient","for","the","loss","calculation",":","param","ent_coef",":","(","float",")","Entropy","coefficient","for","the","loss","calculation",":","param","max_grad_norm",":","(","float",")","The","maximum","value","for","the","gradient","clipping",":","param","learning_rate",":","(","float",")","The","learning","rate",":","param","alpha",":","(","float",")","RMSProp","decay","parameter","(","default",":","0.99",")",":","param","momentum",":","(","float",")","RMSProp","momentum","parameter","(","default",":","0.0",")",":","param","epsilon",":","(","float",")","RMSProp","epsilon","(","stabilizes","square","root","computation","in","denominator","of","RMSProp","update",")","(","default",":","1e-5",")",":","param","lr_schedule",":","(","str",")","The","type","of","scheduler","for","the","learning","rate","update","(","'linear","'",",","'constant","'",",","'double_linear_con","'",",","'middle_drop","'","or","'double_middle_drop","'",")",":","param","verbose",":","(","int",")","the","verbosity","level",":","0","none",",","1","training","information",",","2","tensorflow","debug",":","param","tensorboard_log",":","(","str",")","the","log","location","for","tensorboard","(","if","None",",","no","logging",")",":","param","_init_setup_model",":","(","bool",")","Whether","or","not","to","build","the","network","at","the","creation","of","the","instance","(","used","only","for","loading",")",":","param","policy_kwargs",":","(","dict",")","additional","arguments","to","be","passed","to","the","policy","on","creation",":","param","full_tensorboard_log",":","(","bool",")","enable","additional","logging","when","using","tensorboard","WARNING",":","this","logging","can","take","a","lot","of","space","quickly",":","param","seed",":","(","int",")","Seed","for","the","pseudo-random","generators","(","python",",","numpy",",","tensorflow",")",".","If","None","(","default",")",",","use","random","seed",".","Note","that","if","you","want","completely","deterministic","results",",","you","must","set","`","n_cpu_tf_sess","`","to","1.",":","param","n_cpu_tf_sess",":","(","int",")","The","number","of","threads","for","TensorFlow","operations","If","None",",","the","number","of","cpu","of","the","current","machine","will","be","used","."]
docstr: applies a training step to the model
  
  :param obs: ([float]) The input observations
  :param states: ([float]) The states (used for recurrent policies)
  :param rewards: ([float]) The rewards from the environment
  :param masks: ([bool]) Whether or not the episode is over (used for recurrent policies)
  :param actions: ([float]) The actions taken
  :param values: ([float]) The logits values
  :param update: (int) the current step iteration
  :param writer: (TensorFlow Summary.writer) the writer for tensorboard
  :return: (float, float, float) policy loss, value loss, policy entropy
docstr_tok: ["applies","a","training","step","to","the","model",":","param","obs",":","(","[","float","]",")","The","input","observations",":","param","states",":","(","[","float","]",")","The","states","(","used","for","recurrent","policies",")",":","param","rewards",":","(","[","float","]",")","The","rewards","from","the","environment",":","param","masks",":","(","[","bool","]",")","Whether","or","not","the","episode","is","over","(","used","for","recurrent","policies",")",":","param","actions",":","(","[","float","]",")","The","actions","taken",":","param","values",":","(","[","float","]",")","The","logits","values",":","param","update",":","(","int",")","the","current","step","iteration",":","param","writer",":","(","TensorFlow","Summary.writer",")","the","writer","for","tensorboard",":","return",":","(","float",",","float",",","float",")","policy","loss",",","value","loss",",","policy","entropy"]
code: def _train_step(
      self,
      obs,
      states,
      rewards,
      masks,
      actions,
      values,
      update,
      writer=None,
  ):
      """
      applies a training step to the model
  
      :param obs: ([float]) The input observations
      :param states: ([float]) The states (used for recurrent policies)
      :param rewards: ([float]) The rewards from the environment
      :param masks: ([bool]) Whether or not the episode is over (used for recurrent policies)
      :param actions: ([float]) The actions taken
      :param values: ([float]) The logits values
      :param update: (int) the current step iteration
      :param writer: (TensorFlow Summary.writer) the writer for tensorboard
      :return: (float, float, float) policy loss, value loss, policy entropy
      """
      advs = rewards - values
      cur_lr = None
      for _ in range(len(obs)):
          cur_lr = self.learning_rate_schedule.value()
      assert (
          cur_lr is not None
      ), "Error: the observation input array cannon be empty"
  
      td_map = {
          self.train_model.obs_ph: obs,
          self.actions_ph: actions,
          self.advs_ph: advs,
          self.rewards_ph: rewards,
          self.learning_rate_ph: cur_lr,
      }
      if states is not None:
          td_map[self.train_model.states_ph] = states
          td_map[self.train_model.dones_ph] = masks
  
      if writer is not None:
          # run loss backprop with summary, but once every 10 runs save the metadata (memory, compute time, ...)
          if self.full_tensorboard_log and (1 + update) % 10 == 0:
              run_options = tf.RunOptions(
                  trace_level=tf.RunOptions.FULL_TRACE
              )
              run_metadata = tf.RunMetadata()
              (
                  summary,
                  policy_loss,
                  value_loss,
                  policy_entropy,
                  _,
              ) = self.sess.run(
                  [
                      self.summary,
                      self.pg_loss,
                      self.vf_loss,
                      self.entropy,
                      self.apply_backprop,
                  ],
                  td_map,
                  options=run_options,
                  run_metadata=run_metadata,
              )
              writer.add_run_metadata(
                  run_metadata, "step%d" % (update * self.n_batch)
              )
          else:
              (
                  summary,
                  policy_loss,
                  value_loss,
                  policy_entropy,
                  _,
              ) = self.sess.run(
                  [
                      self.summary,
                      self.pg_loss,
                      self.vf_loss,
                      self.entropy,
                      self.apply_backprop,
                  ],
                  td_map,
              )
          writer.add_summary(summary, update * self.n_batch)
  
      else:
          policy_loss, value_loss, policy_entropy, _ = self.sess.run(
              [
                  self.pg_loss,
                  self.vf_loss,
                  self.entropy,
                  self.apply_backprop,
              ],
              td_map,
          )
  
      return policy_loss, value_loss, policy_entropy
  
imports: import time
  import gym
  import numpy
  import tensorflow
  from stable_baselines import logger
  from stable_baselines.common import explained_variance, tf_util, ActorCriticRLModel, SetVerbosity, TensorboardWriter
  from stable_baselines.common.policies import ActorCriticPolicy, RecurrentActorCriticPolicy
  from stable_baselines.common.runners import AbstractEnvRunner
  from stable_baselines.common.schedules import Scheduler
  from stable_baselines.common.tf_util import mse, total_episode_reward_logger
  from stable_baselines.common.math_util import safe_mean
label_desc: Use image node_id 5 for calling the A2C obj's underlying member method code with example usage: obj._train_step(obs, states, rewards, masks, actions, values, update, writer) and returns: policy_loss,  value_loss,  policy_entropy