class_docstr: TensorBoardStatsHandler defines a set of Ignite Event-handlers for all the TensorBoard logics.
  It can be used for any Ignite Engine(trainer, validator and evaluator).
  And it can support both epoch level and iteration level with pre-defined TensorBoard event writer.
  The expected data source is Ignite ``engine.state.output`` and ``engine.state.metrics``.
  
  Default behaviors:
      - When EPOCH_COMPLETED, write each dictionary item in
        ``engine.state.metrics`` to TensorBoard.
      - When ITERATION_COMPLETED, write each dictionary item in
        ``self.output_transform(engine.state.output)`` to TensorBoard.
  
  Usage example is available in the tutorial:
  https://github.com/Project-MONAI/tutorials/blob/master/3d_segmentation/unet_segmentation_3d_ignite.ipynb.
class_docstr_tok: ["TensorBoardStatsHandler","defines","a","set","of","Ignite","Event-handlers","for","all","the","TensorBoard","logics",".","It","can","be","used","for","any","Ignite","Engine","(","trainer",",","validator","and","evaluator",")",".","And","it","can","support","both","epoch","level","and","iteration","level","with","pre-defined","TensorBoard","event","writer",".","The","expected","data","source","is","Ignite","``","engine.state.output","``","and","``","engine.state.metrics","``",".","Default","behaviors",":","-","When","EPOCH_COMPLETED",",","write","each","dictionary","item","in","``","engine.state.metrics","``","to","TensorBoard",".","-","When","ITERATION_COMPLETED",",","write","each","dictionary","item","in","``","self.output_transform","(","engine.state.output",")","``","to","TensorBoard",".","Usage","example","is","available","in","the","tutorial",":","https",":","\/\/github.com\/Project-MONAI\/tutorials\/blob\/master\/3d_segmentation\/unet_segmentation_3d_ignite.ipynb","."]
docstr: Execute iteration level event write operation based on Ignite `engine.state.output` data.
  Extract the values from `self.output_transform(engine.state.output)`.
  Since `engine.state.output` is a decollated list and we replicated the loss value for every item
  of the decollated list, the default behavior is to track the loss from `output[0]`.
  
  Args:
      engine: Ignite Engine, it can be a trainer, validator or evaluator.
      writer: TensorBoard  or TensorBoardX writer, passed or created in TensorBoardHandler.
docstr_tok: ["Execute","iteration","level","event","write","operation","based","on","Ignite","`","engine.state.output","`","data",".","Extract","the","values","from","`","self.output_transform","(","engine.state.output",")","`",".","Since","`","engine.state.output","`","is","a","decollated","list","and","we","replicated","the","loss","value","for","every","item","of","the","decollated","list",",","the","default","behavior","is","to","track","the","loss","from","`","output","[","0","]","`",".","Args",":","engine",":","Ignite","Engine",",","it","can","be","a","trainer",",","validator","or","evaluator",".","writer",":","TensorBoard","or","TensorBoardX","writer",",","passed","or","created","in","TensorBoardHandler","."]
code: def _default_iteration_writer(
      self, engine: Engine, writer: SummaryWriter | SummaryWriterX
  ) -> None:
      """
      Execute iteration level event write operation based on Ignite `engine.state.output` data.
      Extract the values from `self.output_transform(engine.state.output)`.
      Since `engine.state.output` is a decollated list and we replicated the loss value for every item
      of the decollated list, the default behavior is to track the loss from `output[0]`.
  
      Args:
          engine: Ignite Engine, it can be a trainer, validator or evaluator.
          writer: TensorBoard  or TensorBoardX writer, passed or created in TensorBoardHandler.
  
      """
      loss = self.output_transform(engine.state.output)
      if loss is None:
          return  # do nothing if output is empty
      if isinstance(loss, dict):
          for name in sorted(loss):
              value = loss[name]
              if not is_scalar(value):
                  warnings.warn(
                      "ignoring non-scalar output in TensorBoardStatsHandler,"
                      " make sure `output_transform(engine.state.output)` returns"
                      " a scalar or dictionary of key and scalar pairs to avoid this warning."
                      " {}:{}".format(name, type(value))
                  )
                  continue  # not plot multi dimensional output
              self._write_scalar(
                  _engine=engine,
                  writer=writer,
                  tag=name,
                  value=value.item()
                  if isinstance(value, torch.Tensor)
                  else value,
                  step=engine.state.iteration,
              )
      elif is_scalar(loss):  # not printing multi dimensional output
          self._write_scalar(
              _engine=engine,
              writer=writer,
              tag=self.tag_name,
              value=loss.item()
              if isinstance(loss, torch.Tensor)
              else loss,
              step=engine.state.iteration,
          )
      else:
          warnings.warn(
              "ignoring non-scalar output in TensorBoardStatsHandler,"
              " make sure `output_transform(engine.state.output)` returns"
              " a scalar or a dictionary of key and scalar pairs to avoid this warning."
              " {}".format(type(loss))
          )
      writer.flush()
  
imports: from __future__ import annotations
  import warnings
  from collections.abc import Callable, Sequence
  from typing import TYPE_CHECKING, Any
  import numpy
  import torch
  from monai.config import IgniteInfo
  from monai.utils import is_scalar, min_version, optional_import
  from monai.visualize import plot_2d_or_3d_image
label_desc: Use image node_id 7 for calling the TensorBoardStatsHandler obj's underlying member method code with example usage: obj._default_iteration_writer(engine, writer) without return types