code: def test_pbar_with_nan_input():
      def update(engine, batch):
          x = batch
          return x.item()
  
      def create_engine():
          engine = Engine(update)
          pbar = ProgressBar()
  
          engine.add_event_handler(
              Events.ITERATION_COMPLETED, TerminateOnNan()
          )
          pbar.attach(
              engine,
              event_name=Events.EPOCH_COMPLETED,
              closing_event_name=Events.COMPLETED,
          )
          return engine
  
      data = torch.from_numpy(np.array([np.nan] * 25))
      engine = create_engine()
      engine.run(data)
      assert engine.should_terminate
      assert engine.state.iteration == 1
      assert engine.state.epoch == 1
  
      data = torch.from_numpy(np.array([1] * 1000 + [np.nan] * 25))
      engine = create_engine()
      engine.run(data)
      assert engine.should_terminate
      assert engine.state.iteration == 1001
      assert engine.state.epoch == 1
  
imports: import sys
  import time
  from argparse import Namespace
  from unittest.mock import patch
  import numpy
  import pytest
  import torch
  from packaging.version import Version
  from ignite.contrib.handlers import ProgressBar
  from ignite.engine import Engine, Events
  from ignite.handlers import TerminateOnNan
  from ignite.metrics import RunningAverage
label_desc: Use image node_id 25 for calling a global function with example usage: test_pbar_with_nan_input() and returns: x, engine