code: def test_cosine_annealing_scheduler(cyclic_warmup):
      tensor = torch.zeros([1], requires_grad=True)
      optimizer = torch.optim.SGD([tensor], lr=0)
  
      scheduler = CosineAnnealingScheduler(
          optimizer,
          "lr",
          0,
          1,
          10,
          warmup_duration=2 if cyclic_warmup else 0,
      )
      state_dict = scheduler.state_dict()
  
      data = [0] * (10 + int(cyclic_warmup))
      max_epochs = 2
      simulated_values = CosineAnnealingScheduler.simulate_values(
          num_events=len(data) * max_epochs,
          param_name="lr",
          start_value=0,
          end_value=1,
          cycle_size=10,
          warmup_duration=2 if cyclic_warmup else 0,
      )
  
      def save_lr(engine):
          lrs.append(optimizer.param_groups[0]["lr"])
  
      trainer = Engine(lambda engine, batch: None)
      trainer.add_event_handler(Events.ITERATION_STARTED, scheduler)
      trainer.add_event_handler(Events.ITERATION_COMPLETED, save_lr)
      lr_values_in_cycle = [
          0.0,
          0.02447174185242318,
          0.09549150281252627,
          0.20610737385376332,
          0.3454915028125263,
          0.5,
          0.6545084971874737,
          0.7938926261462365,
          0.9045084971874737,
          0.9755282581475768,
      ]
      lr_values_in_warmup = (
          np.linspace(1.0, 0.0, 2 + 1)[:-1].tolist()
          if cyclic_warmup
          else []
      )
  
      for _ in range(2):
          lrs = []
          trainer.run(data, max_epochs=max_epochs)
  
          assert lrs == pytest.approx(
              [
                  *lr_values_in_cycle,
                  *lr_values_in_warmup,
                  *lr_values_in_cycle,
              ]
          )
          scheduler.load_state_dict(state_dict)
  
          assert lrs == pytest.approx([v for i, v in simulated_values])
  
imports: from unittest.mock import MagicMock, patch
  import numpy
  import pytest
  import torch
  from torch.optim.lr_scheduler import CosineAnnealingWarmRestarts, ExponentialLR, StepLR
  from ignite.engine import Engine, Events
  from ignite.handlers.param_scheduler import ConcatScheduler, CosineAnnealingScheduler, create_lr_scheduler_with_warmup, LinearCyclicalScheduler, LRScheduler, ParamGroupScheduler, ParamScheduler, PiecewiseLinear, ReduceLROnPlateauScheduler
  from tests.ignite.contrib.handlers import MockFP16DeepSpeedZeroOptimizer
label_desc: Use image node_id 5 for calling a global function with example usage: test_cosine_annealing_scheduler(cyclic_warmup) without return types