code: def test_params_groups_and_state_are_accessible(tmpdir):
      class TestModel(BoringModel):
          def on_train_start(self):
              # Update the learning rate manually on the unwrapped optimizer
              assert not isinstance(
                  self.trainer.optimizers[0], LightningOptimizer
              )
              self.trainer.optimizers[0].param_groups[0]["lr"] = 2.0
  
          def training_step(self, batch, batch_idx):
              opt = self.optimizers()
              assert opt.param_groups[0]["lr"] == 2.0
  
              loss = self.step(batch)
              self.__loss = loss
              return loss
  
          def configure_optimizers(self):
              return SGD(self.layer.parameters(), lr=0.1)
  
          def optimizer_step(
              self, epoch, batch_idx, optimizer, optimizer_closure, **__
          ):
              # check attributes are accessible
              assert all("lr" in pg for pg in optimizer.param_groups)
              assert optimizer.state is optimizer._optimizer.state
              assert optimizer.defaults is optimizer._optimizer.defaults
  
              loss = optimizer.step(closure=optimizer_closure)
              # the optimizer step still returns the loss
              assert loss == self.__loss
  
      model = TestModel()
      trainer = Trainer(
          max_epochs=1,
          default_root_dir=tmpdir,
          limit_train_batches=1,
          limit_val_batches=0,
      )
      trainer.fit(model)
  
imports: from copy import deepcopy
  from unittest.mock import DEFAULT, Mock, patch
  import pytest
  import torch
  from lightning.pytorch import Trainer
  from lightning.pytorch.core.optimizer import LightningOptimizer
  from lightning.pytorch.demos.boring_classes import BoringModel
  from lightning.pytorch.loops.optimization.automatic import Closure
  from lightning.pytorch.tuner.tuning import Tuner
  from torch.optim import SGD, Adam, Optimizer
label_desc: Use image node_id 10 for calling a global function with example usage: test_params_groups_and_state_are_accessible(tmpdir) and returns: loss, SGD