docstr: Tests V-trace against ground truth data calculated in python.
docstr_tok: ["Tests","V-trace","against","ground","truth","data","calculated","in","python","."]
code: def test_vtrace(self):
      """Tests V-trace against ground truth data calculated in python."""
      seq_len = 5
      batch_size = 10
  
      # Create log_rhos such that rho will span from near-zero to above the
      # clipping thresholds. In particular, calculate log_rhos in
      # [-2.5, 2.5),
      # so that rho is in approx [0.08, 12.2).
      space_w_time = Box(-1.0, 1.0, (seq_len, batch_size), np.float32)
      space_only_batch = Box(-1.0, 1.0, (batch_size,), np.float32)
      log_rhos = space_w_time.sample() / (batch_size * seq_len)
      log_rhos = 5 * (log_rhos - 0.5)  # [0.0, 1.0) -> [-2.5, 2.5).
      values = {
          "log_rhos": log_rhos,
          # T, B where B_i: [0.9 / (i+1)] * T
          "discounts": np.array(
              [
                  [0.9 / (b + 1) for b in range(batch_size)]
                  for _ in range(seq_len)
              ]
          ),
          "rewards": space_w_time.sample(),
          "values": space_w_time.sample() / batch_size,
          "bootstrap_value": space_only_batch.sample() + 1.0,
          "clip_rho_threshold": 3.7,
          "clip_pg_rho_threshold": 2.2,
      }
  
      for fw, sess in framework_iterator(
          frameworks=("torch", "tf"), session=True
      ):
          vtrace = vtrace_tf if fw != "torch" else vtrace_torch
          output = vtrace.from_importance_weights(**values)
          if sess:
              output = sess.run(output)
  
          gt_vs, gt_pg_advantags = _ground_truth_vtrace_calculation(
              **values
          )
          check(output.vs, gt_vs)
          check(output.pg_advantages, gt_pg_advantags)
  
file_path: ray/rllib/algorithms/impala/tests/test_vtrace.py
imports: from gymnasium.spaces import Box
  import numpy
  import unittest
  from ray.rllib.algorithms.impala import vtrace_tf
  from ray.rllib.algorithms.impala import vtrace_torch
  from ray.rllib.utils.framework import try_import_tf, try_import_torch
  from ray.rllib.utils.numpy import softmax
  from ray.rllib.utils.test_utils import check, framework_iterator
label_desc: Use image node_id 1 for calling the VtraceTest obj's underlying member method code with example usage: obj.test_vtrace() without return types