code: def test_basic_schedule(self):
      optimizer = self._get_optimizer()
      scheduler = MomentumScheduler.from_params(
          optimizer=optimizer,
          params=Params(
              {
                  "type": "inverted_triangular",
                  "cool_down": 6,
                  "warm_up": 10,
                  "ratio": 5,
              }
          ),
      )
      # Before first epoch, momentum should be unchanged.
      assert optimizer.param_groups[0]["momentum"] == self.base_momentum
      # After first epoch, `step` is called, and momentum should be adjusted for
      # the next epoch.
      scheduler.step()
      assert isclose(
          optimizer.param_groups[0]["momentum"],
          self.base_momentum
          - (self.base_momentum - self.base_momentum / 5) * (1 / 6),
      )
      # After second epoch, `step` is called and momentum is updated for 3rd epoch.
      scheduler.step()
      assert isclose(
          optimizer.param_groups[0]["momentum"],
          self.base_momentum
          - (self.base_momentum - self.base_momentum / 5) * (2 / 6),
      )
      scheduler.last_epoch = 4
      # ... after the 6th epoch (epoch id 5), momentum should be set to `base_momentum / ratio`.
      scheduler.step()
      assert isclose(
          optimizer.param_groups[0]["momentum"], self.base_momentum / 5
      )
      # Then the momentum stars increasing again.
      scheduler.step()
      assert isclose(
          optimizer.param_groups[0]["momentum"],
          self.base_momentum / 5
          + (self.base_momentum - self.base_momentum / 5) * (1 / 10),
      )
      # After the 16th epoch (6 + 10) (epoch id 15), momentum should be back to the base level.
      scheduler.last_epoch = 14
      scheduler.step()
      assert isclose(
          optimizer.param_groups[0]["momentum"], self.base_momentum
      )
      scheduler.step()
      assert isclose(
          optimizer.param_groups[0]["momentum"], self.base_momentum
      )
      scheduler.step()
      assert isclose(
          optimizer.param_groups[0]["momentum"], self.base_momentum
      )
  
file_path: allennlp/tests/training/momentum_schedulers/inverted_triangular_test.py
imports: from math import isclose
  import torch
  from allennlp.common.params import Params
  from allennlp.common.testing import AllenNlpTestCase
  from allennlp.training.momentum_schedulers import MomentumScheduler
  from allennlp.training.optimizers import Optimizer
label_desc: Use image node_id 4 for calling the InvertedTriangularTest obj's underlying member method code with example usage: obj.test_basic_schedule() without return types