code: def grid_ft_resume(
      train, grid_id, params, hyper_parameters, start_grid
  ):
      print("TESTING %s\n-------------------" % grid_id)
      export_dir = tempfile.mkdtemp()
      print("Using directory %s" % export_dir)
      grid_size = 1
      for p in hyper_parameters:
          grid_size *= len(hyper_parameters[p])
      print("Grid size %d" % grid_size)
      print("Starting baseline grid")
      grid = start_grid(
          grid_id, export_dir, train, params, hyper_parameters
      )
      grid_in_progress = None
      times_waited = 0
      while (times_waited < 3000) and (
          grid_in_progress is None
          or len(grid_in_progress.model_ids) == 0
      ):
          time.sleep(0.1)  # give it tome to train some models
          times_waited += 1
          try:
              grid_in_progress = h2o.get_grid(grid_id)
          except IndexError:
              if times_waited % 100 == 0:
                  print(
                      "no models trained yet after %ss"
                      % (times_waited / 10)
                  )
      grid.cancel()
  
      grid = h2o.get_grid(grid_id)
      old_grid_model_count = len(grid.model_ids)
      print("Baseline grid has %d models:" % old_grid_model_count)
      assert (
          old_grid_model_count < grid_size
      ), "The full grid should not have finished yet."
      for x in sorted(grid.model_ids):
          print(x)
      h2o.remove_all()
  
      loaded = h2o.load_grid(
          "%s/%s" % (export_dir, grid_id), load_params_references=True
      )
      assert loaded is not None
      assert len(grid.model_ids) == old_grid_model_count
      loaded_train = h2o.H2OFrame.get_frame(train.frame_id)
      assert loaded_train is not None, "Train frame was not loaded"
      print("Starting final grid")
      loaded.resume()
      print("Newly grained grid has %d models:" % len(loaded.model_ids))
      for x in sorted(loaded.model_ids):
          print(x)
      assert (
          len(loaded.model_ids) == grid_size
      ), "The full grid was not trained."
      h2o.remove_all()
  
imports: import sys
  import os
  import tempfile
  import time
  import numpy
  import h2o
  from tests import pyunit_utils
  from h2o.grid.grid_search import H2OGridSearch
  from h2o.estimators.deeplearning import H2OAutoEncoderEstimator
  from h2o.estimators.deeplearning import H2ODeepLearningEstimator
  from h2o.estimators.gbm import H2OGradientBoostingEstimator
  from h2o.estimators.glm import H2OGeneralizedLinearEstimator
  from h2o.estimators.glrm import H2OGeneralizedLowRankEstimator
  from h2o.estimators.kmeans import H2OKMeansEstimator
  from h2o.estimators.xgboost import H2OXGBoostEstimator
label_desc: Use image node_id 18 for calling a global function with example usage: grid_ft_resume(train, grid_id, params, hyper_parameters, start_grid) without return types