def test_migrate_loop_structure_after_optimizer_loop_removal():
    """Test the loop state migration after multiple optimizer support in automatic optimization was removed in
    2.0.0."""
    state_automatic = MagicMock()
    state_manual = MagicMock()
    optim_progress_automatic = {
        "optimizer": MagicMock(),
        "optimizer_position": 33,
    }
    optim_progress_manual = MagicMock()
    old_checkpoint = {
        "loops": {
            "fit_loop": {
                "epoch_loop.state_dict": {"any": "state"},
                "epoch_loop.batch_loop.state_dict": MagicMock(),
                "epoch_loop.batch_loop.optimizer_loop.state_dict": state_automatic,
                "epoch_loop.batch_loop.optimizer_loop.optim_progress": optim_progress_automatic,
                "epoch_loop.batch_loop.manual_loop.state_dict": state_manual,
                "epoch_loop.batch_loop.manual_loop.optim_step_progress": optim_progress_manual,
            }
        }
    }
    _set_version(old_checkpoint, "1.9.0")  # pretend a checkpoint prior to 2.0.0
    updated_checkpoint, _ = migrate_checkpoint(old_checkpoint.copy(), target_version="2.0.0")
    assert updated_checkpoint["loops"] == {
        "fit_loop": {
            "epoch_loop.state_dict": ANY,
            "epoch_loop.automatic_optimization.state_dict": state_automatic,
            "epoch_loop.automatic_optimization.optim_progress": {"optimizer": ANY},  # optimizer_position gets dropped
            "epoch_loop.manual_optimization.state_dict": state_manual,
            "epoch_loop.manual_optimization.optim_step_progress": optim_progress_manual,
        }
    }
Test the loop state migration after multiple optimizer support in automatic optimization was removed in
    2.0.0.
tests/tests_pytorch/utilities/migration/test_migration.py