constant_schedule.py 696 B

123456789101112131415161718192021222324252627
  1. from ray.rllib.utils.annotations import override
  2. from ray.rllib.utils.framework import try_import_tf
  3. from ray.rllib.utils.schedules.schedule import Schedule
  4. tf1, tf, tfv = try_import_tf()
  5. class ConstantSchedule(Schedule):
  6. """
  7. A Schedule where the value remains constant over time.
  8. """
  9. def __init__(self, value, framework):
  10. """
  11. Args:
  12. value (float): The constant value to return, independently of time.
  13. """
  14. super().__init__(framework=framework)
  15. self._v = value
  16. @override(Schedule)
  17. def _value(self, t):
  18. return self._v
  19. @override(Schedule)
  20. def _tf_value_op(self, t):
  21. return tf.constant(self._v)