class_docstr: Runs a given ``process_function`` over each batch of a dataset, emitting events as it goes.
  
  Args:
      process_function: A function receiving a handle to the engine and the current batch
          in each iteration, and returns data to be stored in the engine's state.
  
  Attributes:
      state: object that is used to pass internal and user-defined state between event handlers.
          It is created with the engine and its attributes (e.g. ``state.iteration``, ``state.epoch`` etc) are reset
          on every :meth:`~ignite.engine.engine.Engine.run`.
      last_event_name: last event name triggered by the engine.
  
  Note:
      :class:`~ignite.engine.engine.Engine` implementation has changed in v0.4.10 with "interrupt/resume" feature.
      Engine may behave differently on certain corner cases compared to the one from v0.4.9 and before.
      In such case, you can set ``Engine.interrupt_resume_enabled = False`` to restore previous behaviour.
  
  Examples:
      Create a basic trainer
  
      .. code-block:: python
  
          model = ...
          model = model.cuda()
          optimized = ...
          criterion = ...
  
          def train_step(engine, batch):
              model.train()
              inputs, targets = batch[0].cuda(), batch[1].cuda()
              optimizer.zero_grad()
              outputs = model(inputs)
              loss = criterion(outputs, targets)
              loss.backward()
              optimizer.step()
              return loss.item()
  
          trainer = Engine(update_model)
  
          @trainer.on(Events.ITERATION_COMPLETED(every=100))
          def log_training(engine):
              batch_loss = engine.state.output
              lr = optimizer.param_groups[0]['lr']
              e = engine.state.epoch
              n = engine.state.max_epochs
              i = engine.state.iteration
              print(f"Epoch {e}/{n} : {i} - batch loss: {batch_loss}, lr: {lr}")
  
          trainer.run(data_loader, max_epochs=5)
  
          > Epoch 1/5 : 100 - batch loss: 0.10874069479016124, lr: 0.01
          > ...
          > Epoch 2/5 : 1700 - batch loss: 0.4217900575859437, lr: 0.01
  
      Create a basic evaluator to compute metrics
  
      .. code-block:: python
  
          from ignite.metrics import Accuracy
  
          def predict_on_batch(engine, batch)
              model.eval()
              with torch.no_grad():
                  x, y = prepare_batch(batch, device=device, non_blocking=non_blocking)
                  y_pred = model(x)
  
              return y_pred, y
  
          evaluator = Engine(predict_on_batch)
          Accuracy().attach(evaluator, "val_acc")
          evaluator.run(val_dataloader)
  
      Compute image mean/std on training dataset
  
      .. code-block:: python
  
          from ignite.metrics import Average
  
          def compute_mean_std(engine, batch):
              b, c, *_ = batch['image'].shape
              data = batch['image'].reshape(b, c, -1).to(dtype=torch.float64)
              mean = torch.mean(data, dim=-1).sum(dim=0)
              mean2 = torch.mean(data ** 2, dim=-1).sum(dim=0)
              return {"mean": mean, "mean^2": mean2}
  
          compute_engine = Engine(compute_mean_std)
          img_mean = Average(output_transform=lambda output: output['mean'])
          img_mean.attach(compute_engine, 'mean')
          img_mean2 = Average(output_transform=lambda output: output['mean^2'])
          img_mean2.attach(compute_engine, 'mean2')
          state = compute_engine.run(train_loader)
          state.metrics['std'] = torch.sqrt(state.metrics['mean2'] - state.metrics['mean'] ** 2)
          mean = state.metrics['mean'].tolist()
          std = state.metrics['std'].tolist()
  
      Resume engine's run from a state. User can load a `state_dict` and run engine starting from loaded state :
  
      .. code-block:: python
  
          # Restore from an epoch
          state_dict = {"epoch": 3, "max_epochs": 100, "epoch_length": len(data_loader)}
          # or an iteration
          # state_dict = {"iteration": 500, "max_epochs": 100, "epoch_length": len(data_loader)}
  
          trainer = Engine(...)
          trainer.load_state_dict(state_dict)
          trainer.run(data)
code: def _run_once_on_dataset_as_gen(
      self,
  ) -> Generator[State, None, float]:
      start_time = time.time()
  
      # We need to setup iter_counter > 0 if we resume from an iteration
      iter_counter = 0 if self._init_iter is None else self._init_iter
      self._init_iter = None
      should_exit = False
      try:
          if self._dataloader_iter is None:
              raise RuntimeError(
                  "Internal error, self._dataloader_iter is None. "
                  "Please, file an issue if you encounter this error."
              )
  
          while True:
              self.state.batch = self.state.output = None
              try:
                  # Avoid Events.GET_BATCH_STARTED triggered twice when data iter is restarted
                  if (
                      self.last_event_name
                      != Events.DATALOADER_STOP_ITERATION
                  ):
                      self._fire_event(Events.GET_BATCH_STARTED)
                      yield from self._maybe_terminate_or_interrupt()
  
                  self.state.batch = next(self._dataloader_iter)
                  self._fire_event(Events.GET_BATCH_COMPLETED)
                  yield from self._maybe_terminate_or_interrupt()
  
                  iter_counter += 1
                  should_exit = False
              except StopIteration:
                  # Define self.state.epoch_length if it is not yet set
                  if self.state.epoch_length is None:
                      # Define epoch length and stop the epoch
                      self.state.epoch_length = iter_counter
                      if self.state.max_iters is not None:
                          self.state.max_epochs = math.ceil(
                              self.state.max_iters
                              / self.state.epoch_length
                          )
                      break
  
                  # Should exit while loop if we can not iterate
                  if should_exit:
                      if not self._is_done(self.state):
                          total_iters = (
                              self.state.epoch_length
                              * self.state.max_epochs
                              if self.state.max_epochs is not None
                              else self.state.max_iters
                          )
  
                          warnings.warn(
                              "Data iterator can not provide data anymore but required total number of "
                              "iterations to run is not reached. "
                              f"Current iteration: {self.state.iteration} vs Total iterations to run : {total_iters}"
                          )
                      break
  
                  self._fire_event(Events.DATALOADER_STOP_ITERATION)
                  yield from self._maybe_terminate_or_interrupt()
  
                  self._setup_dataloader_iter()
                  should_exit = True
  
                  continue
  
              self.state.iteration += 1
              self._fire_event(Events.ITERATION_STARTED)
              yield from self._maybe_terminate_or_interrupt()
  
              self.state.output = self._process_function(
                  self, self.state.batch
              )
              self._fire_event(Events.ITERATION_COMPLETED)
              yield from self._maybe_terminate_or_interrupt()
  
              if (
                  self.state.epoch_length is not None
                  and iter_counter == self.state.epoch_length
              ):
                  break
  
              if (
                  self.state.max_iters is not None
                  and self.state.iteration == self.state.max_iters
              ):
                  self.should_terminate = True
                  raise _EngineTerminateException()
  
      except _EngineTerminateSingleEpochException:
          self._fire_event(
              Events.TERMINATE_SINGLE_EPOCH, iter_counter=iter_counter
          )
          self.should_terminate_single_epoch = False
          self._setup_dataloader_iter()
  
      except _EngineTerminateException as e:
          # we need to reraise this exception such that it is not handled
          # as a general exception by the code below
          raise e
  
      except Exception as e:
          self.logger.error(
              f"Current run is terminating due to exception: {e}"
          )
          self._handle_exception(e)
  
      return time.time() - start_time
  
imports: import functools
  import logging
  import math
  import time
  import warnings
  import weakref
  from collections import defaultdict, OrderedDict
  from collections.abc import Mapping
  from typing import Any, Callable, Dict, Generator, Iterable, Iterator, List, Optional, Tuple, Union
  from torch.utils.data import DataLoader
  from ignite.base import Serializable
  from ignite.engine.events import CallableEventWithFilter, EventEnum, Events, EventsList, RemovableEventHandle, State
  from ignite.engine.utils import _check_signature, _to_hours_mins_secs
label_desc: Use image node_id 29 for calling the Engine obj's underlying member method code with example usage: obj._run_once_on_dataset_as_gen() and returns: unknown