class_docstr: Generative adversarial network training based on Goodfellow et al. 2014 https://arxiv.org/abs/1406.266,
  inherits from ``Trainer`` and ``Workflow``.
  
  Training Loop: for each batch of data size `m`
      1. Generate `m` fakes from random latent codes.
      2. Update discriminator with these fakes and current batch reals, repeated d_train_steps times.
      3. If g_update_latents, generate `m` fakes from new random latent codes.
      4. Update generator with these fakes using discriminator feedback.
  
  Args:
      device: an object representing the device on which to run.
      max_epochs: the total epoch number for engine to run.
      train_data_loader: Core ignite engines uses `DataLoader` for training loop batchdata.
      g_network: generator (G) network architecture.
      g_optimizer: G optimizer function.
      g_loss_function: G loss function for optimizer.
      d_network: discriminator (D) network architecture.
      d_optimizer: D optimizer function.
      d_loss_function: D loss function for optimizer.
      epoch_length: number of iterations for one epoch, default to `len(train_data_loader)`.
      g_inferer: inference method to execute G model forward. Defaults to ``SimpleInferer()``.
      d_inferer: inference method to execute D model forward. Defaults to ``SimpleInferer()``.
      d_train_steps: number of times to update D with real data minibatch. Defaults to ``1``.
      latent_shape: size of G input latent code. Defaults to ``64``.
      non_blocking: if True and this copy is between CPU and GPU, the copy may occur asynchronously
          with respect to the host. For other cases, this argument has no effect.
      d_prepare_batch: callback function to prepare batchdata for D inferer.
          Defaults to return ``GanKeys.REALS`` in batchdata dict. for more details please refer to:
          https://pytorch.org/ignite/generated/ignite.engine.create_supervised_trainer.html.
      g_prepare_batch: callback function to create batch of latent input for G inferer.
          Defaults to return random latents. for more details please refer to:
          https://pytorch.org/ignite/generated/ignite.engine.create_supervised_trainer.html.
      g_update_latents: Calculate G loss with new latent codes. Defaults to ``True``.
      iteration_update: the callable function for every iteration, expect to accept `engine`
          and `engine.state.batch` as inputs, return data will be stored in `engine.state.output`.
          if not provided, use `self._iteration()` instead. for more details please refer to:
          https://pytorch.org/ignite/generated/ignite.engine.engine.Engine.html.
      postprocessing: execute additional transformation for the model output data.
          Typically, several Tensor based transforms composed by `Compose`.
      key_train_metric: compute metric when every iteration completed, and save average value to
          engine.state.metrics when epoch completed. key_train_metric is the main metric to compare and save the
          checkpoint into files.
      additional_metrics: more Ignite metrics that also attach to Ignite Engine.
      metric_cmp_fn: function to compare current key metric with previous best key metric value,
          it must accept 2 args (current_metric, previous_best) and return a bool result: if `True`, will update
          `best_metric` and `best_metric_epoch` with current metric and epoch, default to `greater than`.
      train_handlers: every handler is a set of Ignite Event-Handlers, must have `attach` function, like:
          CheckpointHandler, StatsHandler, etc.
      decollate: whether to decollate the batch-first data to a list of data after model computation,
          recommend `decollate=True` when `postprocessing` uses components from `monai.transforms`.
          default to `True`.
      optim_set_to_none: when calling `optimizer.zero_grad()`, instead of setting to zero, set the grads to None.
          more details: https://pytorch.org/docs/stable/generated/torch.optim.Optimizer.zero_grad.html.
      to_kwargs: dict of other args for `prepare_batch` API when converting the input data, except for
          `device`, `non_blocking`.
      amp_kwargs: dict of the args for `torch.cuda.amp.autocast()` API, for more details:
          https://pytorch.org/docs/stable/amp.html#torch.cuda.amp.autocast.
docstr: Callback function for Adversarial Training processing logic of 1 iteration in Ignite Engine.
  
  Args:
      engine: `GanTrainer` to execute operation for an iteration.
      batchdata: input data for this iteration, usually can be dictionary or tuple of Tensor data.
  
  Raises:
      ValueError: must provide batch data for current iteration.
docstr_tok: ["Callback","function","for","Adversarial","Training","processing","logic","of","1","iteration","in","Ignite","Engine",".","Args",":","engine",":","`","GanTrainer","`","to","execute","operation","for","an","iteration",".","batchdata",":","input","data","for","this","iteration",",","usually","can","be","dictionary","or","tuple","of","Tensor","data",".","Raises",":","ValueError",":","must","provide","batch","data","for","current","iteration","."]
code: def _iteration(
      self, engine: GanTrainer, batchdata: dict | Sequence
  ) -> dict[str, torch.Tensor | int | float | bool]:
      """
      Callback function for Adversarial Training processing logic of 1 iteration in Ignite Engine.
  
      Args:
          engine: `GanTrainer` to execute operation for an iteration.
          batchdata: input data for this iteration, usually can be dictionary or tuple of Tensor data.
  
      Raises:
          ValueError: must provide batch data for current iteration.
  
      """
      if batchdata is None:
          raise ValueError(
              "must provide batch data for current iteration."
          )
  
      d_input = engine.prepare_batch(
          batchdata,
          engine.state.device,
          engine.non_blocking,
          **engine.to_kwargs,
      )
      batch_size = engine.data_loader.batch_size  # type: ignore
      g_input = engine.g_prepare_batch(
          num_latents=batch_size,
          latent_size=engine.latent_shape,
          device=engine.state.device,
          non_blocking=engine.non_blocking,
          **engine.to_kwargs,
      )
      g_output = engine.g_inferer(g_input, engine.g_network)
  
      # Train Discriminator
      d_total_loss = torch.zeros(1)
      for _ in range(engine.d_train_steps):
          engine.d_optimizer.zero_grad(
              set_to_none=engine.optim_set_to_none
          )
          dloss = engine.d_loss_function(g_output, d_input)
          dloss.backward()
          engine.d_optimizer.step()
          d_total_loss += dloss.item()
  
      # Train Generator
      if engine.g_update_latents:
          g_input = engine.g_prepare_batch(
              num_latents=batch_size,
              latent_size=engine.latent_shape,
              device=engine.state.device,
              non_blocking=engine.non_blocking,
              **engine.to_kwargs,
          )
      g_output = engine.g_inferer(g_input, engine.g_network)
      engine.g_optimizer.zero_grad(set_to_none=engine.optim_set_to_none)
      g_loss = engine.g_loss_function(g_output)
      g_loss.backward()
      engine.g_optimizer.step()
  
      return {
          GanKeys.REALS: d_input,
          GanKeys.FAKES: g_output,
          GanKeys.LATENTS: g_input,
          GanKeys.GLOSS: g_loss.item(),
          GanKeys.DLOSS: d_total_loss.item(),
      }
  
imports: from __future__ import annotations
  from typing import TYPE_CHECKING, Any, Callable, Iterable, Sequence
  import torch
  from torch.optim.optimizer import Optimizer
  from torch.utils.data import DataLoader
  from monai.config import IgniteInfo
  from monai.engines.utils import IterationEvents, default_make_latent, default_metric_cmp_fn, default_prepare_batch
  from monai.engines.workflow import Workflow
  from monai.inferers import Inferer, SimpleInferer
  from monai.transforms import Transform
  from monai.utils import GanKeys, min_version, optional_import
  from monai.utils.enums import CommonKeys
  from monai.utils.enums import EngineStatsKeys
label_desc: Use image node_id 2 for calling the GanTrainer obj's underlying member method code with example usage: obj._iteration(engine, batchdata) and returns: dict