docstr: Test whether a DT algorithm can be built with all supported frameworks.
docstr_tok: ["Test","whether","a","DT","algorithm","can","be","built","with","all","supported","frameworks","."]
code: def test_dt_compilation(self):
      """Test whether a DT algorithm can be built with all supported frameworks."""
  
      config = (
          DTConfig()
          .environment(
              env="Pendulum-v1",
              clip_actions=True,
              normalize_actions=True,
          )
          .framework("torch")
          .offline_data(
              input_="dataset",
              input_config={
                  "format": "json",
                  "paths": [
                      "s3://anonymous@air-example-data/rllib/pendulum/large.json"
                  ],
              },
              actions_in_input_normalized=True,
          )
          .training(
              train_batch_size=200,
              replay_buffer_config={
                  "capacity": 8,
              },
              model={
                  "max_seq_len": 4,
              },
              num_layers=1,
              num_heads=1,
              embed_dim=64,
              horizon=200,
          )
          .evaluation(
              target_return=-120,
              evaluation_interval=2,
              evaluation_num_workers=0,
              evaluation_duration=10,
              evaluation_duration_unit="episodes",
              evaluation_parallel_to_training=False,
              evaluation_config=DTConfig.overrides(
                  input_="sampler", explore=False
              ),
          )
          .rollouts(
              num_rollout_workers=0,
          )
          .reporting(
              min_train_timesteps_per_iteration=10,
          )
          .experimental(
              _disable_preprocessor_api=True,
          )
      )
  
      num_iterations = 4
  
      for _ in ["torch"]:
          algo = config.build()
          # check if 4 iterations raises any errors
          for i in range(num_iterations):
              results = algo.train()
              check_train_results(results)
              print(results)
              if (i + 1) % 2 == 0:
                  # evaluation happens every 2 iterations
                  eval_results = results["evaluation"]
                  print(
                      f"iter={algo.iteration} "
                      f"R={eval_results['episode_reward_mean']}"
                  )
  
          # do example inference rollout
          env = gym.make("Pendulum-v1")
  
          obs, _ = env.reset()
          input_dict = algo.get_initial_input_dict(obs)
  
          for _ in range(200):
              action, _, extra = algo.compute_single_action(
                  input_dict=input_dict
              )
              obs, reward, terminated, truncated, _ = env.step(action)
              if terminated or truncated:
                  break
              else:
                  input_dict = algo.get_next_input_dict(
                      input_dict,
                      action,
                      reward,
                      obs,
                      extra,
                  )
  
          env.close()
          algo.stop()
  
file_path: ray/rllib_contrib/dt/tests/test_dt.py
imports: import unittest
  from typing import Dict
  import gymnasium
  import numpy
  from rllib_dt.dt.dt import DTConfig
  import ray
  from ray.rllib import SampleBatch
  from ray.rllib.utils.framework import try_import_tf, try_import_torch
  from ray.rllib.utils.test_utils import check_train_results
label_desc: Use image node_id 3 for calling the TestDT obj's underlying member method code with example usage: obj.test_dt_compilation() without return types