code: def test_lr_monitor_update_callback_metrics(tmpdir):
      """Test that the `LearningRateMonitor` callback updates trainer.callback_metrics."""
  
      class TestModel(BoringModel):
          def configure_optimizers(self):
              optimizer = torch.optim.SGD(
                  self.layer.parameters(), lr=0.1
              )
              lr_scheduler = torch.optim.lr_scheduler.StepLR(
                  optimizer, step_size=1, gamma=0.5
              )
              return [optimizer], [lr_scheduler]
  
      monitor_key = "lr-SGD"
      stop_threshold = 0.02
      expected_stop_epoch = 3
  
      lr_monitor = LearningRateMonitor()
      lr_es = EarlyStopping(
          monitor=monitor_key,
          mode="min",
          stopping_threshold=stop_threshold,
          check_on_train_epoch_end=True,
      )
      trainer = Trainer(
          default_root_dir=tmpdir,
          callbacks=[lr_monitor, lr_es],
          max_epochs=5,
          limit_val_batches=0,
          limit_train_batches=2,
          logger=CSVLogger(tmpdir),
      )
      model = TestModel()
      trainer.fit(model)
  
      assert monitor_key in trainer.callback_metrics
      assert lr_monitor.lrs[monitor_key] == [0.1, 0.05, 0.025, 0.0125]
      assert (
          min(lr_monitor.lrs[monitor_key][:expected_stop_epoch])
          > stop_threshold
      )
      assert len(lr_monitor.lrs[monitor_key][expected_stop_epoch:]) == 1
      assert (
          min(lr_monitor.lrs[monitor_key][expected_stop_epoch:])
          < stop_threshold
      )
      assert trainer.current_epoch - 1 == expected_stop_epoch
      assert lr_es.stopped_epoch == expected_stop_epoch
  
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 16 for calling a global function with example usage: test_lr_monitor_update_callback_metrics(tmpdir) and returns: list,  list