code: def test_manual_optimization_with_non_pytorch_scheduler(
      automatic_optimization,
  ):
      """In manual optimization, the user can provide a custom scheduler that doesn't follow PyTorch's interface."""
  
      class IncompatibleScheduler:
          def __init__(self, optimizer):
              self.optimizer = optimizer
  
          def state_dict(self):
              return {}
  
          def load_state_dict(self, _):
              pass
  
      class Model(BoringModel):
          def __init__(self):
              super().__init__()
              self.automatic_optimization = automatic_optimization
  
          def configure_optimizers(self):
              optimizer = torch.optim.SGD(
                  self.layer.parameters(), lr=0.1
              )
              scheduler = IncompatibleScheduler(optimizer)
              return [optimizer], [scheduler]
  
      model = Model()
      trainer = Trainer(accelerator="cpu", max_epochs=0)
      if automatic_optimization:
          with pytest.raises(
              MisconfigurationException,
              match="doesn't follow PyTorch's LRScheduler",
          ):
              trainer.fit(model)
      else:
          # No error for manual optimization
          trainer.fit(model)
  
imports: import collections
  import contextlib
  from copy import deepcopy
  from unittest import mock
  from unittest.mock import ANY, call, patch
  import pytest
  import torch
  import torch.distributed
  import torch.nn.functional
  from lightning.fabric.utilities.exceptions import MisconfigurationException
  from lightning.fabric.utilities.imports import _TORCH_GREATER_EQUAL_2_0
  from lightning.pytorch import Trainer, seed_everything
  from lightning.pytorch.demos.boring_classes import BoringModel, ManualOptimBoringModel
  from lightning.pytorch.strategies import Strategy
  from tests_pytorch.helpers.runif import RunIf
label_desc: Use image node_id 19 for calling a global function with example usage: test_manual_optimization_with_non_pytorch_scheduler(automatic_optimization) and returns: dict, list,  list