code: def test_concurrent_evaluation():
      """
      Assume we were evaluating k trials in parallel, so when the first out of
      those k trials is finished there are still k-1 unfinished trials, i.e.
      only one result is available so far and nothing is promotable yet. Then
      we would expect ASHA to add another trial to the bottom rung as a next step.
      """
      parameters = [sherpa.Continuous("myparam", [0, 1])]
  
      algorithm = successive_halving.SuccessiveHalving(
          r=1, R=9, eta=3, s=0, max_finished_configs=1
      )
  
      study = sherpa.Study(
          parameters=parameters,
          algorithm=algorithm,
          lower_is_better=True,
          disable_dashboard=True,
      )
  
      k = 6
      # Submit k trials
      running_trials = collections.deque()
      for _ in range(k):
          trial = study.get_suggestion()
          print(trial.id)
          assert trial.parameters["load_from"] == ""
          assert trial.parameters["rung"] == 0
          assert trial.parameters["save_to"] == str(trial.id)
          running_trials.append(trial)
  
      # First one finishes. Since no other trials have finished a new config
      # is added to the bottom rung
      print("Trial 1 finished")
      trial = running_trials.popleft()
      study.add_observation(
          trial=trial, iteration=1, objective=float(trial.id)
      )
      study.finalize(trial)
      trial = study.get_suggestion()
      assert trial.parameters["load_from"] == ""
      assert trial.parameters["rung"] == 0
      running_trials.append(trial)
  
      # Now two more finish. The first one gets added to the bottom rung, the
      # second one has enough completed configs to promote one to rung 1
      print("Trial 2 finished")
      trial = running_trials.popleft()
      study.add_observation(
          trial=trial, iteration=1, objective=float(trial.id)
      )
      study.finalize(trial)
      trial = study.get_suggestion()
      assert trial.parameters["load_from"] == ""
      assert trial.parameters["rung"] == 0
      running_trials.append(trial)
  
      print("Trial 3 finished")
      trial = running_trials.popleft()
      study.add_observation(
          trial=trial, iteration=1, objective=float(trial.id)
      )
      study.finalize(trial)
      trial = study.get_suggestion()
      assert trial.parameters["load_from"] == "1"
      assert trial.parameters["rung"] == 1
      running_trials.append(trial)
  
      # Now three more finish. Again the first two get added to the bottom rung
      # because there aren't enough completed unpromoted trials to promote one.
      print("Trial 4 finished")
      trial = running_trials.popleft()
      study.add_observation(
          trial=trial, iteration=1, objective=float(trial.id)
      )
      study.finalize(trial)
      trial = study.get_suggestion()
      print(trial.parameters)
      assert trial.parameters["load_from"] == ""
      assert trial.parameters["rung"] == 0
      running_trials.append(trial)
  
      print("Trial 5 finished")
      trial = running_trials.popleft()
      study.add_observation(
          trial=trial, iteration=1, objective=float(trial.id)
      )
      study.finalize(trial)
      trial = study.get_suggestion()
      assert trial.parameters["load_from"] == ""
      assert trial.parameters["rung"] == 0
      running_trials.append(trial)
  
      print("Trial 6 finished")
      trial = running_trials.popleft()
      study.add_observation(
          trial=trial, iteration=1, objective=float(trial.id)
      )
      study.finalize(trial)
      trial = study.get_suggestion()
      assert trial.parameters["load_from"] == "2"
      assert trial.parameters["rung"] == 1
      running_trials.append(trial)
  
file_path: sherpa/tests/test_successive_halving.py
imports: from __future__ import absolute_import
  import collections
  from sherpa.algorithms import successive_halving
  from testing_utils import *
label_desc: Use image node_id 3 for calling a global function with example usage: test_concurrent_evaluation() without return types