class_docstr: Mixin class calculating TD-error (part of critic loss) per batch item.
  
  - Adds `policy.compute_td_error()` method for TD-error calculation from a
    batch of observations/actions/rewards/etc..
class_docstr_tok: ["Mixin","class","calculating","TD-error","(","part","of","critic","loss",")","per","batch","item",".","-","Adds","`","policy.compute_td_error","(",")","`","method","for","TD-error","calculation","from","a","batch","of","observations\/actions\/rewards\/etc",".."]
code: def __init__(self):
      def compute_td_error(
          obs_t,
          act_t,
          rew_t,
          obs_tp1,
          terminateds_mask,
          importance_weights,
      ):
          input_dict = self._lazy_tensor_dict(
              {
                  SampleBatch.CUR_OBS: obs_t,
                  SampleBatch.ACTIONS: act_t,
                  SampleBatch.REWARDS: rew_t,
                  SampleBatch.NEXT_OBS: obs_tp1,
                  SampleBatch.TERMINATEDS: terminateds_mask,
                  PRIO_WEIGHTS: importance_weights,
              }
          )
          # Do forward pass on loss to update td errors attribute
          # (one TD-error value per item in batch to update PR weights).
          actor_critic_loss(self, self.model, None, input_dict)
  
          # `self.model.td_error` is set within actor_critic_loss call.
          # Return its updated value here.
          return self.model.tower_stats["td_error"]
  
      # Assign the method to policy (self) for later usage.
      self.compute_td_error = compute_td_error
  
imports: import gymnasium
  from gymnasium.spaces import Box, Discrete
  import logging
  import tree
  from typing import Dict, List, Optional, Tuple, Type, Union
  import ray
  import ray.experimental.tf_utils
  from ray.rllib.algorithms.sac.sac_tf_policy import build_sac_model, postprocess_trajectory, validate_spaces
  from ray.rllib.algorithms.dqn.dqn_tf_policy import PRIO_WEIGHTS
  from ray.rllib.models.catalog import ModelCatalog
  from ray.rllib.models.modelv2 import ModelV2
  from ray.rllib.models.torch.torch_action_dist import TorchCategorical, TorchDistributionWrapper, TorchDirichlet, TorchSquashedGaussian, TorchDiagGaussian, TorchBeta
  from ray.rllib.policy.policy import Policy
  from ray.rllib.policy.policy_template import build_policy_class
  from ray.rllib.policy.sample_batch import SampleBatch
  from ray.rllib.utils.framework import try_import_torch
  from ray.rllib.utils.spaces.simplex import Simplex
  from ray.rllib.policy.torch_mixins import TargetNetworkMixin
  from ray.rllib.utils.torch_utils import apply_grad_clipping, concat_multi_gpu_td_errors, huber_loss
  from ray.rllib.utils.typing import LocalOptimizer, ModelInputDict, TensorType, AlgorithmConfigDict
label_desc: Use image node_id 1 to create a new ComputeTDErrorMixin object  with example: obj = ComputeTDErrorMixin()