        def init_and_restore_scheduler(
            optimizer: torch.optim.Optimizer,
            params: Dict[str, Any],
            state_dict: Dict[str, Any] = None,
        ):
            """
            Initialize a new scheduler and optionally restore its state from
            a checkpoint.
            """
            params["type"] = "cosine"
            scheduler = LearningRateScheduler.from_params(
                optimizer=optimizer, params=Params(deepcopy(params))
            )
            if state_dict is not None:
                scheduler.load_state_dict(state_dict)
            return scheduler
Initialize a new scheduler and optionally restore its state from
a checkpoint.
tests/training/learning_rate_schedulers/cosine_test.py