class_docstr: Tensorforce runner utility.
  
  Args:
      agent (specification | Agent object | Agent.load kwargs): Agent specification or object
          (<b>note</b>: if passed as object, `agent.close()` is not (!) automatically triggered
          as part of `runner.close()`), or keyword arguments to `Agent.load()` in particular
          containing `directory`, in all cases argument `environment` is implicitly specified
          as the following argument, and argument `parallel_interactions` is either implicitly
          specified as `num_parallel` or expected to be at least `num_parallel`
          (<span style="color:#C00000"><b>required</b></span>).
      environment (specification | Environment object): Environment specification or object
          (<b>note</b>: if passed as object, `environment.close()` is not (!) automatically
          triggered as part of `runner.close()`), where argument `max_episode_timesteps` is
          implicitly specified as the following argument
          (<span style="color:#C00000"><b>required</b></span>, or alternatively `environments`,
          invalid for "socket-client" remote mode).
      max_episode_timesteps (int > 0): Maximum number of timesteps per episode, overwrites the
          environment default if defined
          (<span style="color:#00C000"><b>default</b></span>: environment default, invalid for
          "socket-client" remote mode).
      num_parallel (int >= 2): Number of environment instances to execute in parallel, usually
          requires argument `remote` to be specified for proper parallel execution unless
          vectorizable environment
          (<span style="color:#00C000"><b>default</b></span>: no parallel execution, implicitly
          specified by `environments`).
      environments (list[specification | Environment object]): Environment specifications or
          objects to execute in parallel, the latter are not closed automatically as part of
          `runner.close()`
          (<span style="color:#00C000"><b>default</b></span>: no parallel execution,
          alternatively specified via `environment` and `num_parallel`, invalid for
          "socket-client" remote mode).
      evaluation (bool): Whether to run the last of multiple parallel environments in evaluation
          mode, only valid with `num_parallel` or `environments`
          (<span style="color:#00C000"><b>default</b></span>: no evaluation).
      remote ("multiprocessing" | "socket-client"): Communication mode for remote environment
          execution of parallelized environment execution, not compatible with environment(s)
          given as Environment objects, "socket-client" mode requires a corresponding
          "socket-server" running
          (<span style="color:#00C000"><b>default</b></span>: local execution).
      blocking (bool): Whether remote environment calls should be blocking, only valid if remote
          mode given
          (<span style="color:#00C000"><b>default</b></span>: not blocking, invalid unless
          "multiprocessing" or "socket-client" remote mode).
      host (str, iter[str]): Socket server hostname(s) or IP address(es)
          (<span style="color:#C00000"><b>required</b></span> only for "socket-client" remote
          mode).
      port (int, iter[int]): Socket server port(s), increasing sequence if single host and port
          given
          (<span style="color:#C00000"><b>required</b></span> only for "socket-client" remote
          mode).
class_docstr_tok: ["Tensorforce","runner","utility",".","Args",":","agent","(","specification","|","Agent","object","|","Agent.load","kwargs",")",":","Agent","specification","or","object","(","<","b",">","note","<","\/b",">",":","if","passed","as","object",",","`","agent.close","(",")","`","is","not","(","!",")","automatically","triggered","as","part","of","`","runner.close","(",")","`",")",",","or","keyword","arguments","to","`","Agent.load","(",")","`","in","particular","containing","`","directory","`",",","in","all","cases","argument","`","environment","`","is","implicitly","specified","as","the","following","argument",",","and","argument","`","parallel_interactions","`","is","either","implicitly","specified","as","`","num_parallel","`","or","expected","to","be","at","least","`","num_parallel","`","(","<","span","style=","''","color",":","#","C00000","''",">","<","b",">","required","<","\/b",">","<","\/span",">",")",".","environment","(","specification","|","Environment","object",")",":","Environment","specification","or","object","(","<","b",">","note","<","\/b",">",":","if","passed","as","object",",","`","environment.close","(",")","`","is","not","(","!",")","automatically","triggered","as","part","of","`","runner.close","(",")","`",")",",","where","argument","`","max_episode_timesteps","`","is","implicitly","specified","as","the","following","argument","(","<","span","style=","''","color",":","#","C00000","''",">","<","b",">","required","<","\/b",">","<","\/span",">",",","or","alternatively","`","environments","`",",","invalid","for","``","socket-client","''","remote","mode",")",".","max_episode_timesteps","(","int",">","0",")",":","Maximum","number","of","timesteps","per","episode",",","overwrites","the","environment","default","if","defined","(","<","span","style=","''","color",":","#","00C000","''",">","<","b",">","default","<","\/b",">","<","\/span",">",":","environment","default",",","invalid","for","``","socket-client","''","remote","mode",")",".","num_parallel","(","int",">","=","2",")",":","Number","of","environment","instances","to","execute","in","parallel",",","usually","requires","argument","`","remote","`","to","be","specified","for","proper","parallel","execution","unless","vectorizable","environment","(","<","span","style=","''","color",":","#","00C000","''",">","<","b",">","default","<","\/b",">","<","\/span",">",":","no","parallel","execution",",","implicitly","specified","by","`","environments","`",")",".","environments","(","list","[","specification","|","Environment","object","]",")",":","Environment","specifications","or","objects","to","execute","in","parallel",",","the","latter","are","not","closed","automatically","as","part","of","`","runner.close","(",")","`","(","<","span","style=","''","color",":","#","00C000","''",">","<","b",">","default","<","\/b",">","<","\/span",">",":","no","parallel","execution",",","alternatively","specified","via","`","environment","`","and","`","num_parallel","`",",","invalid","for","``","socket-client","''","remote","mode",")",".","evaluation","(","bool",")",":","Whether","to","run","the","last","of","multiple","parallel","environments","in","evaluation","mode",",","only","valid","with","`","num_parallel","`","or","`","environments","`","(","<","span","style=","''","color",":","#","00C000","''",">","<","b",">","default","<","\/b",">","<","\/span",">",":","no","evaluation",")",".","remote","(","``","multiprocessing","''","|","``","socket-client","''",")",":","Communication","mode","for","remote","environment","execution","of","parallelized","environment","execution",",","not","compatible","with","environment","(","s",")","given","as","Environment","objects",",","``","socket-client","''","mode","requires","a","corresponding","``","socket-server","''","running","(","<","span","style=","''","color",":","#","00C000","''",">","<","b",">","default","<","\/b",">","<","\/span",">",":","local","execution",")",".","blocking","(","bool",")",":","Whether","remote","environment","calls","should","be","blocking",",","only","valid","if","remote","mode","given","(","<","span","style=","''","color",":","#","00C000","''",">","<","b",">","default","<","\/b",">","<","\/span",">",":","not","blocking",",","invalid","unless","``","multiprocessing","''","or","``","socket-client","''","remote","mode",")",".","host","(","str",",","iter","[","str","]",")",":","Socket","server","hostname","(","s",")","or","IP","address","(","es",")","(","<","span","style=","''","color",":","#","C00000","''",">","<","b",">","required","<","\/b",">","<","\/span",">","only","for","``","socket-client","''","remote","mode",")",".","port","(","int",",","iter","[","int","]",")",":","Socket","server","port","(","s",")",",","increasing","sequence","if","single","host","and","port","given","(","<","span","style=","''","color",":","#","C00000","''",">","<","b",">","required","<","\/b",">","<","\/span",">","only","for","``","socket-client","''","remote","mode",")","."]
code: def handle_terminal(self, parallel):
      # Update experiment statistics
      if self.num_vectorized is None:
          actual_episode_return = self.environments[
              parallel
          ].episode_return()
      else:
          actual_episode_return = self.environments[0].episode_return(
              parallel=parallel
          )
      if actual_episode_return is None:
          self.episode_returns.append(self.episode_return[parallel])
      else:
          self.episode_returns.append(actual_episode_return)
      self.episode_timesteps.append(self.episode_timestep[parallel])
      self.episode_seconds.append(
          time.time() - self.episode_start[parallel]
      )
      self.episode_agent_seconds.append(
          self.episode_agent_second[parallel]
      )
      if self.is_environment_remote:
          self.episode_env_seconds.append(
              self.environments[parallel]._episode_seconds
          )
  
      # Maximum number of episodes or episode callback (after counter increment!)
      self.episodes += 1
      if self.terminate == 0 and (
          (
              self.episodes % self.callback_episode_frequency == 0
              and not self.callback(self, parallel)
          )
          or self.episodes >= self.num_episodes
      ):
          self.terminate = 1
  
      # Reset episode statistics
      self.episode_return[parallel] = 0.0
      self.episode_timestep[parallel] = 0
      self.episode_agent_second[parallel] = 0.0
      self.episode_start[parallel] = time.time()
  
      # Reset environment
      if self.terminate == 0 and not self.sync_episodes:
          self.terminals[parallel] = -1
          self.environments[parallel].start_reset()
  
file_path: tensorforce/tensorforce/execution/runner.py
imports: import time
  import numpy
  from tqdm.auto import tqdm
  from tensorforce import Agent, Environment, TensorforceError, util
  from tensorforce.environments import RemoteEnvironment
label_desc: Use image node_id 10 for calling the Runner obj's underlying member method code with example usage: obj.handle_terminal(parallel) without return types