code: def define_by_run_func(trial) -> Optional[Dict[str, Any]]:
      """Define-by-run function to create the search space.
  
      Ensure no actual computation takes place here. That should go into
      the trainable passed to ``Tuner`` (in this example, that's
      ``easy_objective``).
  
      For more information, see https://optuna.readthedocs.io/en/stable\
  /tutorial/10_key_features/002_configurations.html
  
      This function should either return None or a dict with constant values.
      """
      # This param is not used in the objective function.
      activation = trial.suggest_categorical(
          "activation", ["relu", "tanh"]
      )
      trial.suggest_float("width", 0, 20)
      trial.suggest_float("height", -100, 100)
  
      # Define-by-run allows for conditional search spaces.
      if activation == "relu":
          trial.suggest_float("mult", 1, 2)
  
      # Return all constants in a dictionary.
      return {"steps": 100}
  
file_path: ray/python/ray/tune/examples/optuna_define_by_run_example.py
imports: import time
  from typing import Dict, Optional, Any
  import ray
  from ray import train, tune
  from ray.tune.search import ConcurrencyLimiter
  from ray.tune.schedulers import AsyncHyperBandScheduler
  from ray.tune.search.optuna import OptunaSearch
label_desc: Use image node_id 3 for calling a global function with example usage: define_by_run_func(trial) and returns: dict