Example #1
0
 def test_leaky_policy(self):
     """Tests, whether our diagnostics tools can detect leaks in a policy."""
     config = dqn.DEFAULT_CONFIG.copy()
     # Make sure we have an env to test on the local worker.
     # Otherwise, `check_memory_leaks` will complain.
     config["create_env_on_driver"] = True
     config["env"] = "CartPole-v0"
     config["multiagent"]["policies"] = {
         "default_policy": PolicySpec(policy_class=MemoryLeakingPolicy),
     }
     trainer = dqn.DQN(config=config)
     results = check_memory_leaks(trainer, to_check={"policy"}, repeats=300)
     assert results["policy"]
     trainer.stop()
Example #2
0
 def test_leaky_env(self):
     """Tests, whether our diagnostics tools can detect leaks in an env."""
     config = ppo.DEFAULT_CONFIG.copy()
     # Make sure we have an env to test on the local worker.
     # Otherwise, `check_memory_leaks` will complain.
     config["create_env_on_driver"] = True
     config["env"] = MemoryLeakingEnv
     config["env_config"] = {
         "static_samples": True,
     }
     trainer = ppo.PPO(config=config)
     results = check_memory_leaks(trainer, to_check={"env"}, repeats=150)
     assert results["env"]
     trainer.stop()
Example #3
0
        # Move "env" specifier into config.
        experiment["config"]["env"] = experiment["env"]
        experiment.pop("env", None)

        # Print out the actual config.
        print("== Test config ==")
        print(yaml.dump(experiment))

        # Construct the trainer instance based on the given config.
        leaking = True
        try:
            ray.init(num_cpus=5, local_mode=args.local_mode)
            trainer = get_trainer_class(experiment["run"])(
                experiment["config"])
            results = check_memory_leaks(
                trainer,
                to_check=set(args.to_check),
            )
            if not results:
                leaking = False
        finally:
            ray.shutdown()
            _register_all()

        if not leaking:
            print("Memory leak test PASSED")
        else:
            print("Memory leak test FAILED. Exiting with Error.")
            sys.exit(1)