code: def test_automl_early_stopping_callback(tmpdir):
      # Given
      cx = AutoMLContext.from_context(CX(tmpdir))
      n_epochs = 10
      max_epochs_without_improvement = 3
      auto_ml = AutoML(
          pipeline=Pipeline(
              [
                  MultiplyByN(2).set_hyperparams_space(
                      HyperparameterSpace(
                          {"multiply_by": FixedHyperparameter(2)}
                      )
                  ),
                  NumpyReshape(new_shape=(-1, 1)),
              ]
          ),
          hyperparams_optimizer=RandomSearchSampler(),
          validation_splitter=ValidationSplitter(0.20),
          scoring_callback=ScoringCallback(
              mean_squared_error, higher_score_is_better=False
          ),
          callbacks=[
              MetricCallback(
                  "mse",
                  metric_function=mean_squared_error,
                  higher_score_is_better=False,
              ),
              EarlyStoppingCallback(max_epochs_without_improvement),
          ],
          n_trials=1,
          refit_best_trial=True,
          epochs=n_epochs,
          continue_loop_on_error=False,
      )
  
      # When
      data_inputs = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
      expected_outputs = data_inputs * 2
      auto_ml.handle_fit(
          DACT(
              data_inputs=data_inputs, expected_outputs=expected_outputs
          ),
          cx,
      )
  
      # Then
      round_report: RoundReport = auto_ml.report
      trial: TrialReport = round_report.get_best_trial()
      assert len(trial) == 1
      validation_scores = trial.get_avg_validation_score(
          "mse", over_time=True
      )
      nepochs_executed = len(validation_scores)
      assert nepochs_executed == max_epochs_without_improvement + 1
  
imports: import numpy
  import pytest
  from neuraxle.base import ExecutionContext
  from neuraxle.data_container import DataContainer
  from neuraxle.hyperparams.distributions import FixedHyperparameter, RandInt
  from neuraxle.hyperparams.space import HyperparameterSpace
  from neuraxle.metaopt.auto_ml import AutoML, ControlledAutoML, Trainer
  from neuraxle.metaopt.callbacks import BestModelCheckpoint, EarlyStoppingCallback, MetricCallback, ScoringCallback
  from neuraxle.metaopt.context import AutoMLContext
  from neuraxle.metaopt.data.aggregates import Trial
  from neuraxle.metaopt.data.reporting import RoundReport, TrialReport
  from neuraxle.metaopt.optimizer import GridExplorationSampler, RandomSearchSampler
  from neuraxle.metaopt.validation import KFoldCrossValidationSplitter, ValidationSplitter
  from neuraxle.pipeline import Pipeline
  from neuraxle.steps.flow import ChooseStepElseIdentity
  from neuraxle.steps.numpy import MultiplyByN, NumpyReshape
  from neuraxle.steps.sklearn import SKLearnWrapper
  from sklearn import linear_model
  from sklearn.exceptions import ConvergenceWarning
  from sklearn.metrics import mean_squared_error
  from sklearn.svm import LinearSVC
  from sklearn.utils._testing import ignore_warnings
label_desc: Use image node_id 1 for calling a global function with example usage: test_automl_early_stopping_callback(tmpdir) without return types