code: def test_with_engine_early_stopping_on_plateau():
      class Counter(object):
          def __init__(self, count=0):
              self.count = count
  
      n_epochs_counter = Counter()
  
      def score_function(engine):
          return 0.047
  
      trainer = Engine(do_nothing_update_fn)
      evaluator = Engine(do_nothing_update_fn)
      early_stopping = EarlyStopping(
          patience=4, score_function=score_function, trainer=trainer
      )
  
      @trainer.on(Events.EPOCH_COMPLETED)
      def evaluation(engine):
          evaluator.run([0])
          n_epochs_counter.count += 1
  
      evaluator.add_event_handler(Events.COMPLETED, early_stopping)
      trainer.run([0], max_epochs=10)
      assert n_epochs_counter.count == 5
      assert trainer.state.epoch == 5
  
imports: import os
  import pytest
  import torch
  import ignite.distributed
  from ignite.engine import Engine, Events
  from ignite.handlers import EarlyStopping
label_desc: Use image node_id 11 for calling a global function with example usage: test_with_engine_early_stopping_on_plateau() and returns: int