code: def _test_every_event_filter_with_engine(device="cpu"):
      data = torch.rand(100, 4, device=device)
  
      def _test(event_name, event_attr, every, true_num_calls):
          engine = Engine(lambda e, b: b)
  
          counter = [0]
          counter_every = [0]
          num_calls = [0]
  
          @engine.on(event_name(every=every))
          def assert_every(engine):
              counter_every[0] += every
              assert getattr(engine.state, event_attr) % every == 0
              assert counter_every[0] == getattr(
                  engine.state, event_attr
              )
              num_calls[0] += 1
  
          @engine.on(event_name(every=every))
          def assert_every_no_engine():
              assert getattr(engine.state, event_attr) % every == 0
              assert counter_every[0] == getattr(
                  engine.state, event_attr
              )
  
          @engine.on(event_name)
          def assert_(engine):
              counter[0] += 1
              assert getattr(engine.state, event_attr) == counter[0]
  
          @engine.on(event_name)
          def assert_no_engine():
              assert getattr(engine.state, event_attr) == counter[0]
  
          engine.run(data, max_epochs=5)
  
          assert num_calls[0] == true_num_calls
  
      _test(Events.ITERATION_STARTED, "iteration", 10, 100 * 5 // 10)
      _test(Events.ITERATION_COMPLETED, "iteration", 10, 100 * 5 // 10)
      _test(Events.EPOCH_STARTED, "epoch", 2, 5 // 2)
      _test(Events.EPOCH_COMPLETED, "epoch", 2, 5 // 2)
  
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 10 for calling a global function with example usage: _test_every_event_filter_with_engine(device) without return types