code: def test_pbt():
      parameters = [sherpa.Continuous(name="param_a", range=[0, 1])]
  
      algorithm = sherpa.algorithms.PopulationBasedTraining(
          num_generations=3,
          population_size=20,
          parameter_range={"param_a": [0.0, 1.2]},
      )
  
      study = sherpa.Study(
          parameters=parameters,
          algorithm=algorithm,
          lower_is_better=True,
          disable_dashboard=True,
      )
  
      for _ in range(20):
          trial = study.get_suggestion()
          print("Trial-ID={}".format(trial.id))
          print(trial.parameters)
          print()
          study.add_observation(
              trial=trial, iteration=1, objective=trial.id
          )
          study.finalize(trial=trial, status="COMPLETED")
  
      for _ in range(16):
          trial = study.get_suggestion()
          print("Trial-ID={}".format(trial.id))
          print(trial.parameters)
          print()
          parent_param = study.results.loc[
              study.results["Trial-ID"]
              == int(trial.parameters["load_from"])
          ]["param_a"].iloc[0]
          print(parent_param)
          assert trial.parameters["param_a"] == parent_param
          assert trial.parameters["load_from"] == str(trial.id - 20)
          study.add_observation(
              trial=trial, iteration=1, objective=trial.id
          )
          study.finalize(trial=trial, status="COMPLETED")
  
      for _ in range(4):
          trial = study.get_suggestion()
          print("Trial-ID={}".format(trial.id))
          print(trial.parameters)
          print()
          parent_param = study.results.loc[
              study.results["Trial-ID"]
              == int(trial.parameters["load_from"])
          ]["param_a"].iloc[0]
          print(parent_param)
          assert (
              trial.parameters["param_a"] == 0.8 * parent_param
              or trial.parameters["param_a"] == 1.0 * parent_param
              or trial.parameters["param_a"] == 1.2 * parent_param
              or trial.parameters["param_a"] == 0.0
              or trial.parameters["param_a"] == 1.2
          )
          assert int(trial.parameters["load_from"]) in [1, 2, 3, 4]
          study.add_observation(
              trial=trial, iteration=1, objective=trial.id
          )
          study.finalize(trial=trial, status="COMPLETED")
  
      for _ in range(16):
          trial = study.get_suggestion()
          print("Trial-ID={}".format(trial.id))
          print(trial.parameters)
          print()
          parent_param = study.results.loc[
              study.results["Trial-ID"]
              == int(trial.parameters["load_from"])
          ]["param_a"].iloc[0]
          print(parent_param)
          assert trial.parameters["param_a"] == parent_param
          assert trial.parameters["load_from"] == str(trial.id - 20)
          study.add_observation(
              trial=trial, iteration=1, objective=trial.id
          )
          study.finalize(trial=trial, status="COMPLETED")
  
      for _ in range(4):
          trial = study.get_suggestion()
          print("Trial-ID={}".format(trial.id))
          print(trial.parameters)
          print()
          parent_param = study.results.loc[
              study.results["Trial-ID"]
              == int(trial.parameters["load_from"])
          ]["param_a"].iloc[0]
          print(parent_param)
          assert (
              trial.parameters["param_a"] == 0.8 * parent_param
              or trial.parameters["param_a"] == 1.0 * parent_param
              or trial.parameters["param_a"] == 1.2 * parent_param
              or trial.parameters["param_a"] == 0.0
              or trial.parameters["param_a"] == 1.2
          )
          assert int(trial.parameters["load_from"]) in list(
              range(1, 9)
          ) + list(range(21, 29))
          study.add_observation(
              trial=trial, iteration=1, objective=trial.id
          )
          study.finalize(trial=trial, status="COMPLETED")
  
      assert study.get_suggestion() == sherpa.AlgorithmState.DONE
  
imports: from __future__ import absolute_import
  import collections
  import pandas
  import numpy
  import sherpa
  import logging
  import itertools
  import pytest
  from testing_utils import *
label_desc: Use image node_id 7 for calling a global function with example usage: test_pbt() without return types