class_docstr: Log statistics writer implementation for Tensorboard.
  :param log_dir: log_dir for TensorBoard
  :param tensorboard_render_figure: Indicates whether to visualize the actions taken in TensorBoard.
class_docstr_tok: ["Log","statistics","writer","implementation","for","Tensorboard",".",":","param","log_dir",":","log_dir","for","TensorBoard",":","param","tensorboard_render_figure",":","Indicates","whether","to","visualize","the","actions","taken","in","TensorBoard","."]
docstr: LogStatsWriter.write implementation
docstr_tok: ["LogStatsWriter.write","implementation"]
code: def write(self, path: str, step: int, stats: LogStats) -> None:
      """LogStatsWriter.write implementation"""
  
      # Create custom figures for TensorBoard visualization
      # ===================================================
      if self.tensorboard_render_figure:
          for (event, name, groups), value in stats.items():
              tag = self._event_to_tag(event, name, groups)
              if path:
                  tag = path.replace("/", "_") + "_" + tag
  
              # get plotting function from the event definition
              render_figure_dict = getattr(
                  event, "tensorboard_render_figure_dict", dict()
              )
              render_figure_function = render_figure_dict.get(
                  name, None
              )
              if render_figure_function:
                  fig = render_figure_function(
                      value, event=event, name=event, groups=groups
                  )
                  self.summary_writer.add_figure(
                      tag=tag, figure=fig, global_step=step
                  )
  
          self.summary_writer.flush()
  
      # Vanilla TensorBoard visualization
      # =================================
      for (event, name, groups), value in stats.items():
          tag = self._event_to_tag(event, name, groups)
          if path:
              tag = path.replace("/", "_") + "_" + tag
  
          # Skip all events that have the attribute "tensorboard_render_figure". Events with this attribute are
          # plotted with an external plotting library and added to TensorBoard manually above.
          if getattr(event, "tensorboard_render_figure_dict", dict()):
              continue
  
          if isinstance(value, List):
              self.summary_writer.add_histogram(
                  tag, np.array(value), step
              )
          elif isinstance(value, numbers.Number):
              self.summary_writer.add_scalar(tag, value, step)
          else:
              # Only lists and scalars are added to TensorBoard
              pass
          self.this_step_tags.add(tag)
  
      self.summary_writer.flush()
  
file_path: maze/maze/core/log_stats/log_stats_writer_tensorboard.py
imports: import logging
  import math
  import numbers
  from typing import Callable, Union, List, Optional
  import numpy
  from torch.utils.tensorboard import SummaryWriter
  from maze.core.annotations import override
  from maze.core.log_stats.log_stats import LogStatsWriter, LogStats, GlobalLogState
label_desc: Use image node_id 2 for calling the LogStatsWriterTensorboard obj's underlying member method code with example usage: obj.write(path, step, stats) without return types