docstr: Calculate advantages and value targets.
docstr_tok: ["Calculate","advantages","and","value","targets","."]
code: def postprocess_episodes(
      self, episodes: List[SingleAgentEpisode]
  ) -> List[SingleAgentEpisode]:
      """Calculate advantages and value targets."""
      from ray.rllib.evaluation.postprocessing_v2 import (
          compute_gae_for_episode,
      )
  
      # Bootstrap values.
      postprocessed_episodes = []
      # TODO (simon): Remove somehow the double list.
      # episodes = [episode for episode_list in episodes for episode in episode_list]
      for episode in episodes:
          # TODO (sven): Calling 'module' on the 'EnvRunner' only works
          #  for the 'SingleAgentEnvRunner' not for 'MultiAgentEnvRunner'.
          postprocessed_episodes.append(
              compute_gae_for_episode(
                  episode,
                  self.config,
                  self.workers.local_worker().module,
              )
          )
  
      return postprocessed_episodes
  
imports: import logging
  from typing import List, Optional, Type, Union, TYPE_CHECKING
  import numpy
  import tree
  from ray.rllib.algorithms.algorithm import Algorithm
  from ray.rllib.algorithms.algorithm_config import AlgorithmConfig, NotProvided
  from ray.rllib.core.rl_module.rl_module import SingleAgentRLModuleSpec
  from ray.rllib.evaluation.postprocessing_v2 import postprocess_episodes_to_sample_batch
  from ray.rllib.evaluation.rollout_worker import RolloutWorker
  from ray.rllib.execution.rollout_ops import standardize_fields, synchronous_parallel_sample
  from ray.rllib.execution.train_ops import train_one_step, multi_gpu_train_one_step
  from ray.rllib.policy.policy import Policy
  from ray.rllib.utils.annotations import override
  from ray.rllib.utils.deprecation import DEPRECATED_VALUE
  from ray.rllib.utils.metrics.learner_info import LEARNER_STATS_KEY
  from ray.rllib.utils.metrics import NUM_AGENT_STEPS_SAMPLED, NUM_ENV_STEPS_SAMPLED, SYNCH_WORKER_WEIGHTS_TIMER, SAMPLE_TIMER, ALL_MODULES
  from ray.rllib.env.single_agent_episode import SingleAgentEpisode
  from ray.rllib.policy.sample_batch import SampleBatch
  from ray.rllib.utils.schedules.scheduler import Scheduler
  from ray.rllib.utils.typing import ResultDict
  from ray.util.debug import log_once
label_desc: Use image node_id 4 for calling the PPO obj's underlying member method code with example usage: obj.postprocess_episodes(episodes) and returns: postprocessed_episodes