docstr: Test whether a MARWILAlgorithm can be built with all frameworks.
  
  Learns from a historic-data file.
  To generate this data, first run:
  $ ./train.py --run=PPO --env=CartPole-v1           --stop='{"timesteps_total": 50000}'           --config='{"output": "/tmp/out", "batch_mode": "complete_episodes"}'
docstr_tok: ["Test","whether","a","MARWILAlgorithm","can","be","built","with","all","frameworks",".","Learns","from","a","historic-data","file",".","To","generate","this","data",",","first","run",":","$",".\/train.py","--","run=PPO","--","env=CartPole-v1","--","stop=","'","{","``","timesteps_total","''",":","50000","}","'","--","config=","'","{","``","output","''",":","``","\/tmp\/out","''",",","``","batch_mode","''",":","``","complete_episodes","''","}","'"]
code: def test_marwil_compilation_and_learning_from_offline_file(self):
      """Test whether a MARWILAlgorithm can be built with all frameworks.
  
          Learns from a historic-data file.
          To generate this data, first run:
          $ ./train.py --run=PPO --env=CartPole-v1 \
            --stop='{"timesteps_total": 50000}' \
            --config='{"output": "/tmp/out", "batch_mode": "complete_episodes"}'
          """
      rllib_dir = Path(__file__).parent.parent.parent.parent
      print("rllib dir={}".format(rllib_dir))
      data_file = os.path.join(
          rllib_dir, "tests/data/cartpole/large.json"
      )
      print(
          "data_file={} exists={}".format(
              data_file, os.path.isfile(data_file)
          )
      )
  
      config = (
          marwil.MARWILConfig()
          .rollouts(num_rollout_workers=2)
          .environment(env="CartPole-v1")
          .evaluation(
              evaluation_interval=3,
              evaluation_num_workers=1,
              evaluation_duration=5,
              evaluation_parallel_to_training=True,
              evaluation_config=marwil.MARWILConfig.overrides(
                  input_="sampler"
              ),
              off_policy_estimation_methods={},
              always_attach_evaluation_results=True,
          )
          .offline_data(input_=[data_file])
      )
  
      num_iterations = 350
      min_reward = 100.0
  
      # Test for all frameworks.
      for _ in framework_iterator(config, frameworks=("torch", "tf")):
          algo = config.build()
          learnt = False
          for i in range(num_iterations):
              results = algo.train()
              check_train_results(results)
              print(results)
  
              eval_results = results.get("evaluation")
              if eval_results:
                  print(
                      "iter={} R={} ".format(
                          i, eval_results["episode_reward_mean"]
                      )
                  )
                  # Learn until some reward is reached on an actual live env.
                  if eval_results["episode_reward_mean"] > min_reward:
                      print("learnt!")
                      learnt = True
                      break
  
          if not learnt:
              raise ValueError(
                  "MARWILAlgorithm did not reach {} reward from expert "
                  "offline data!".format(min_reward)
              )
  
          check_compute_single_action(
              algo, include_prev_action_reward=True
          )
  
          algo.stop()
  
file_path: ray/rllib/algorithms/marwil/tests/test_marwil.py
imports: import numpy
  import os
  from pathlib import Path
  import unittest
  import ray
  import ray.rllib.algorithms.marwil
  from ray.rllib.algorithms.marwil.marwil_tf_policy import MARWILTF2Policy
  from ray.rllib.algorithms.marwil.marwil_torch_policy import MARWILTorchPolicy
  from ray.rllib.evaluation.postprocessing import compute_advantages
  from ray.rllib.offline import JsonReader
  from ray.rllib.utils.framework import try_import_tf, try_import_torch
  from ray.rllib.utils.test_utils import check, check_compute_single_action, check_train_results, framework_iterator
label_desc: Use image node_id 3 for calling the TestMARWIL obj's underlying member method code with example usage: obj.test_marwil_compilation_and_learning_from_offline_file() without return types