code: def test_epoch_length():
      def _test(data, max_epochs, num_iters):
          batch_checker = BatchChecker(data)
  
          def update_fn(_, batch):
              assert batch_checker.check(
                  batch
              ), f"{batch_checker.counter}: {batch_checker.true_batch} vs {batch}"
  
          engine = Engine(update_fn)
          engine.run(
              data, max_epochs=max_epochs, epoch_length=num_iters
          )
          if num_iters is None:
              num_iters = len(data)
          assert engine.state.iteration == num_iters * max_epochs
          assert engine.state.epoch == max_epochs
  
      def _test_as_iter(data, max_epochs, num_iters):
          batch_checker = BatchChecker(data)
  
          def update_fn(_, batch):
              assert batch_checker.check(
                  batch
              ), f"{batch_checker.counter}: {batch_checker.true_batch} vs {batch}"
  
          engine = Engine(update_fn)
          engine.run(
              iter(data), max_epochs=max_epochs, epoch_length=num_iters
          )
          if num_iters is None:
              num_iters = len(data)
          assert engine.state.iteration == num_iters * max_epochs
          assert engine.state.epoch == max_epochs
  
      max_epochs = 10
      num_iters = 21
      data = torch.randint(0, 1000, size=(num_iters,))
      _test(data, max_epochs, num_iters=None)
      _test(data, max_epochs, num_iters)
      _test(data, max_epochs, num_iters // 2)
      _test(data, max_epochs, num_iters * 2)
  
      _test_as_iter(data, 1, num_iters)
      _test_as_iter(data, 2, num_iters // 2)
  
file_path: ignite/tests/ignite/engine/test_engine_state_dict.py
imports: from collections.abc import Mapping
  import pytest
  import torch
  from ignite.engine import Engine, Events, State
  from tests.ignite.engine import BatchChecker, EpochCounter, IterationCounter
label_desc: Use image node_id 12 for calling a global function with example usage: test_epoch_length() without return types