code: def test_log_momentum_no_momentum_optimizer(tmpdir):
      """Test that if optimizer doesn't have momentum then a warning is raised with log_momentum=True."""
  
      class LogMomentumModel(BoringModel):
          def configure_optimizers(self):
              optimizer = optim.ASGD(self.parameters(), lr=1e-2)
              lr_scheduler = optim.lr_scheduler.StepLR(
                  optimizer, step_size=1
              )
              return [optimizer], [lr_scheduler]
  
      model = LogMomentumModel()
      lr_monitor = LearningRateMonitor(log_momentum=True)
      trainer = Trainer(
          default_root_dir=tmpdir,
          max_epochs=1,
          limit_val_batches=2,
          limit_train_batches=5,
          log_every_n_steps=1,
          callbacks=[lr_monitor],
          logger=CSVLogger(tmpdir),
      )
      with pytest.warns(
          RuntimeWarning, match="optimizers do not have momentum."
      ):
          trainer.fit(model)
  
      assert all(
          v == 0 for v in lr_monitor.last_momentum_values.values()
      ), "Expected momentum to be logged"
      assert len(lr_monitor.last_momentum_values) == len(
          trainer.lr_scheduler_configs
      )
      assert all(
          k == "lr-ASGD-momentum"
          for k in lr_monitor.last_momentum_values
      )
  
imports: import pytest
  import torch
  from lightning.pytorch import Trainer
  from lightning.pytorch.callbacks import EarlyStopping, LearningRateMonitor
  from lightning.pytorch.callbacks.callback import Callback
  from lightning.pytorch.callbacks.finetuning import BackboneFinetuning
  from lightning.pytorch.demos.boring_classes import BoringModel
  from lightning.pytorch.loggers import CSVLogger
  from lightning.pytorch.utilities.exceptions import MisconfigurationException
  from torch import optim
  from tests_pytorch.helpers.datamodules import ClassifDataModule
  from tests_pytorch.helpers.runif import RunIf
  from tests_pytorch.helpers.simple_models import ClassificationModel
label_desc: Use image node_id 3 for calling a global function with example usage: test_log_momentum_no_momentum_optimizer(tmpdir) and returns: list,  list