code: def test_exhaust_trials_in_between_before_the_latter_finishes(
      tmp_path,
  ):
      class MyHyperModel(hypermodel.HyperModel):
          def build(self, hp):
              hp.Boolean("bool")
              return keras.Sequential()
  
          def fit(self, hp, model, *args, **kwargs):
              hp.Boolean("bool2")
              return random.random()
  
      tuner = gridsearch.GridSearch(
          hypermodel=MyHyperModel(), directory=tmp_path
      )
      oracle = tuner.oracle
  
      def run(trial):
          hp = trial.hyperparameters
          hm = MyHyperModel()
          hm.fit(hp, hm.build(hp))
          oracle.update_space(hp)
  
      def end_trial(trial):
          run(trial)
          oracle.update_trial(
              trial_id=trial.trial_id,
              metrics={oracle.objective.name: random.random()},
          )
          trial.status = trial_module.TrialStatus.COMPLETED
          oracle.end_trial(trial)
  
      trial_1 = oracle.create_trial(tuner_id="1")
      assert trial_1.status == trial_module.TrialStatus.RUNNING
      trial_2 = oracle.create_trial(tuner_id="2")
      assert trial_2.status == trial_module.TrialStatus.RUNNING
  
      # Iterated bool1, bool2 not discovered yet. So idle.
      trial_3 = oracle.create_trial(tuner_id="3")
      assert trial_3.status == trial_module.TrialStatus.IDLE
  
      end_trial(trial_1)
      # Discovered bool2 in trial_1, so new value of bool2 for trial_3 after
      # trial_1.
      trial_3 = oracle.create_trial(tuner_id="3")
      assert trial_3.status == trial_module.TrialStatus.RUNNING
      # Exhausted all possible combinations whose order is between trial_1 and
      # trial_2.  So idle.
      trial_4 = oracle.create_trial(tuner_id="4")
      assert trial_4.status == trial_module.TrialStatus.IDLE
  
      end_trial(trial_2)
      # New value of bool2 for trial_4 after trial_2.
      trial_4 = oracle.create_trial(tuner_id="4")
      assert trial_4.status == trial_module.TrialStatus.RUNNING
      trial_5 = oracle.create_trial(tuner_id="5")
      assert trial_5.status == trial_module.TrialStatus.IDLE
  
      end_trial(trial_3)
      end_trial(trial_4)
      trial_5 = oracle.create_trial(tuner_id="5")
      assert trial_5.status == trial_module.TrialStatus.STOPPED
  
file_path: keras-tuner/keras_tuner/tuners/gridsearch_test.py
imports: import random
  from keras_tuner.backend import keras
  from keras_tuner.engine import hypermodel
  from keras_tuner.engine import trial
  from keras_tuner.tuners import gridsearch
label_desc: Use image node_id 6 for calling a global function with example usage: test_exhaust_trials_in_between_before_the_latter_finishes(tmp_path) and returns: keras, random