code: def test_custom_callable_events_with_engine():
      class CustomEvents(EventEnum):
          TEST_EVENT = "test_event"
  
      event_to_attr = {CustomEvents.TEST_EVENT: "test_event"}
  
      special_events = [1, 2, 5, 7, 17, 20]
  
      def custom_event_filter(engine, event):
          if event in special_events:
              return True
          return False
  
      def _test(event_name, event_attr, true_num_calls):
          def update_fn(engine, batch):
              engine.state.test_event = engine.state.iteration
              engine.fire_event(CustomEvents.TEST_EVENT)
  
          engine = Engine(update_fn)
          engine.register_events(
              *CustomEvents, event_to_attr=event_to_attr
          )
  
          num_calls = [0]
  
          @engine.on(event_name(event_filter=custom_event_filter))
          def assert_on_special_event(engine):
              assert getattr(
                  engine.state, event_attr
              ) == special_events.pop(0)
              num_calls[0] += 1
  
          d = list(range(50))
          engine.run(d, max_epochs=25)
  
          assert num_calls[0] == true_num_calls
  
      _test(CustomEvents.TEST_EVENT, "test_event", len(special_events))
  
imports: from enum import Enum
  from unittest.mock import MagicMock
  import pytest
  import torch
  import ignite.distributed
  from ignite.engine import Engine, Events
  from ignite.engine.events import CallableEventWithFilter, EventEnum, EventsList
label_desc: Use image node_id 20 for calling a global function with example usage: test_custom_callable_events_with_engine() and returns: False, True