re3_exploration.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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.algorithms import sac
  10. from ray.rllib.algorithms.callbacks import MultiCallbacks, RE3UpdateCallbacks
  11. if __name__ == "__main__":
  12. ray.init()
  13. config = (
  14. sac.SACConfig()
  15. .environment("LunarLanderContinuous-v2")
  16. # Add type as RE3 in the exploration_config parameter
  17. .exploration(
  18. exploration_config={
  19. "type": "RE3",
  20. "sub_exploration": {
  21. "type": "StochasticSampling",
  22. },
  23. }
  24. )
  25. .debugging(seed=12345)
  26. )
  27. # Add a new RE3UpdateCallbacks
  28. config.callbacks(
  29. MultiCallbacks(
  30. [
  31. config.callbacks_class,
  32. partial(
  33. RE3UpdateCallbacks,
  34. embeds_dim=128,
  35. beta_schedule="linear_decay",
  36. k_nn=50,
  37. ),
  38. ]
  39. )
  40. )
  41. num_iterations = 2000
  42. algo = config.build()
  43. for i in range(num_iterations):
  44. result = algo.train()
  45. print(result)
  46. algo.stop()
  47. ray.shutdown()