code: def test_sha_max_iter_and_metadata(n, r):
      # This test makes sure the number of partial fit calls is preserved
      # when
  
      # * n_initial_parameters and max_iter are specified
      # * n_initial_parameters is specified (but max_iter isn't)
      # * max_iter is specified (but n_initial_parameters isn't)
  
      # n_initial_parameters and max_iter are chosen to make sure the
      # successivehalving works as expected
      # (so only one model is obtained at the end, as per the last assert)
  
      @gen_cluster(client=True)
      async def _test_sha_max_iter(c, s, a, b):
          model = SGDClassifier(tol=1e-3)
          params = {"alpha": np.logspace(-3, 0, num=1000)}
          search = SuccessiveHalvingSearchCV(
              model, params, n_initial_parameters=n, n_initial_iter=r
          )
  
          X, y = make_classification()
          await search.fit(X, y, classes=np.unique(y))
  
          calls = set(search.cv_results_["partial_fit_calls"]) - {1}
          assert min(calls) == r
  
          # One model trained to completion
          assert (
              search.cv_results_["partial_fit_calls"] == max(calls)
          ).sum() < search.aggressiveness
  
          assert search.metadata == search.metadata_
          assert set(search.metadata.keys()) == {
              "partial_fit_calls",
              "n_models",
              "max_iter",
          }
  
      _test_sha_max_iter()
  
file_path: dask-ml/tests/model_selection/test_successive_halving.py
imports: import numpy
  import pytest
  from distributed.utils_test import gen_cluster
  from sklearn.datasets import make_classification
  from sklearn.linear_model import SGDClassifier
  from dask_ml._compat import DISTRIBUTED_2_5_0
  from dask_ml.model_selection import SuccessiveHalvingSearchCV
  from dask_ml.utils import ConstantFunction
label_desc: Use image node_id 1 for calling a global function with example usage: test_sha_max_iter_and_metadata(n, r) without return types