Skip to content

Commit 949af4c

Browse files
committed
Add CustomScheduler
1 parent 80d4ef8 commit 949af4c

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

alf/utils/schedulers.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,25 @@ def final_value(self):
343343
"This scheduler is cyclical and does not have a final value.")
344344

345345

346+
@alf.configurable
347+
class CustomScheduler(Scheduler):
348+
349+
def __init__(self, progress_type: str, func: Callable[[float], float]):
350+
"""
351+
Args:
352+
progress_type: one of "percent", "iterations", "env_steps"
353+
func: a callable function that takes a single argument
354+
which is the current progress and returns the scheduled value.
355+
"""
356+
super().__init__(progress_type)
357+
assert callable(func)
358+
self._func = func
359+
360+
def __call__(self):
361+
progress = self.progress()
362+
return self._func(progress)
363+
364+
346365
ValueOrScheduler = Union[Number, Scheduler]
347366

348367

0 commit comments

Comments
 (0)