code: def test_result_collection_simple_loop():
      result = _ResultCollection(True)
      current_fx_name = None
      batch_idx = None
  
      def lightning_log(fx, *args, **kwargs):
          nonlocal current_fx_name
          if current_fx_name != fx and batch_idx in (None, 0):
              result.reset(metrics=False, fx=fx)
          result.log(fx, *args, **kwargs)
          current_fx_name = fx
  
      lightning_log("a0", "a", tensor(0.0), on_step=True, on_epoch=True)
      lightning_log("a1", "a", tensor(0.0), on_step=True, on_epoch=True)
      for epoch in range(2):
          lightning_log(
              "b0",
              "a",
              tensor(1.0) + epoch,
              on_step=True,
              on_epoch=True,
          )
          lightning_log(
              "b1",
              "a",
              tensor(1.0) + epoch,
              on_step=True,
              on_epoch=True,
          )
          for batch_idx in range(2):
              lightning_log(
                  "c0",
                  "a",
                  tensor(2.0) + epoch,
                  on_step=True,
                  on_epoch=True,
              )
              lightning_log(
                  "c1",
                  "a",
                  tensor(2.0) + epoch,
                  on_step=True,
                  on_epoch=True,
              )
              lightning_log(
                  "c2",
                  "a",
                  tensor(2.0) + epoch,
                  on_step=True,
                  on_epoch=True,
              )
          batch_idx = None
          lightning_log(
              "d0",
              "a",
              tensor(3.0) + epoch,
              on_step=False,
              on_epoch=True,
          )
          lightning_log(
              "d1",
              "a",
              tensor(3.0) + epoch,
              on_step=False,
              on_epoch=True,
          )
  
          for k in ("a0.a", "a1.a"):
              assert result[k].value == tensor(0.0), k
              assert result[k].cumulated_batch_size == tensor(1.0), k
  
          for k in ("b0.a", "b1.a"):
              assert result[k].value == tensor(1.0) + epoch, k
              assert result[k].cumulated_batch_size == tensor(1.0), k
  
          for k in ("c0.a", "c1.a", "c2.a"):
              assert result[k].value == tensor(4.0) + epoch * 2, k
              assert result[k].cumulated_batch_size == tensor(2.0), k
  
          for k in ("d0.a", "d1.a"):
              assert result[k].value == tensor(3.0) + epoch, k
              assert result[k].cumulated_batch_size == tensor(1.0), k
  
imports: import os
  import pickle
  from contextlib import nullcontext, suppress
  from unittest import mock
  import lightning.pytorch
  import pytest
  import torch
  from lightning.fabric.utilities.warnings import PossibleUserWarning
  from lightning.pytorch import Trainer
  from lightning.pytorch.callbacks import OnExceptionCheckpoint
  from lightning.pytorch.demos.boring_classes import BoringModel
  from lightning.pytorch.trainer.connectors.logger_connector.result import _Metadata, _ResultCollection, _ResultMetric, _Sync
  from lightning.pytorch.utilities.imports import _TORCHMETRICS_GREATER_EQUAL_0_11
  from lightning_utilities.test.warning import no_warning_call
  from torch import Tensor, tensor
  from torch.nn import ModuleDict, ModuleList
  from torchmetrics import Metric, MetricCollection
  from torchmetrics.classification import Accuracy
  from tests_pytorch.core.test_results import spawn_launch
  from tests_pytorch.helpers.runif import RunIf
label_desc: Use image node_id 4 for calling a global function with example usage: test_result_collection_simple_loop() without return types