class_docstr: Phoenix: A smart search AutoML algorithm.
class_docstr_tok: ["Phoenix",":","A","smart","search","AutoML","algorithm","."]
docstr: Gets the Phoenix search space as keras Hyperparameters object.
docstr_tok: ["Gets","the","Phoenix","search","space","as","keras","Hyperparameters","object","."]
code: def get_keras_hyperparameters_space(phoenix_spec, train_steps):
      """Gets the Phoenix search space as keras Hyperparameters object."""
      hp_space = keras_tuner.HyperParameters()
      hp_space.merge(
          architecture_utils.get_blocks_search_space(
              phoenix_spec.blocks_to_use
          )
      )
      hp_space.Float("learning_rate", 1e-6, 0.01, sampling="log")
      hp_space.Choice("new_block_type", phoenix_spec.blocks_to_use)
  
      # Try different optimizers.
      hp_space.Choice(
          "optimizer", ["momentum", "sgd", "adagrad", "adam", "rmsprop"]
      )
  
      # Search for the best tower of depth phoenix_spec.minimum_depth
      # Used for initial structure (before evolution + going deeper).
      for i in range(phoenix_spec.minimum_depth):
          hp_space.Choice(
              "initial_architecture_{}".format(i),
              phoenix_spec.blocks_to_use,
          )
  
      learning_spec = phoenix_spec.learning_spec
  
      # Exponential decay.
      if learning_spec.apply_exponential_decay:
          hp_space.Float(
              "exponential_decay_rate",
              learning_spec.min_learning_rate_decay_rate,
              learning_spec.max_learning_rate_decay_rate,
          )
          decay_steps = [
              train_steps // i
              for i in range(
                  learning_spec.min_decay_times,
                  learning_spec.max_decay_times,
              )
          ]
          seen = set()
          unique_decay_steps = [
              x for x in decay_steps if not (x in seen or seen.add(x))
          ]
          hp_space.Choice("exponential_decay_steps", unique_decay_steps)
  
      # Gradient clipping
      if learning_spec.apply_gradient_clipping:
          hp_space.Int(
              "gradient_max_norm",
              learning_spec.min_gradient_norm_when_clipping,
              learning_spec.max_gradient_norm_when_clipping,
          )
  
      # L2 regularization
      if learning_spec.apply_l2_regularization:
          hp_space.Float(
              "l2_regularization",
              learning_spec.min_l2_regularization,
              learning_spec.max_l2_regularization,
          )
  
      # Apply dropout between blocks. Here -1 wouldn't apply any dropouts.
      if phoenix_spec.apply_dropouts_between_blocks:
          assert learning_spec.min_dropout < learning_spec.max_dropout
          step = (
              learning_spec.max_dropout - learning_spec.min_dropout
          ) / 10
          dropout = np.arange(
              learning_spec.min_dropout, learning_spec.max_dropout, step
          )
          hp_space.Choice("dropout_rate", [-1.0] + dropout.tolist())
  
      return hp_space
  
imports: import functools
  import inspect
  from absl import logging
  import keras_tuner
  from model_search import controller
  from model_search import hparam
  from model_search import loss_fns
  from model_search import metric_fns
  from model_search import task_manager
  from model_search.architecture import architecture_utils
  from model_search.generators import base_tower_generator
  from model_search.generators import trial_utils
  from model_search.meta import transfer_learning
  from model_search.metadata import ml_metadata_db
  from model_search.proto import phoenix_spec_pb2
  from model_search.proto import transfer_learning_spec_pb2
  import numpy
  import tensorflow.compat.v2
label_desc: Use image node_id 9 for calling the Phoenix obj's underlying member method code with example usage: obj.get_keras_hyperparameters_space(phoenix_spec, train_steps) and returns: hp_space