re3_exploration.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. """Examples demonstrating the usage of RE3 exploration strategy.
  2. To use RE3 user will need to patch the callbacks with RE3 specific callbacks
  3. and set the `exploration_config` with RE3 configs.
  4. ```Python
  5. config["exploration_config"] = {"type": "RE3"}
  6. """
  7. from functools import partial
  8. import ray
  9. from ray.rllib.agents import sac
  10. from ray.rllib.agents.callbacks import MultiCallbacks, RE3UpdateCallbacks
  11. if __name__ == "__main__":
  12. ray.init()
  13. config = sac.DEFAULT_CONFIG.copy()
  14. # Add a new RE3UpdateCallbacks
  15. config["callbacks"] = MultiCallbacks([
  16. config["callbacks"],
  17. partial(
  18. RE3UpdateCallbacks,
  19. embeds_dim=128,
  20. beta_schedule="linear_decay",
  21. k_nn=50),
  22. ])
  23. config["env"] = "LunarLanderContinuous-v2"
  24. config["seed"] = 12345
  25. # Add type as RE3 in the exploration_config parameter
  26. config["exploration_config"] = {
  27. "type": "RE3",
  28. "sub_exploration": {
  29. "type": "StochasticSampling",
  30. }
  31. }
  32. num_iterations = 2000
  33. trainer = sac.SACTrainer(config=config)
  34. for i in range(num_iterations):
  35. result = trainer.train()
  36. print(result)
  37. trainer.stop()
  38. ray.shutdown()