code: def test_with_terminate_on_nan():
      torch.manual_seed(12)
  
      data = [
          1.0,
          0.8,
          (torch.rand(4, 4), torch.rand(4, 4)),
          torch.rand(5),
          torch.asin(torch.randn(4, 4)),
          0.0,
          1.0,
      ]
  
      def update_fn(engine, batch):
          return batch
  
      trainer = Engine(update_fn)
      h = TerminateOnNan()
      trainer.add_event_handler(Events.ITERATION_COMPLETED, h)
  
      trainer.run(data, max_epochs=2)
      assert trainer.state.iteration == 5
  
file_path: ignite/tests/ignite/handlers/test_terminate_on_nan.py
imports: import numpy
  import pytest
  import torch
  from ignite.engine import Engine, Events, State
  from ignite.handlers import TerminateOnNan
label_desc: Use image node_id 2 for calling a global function with example usage: test_with_terminate_on_nan() and returns: batch