code: def sample_trpo_params(trial: optuna.Trial) -> dict[str, Any]:
      """
      Sampler for TRPO hyperparams.
  
      :param trial:
      :return:
      """
      batch_size = trial.suggest_categorical(
          "batch_size", [8, 16, 32, 64, 128, 256, 512]
      )
      n_steps = trial.suggest_categorical(
          "n_steps", [8, 16, 32, 64, 128, 256, 512, 1024, 2048]
      )
      gamma = trial.suggest_categorical(
          "gamma", [0.9, 0.95, 0.98, 0.99, 0.995, 0.999, 0.9999]
      )
      learning_rate = trial.suggest_loguniform("learning_rate", 1e-5, 1)
      lr_schedule = "constant"
      # Uncomment to enable learning rate schedule
      # lr_schedule = trial.suggest_categorical('lr_schedule', ['linear', 'constant'])
      # line_search_shrinking_factor = trial.suggest_categorical("line_search_shrinking_factor", [0.6, 0.7, 0.8, 0.9])
      n_critic_updates = trial.suggest_categorical(
          "n_critic_updates", [5, 10, 20, 25, 30]
      )
      cg_max_steps = trial.suggest_categorical(
          "cg_max_steps", [5, 10, 20, 25, 30]
      )
      # cg_damping = trial.suggest_categorical("cg_damping", [0.5, 0.2, 0.1, 0.05, 0.01])
      target_kl = trial.suggest_categorical(
          "target_kl", [0.1, 0.05, 0.03, 0.02, 0.01, 0.005, 0.001]
      )
      gae_lambda = trial.suggest_categorical(
          "gae_lambda", [0.8, 0.9, 0.92, 0.95, 0.98, 0.99, 1.0]
      )
      net_arch = trial.suggest_categorical(
          "net_arch", ["small", "medium"]
      )
      # Uncomment for gSDE (continuous actions)
      # log_std_init = trial.suggest_uniform("log_std_init", -4, 1)
      # Uncomment for gSDE (continuous action)
      # sde_sample_freq = trial.suggest_categorical("sde_sample_freq", [-1, 8, 16, 32, 64, 128, 256])
      # Orthogonal initialization
      ortho_init = False
      # ortho_init = trial.suggest_categorical('ortho_init', [False, True])
      # activation_fn = trial.suggest_categorical('activation_fn', ['tanh', 'relu', 'elu', 'leaky_relu'])
      activation_fn = trial.suggest_categorical(
          "activation_fn", ["tanh", "relu"]
      )
  
      # TODO: account when using multiple envs
      if batch_size > n_steps:
          batch_size = n_steps
  
      if lr_schedule == "linear":
          learning_rate = linear_schedule(learning_rate)
  
      # Independent networks usually work best
      # when not working with images
      net_arch = {
          "small": [dict(pi=[64, 64], vf=[64, 64])],
          "medium": [dict(pi=[256, 256], vf=[256, 256])],
      }[net_arch]
  
      activation_fn = {
          "tanh": nn.Tanh,
          "relu": nn.ReLU,
          "elu": nn.ELU,
          "leaky_relu": nn.LeakyReLU,
      }[activation_fn]
  
      return {
          "n_steps": n_steps,
          "batch_size": batch_size,
          "gamma": gamma,
          # "cg_damping": cg_damping,
          "cg_max_steps": cg_max_steps,
          # "line_search_shrinking_factor": line_search_shrinking_factor,
          "n_critic_updates": n_critic_updates,
          "target_kl": target_kl,
          "learning_rate": learning_rate,
          "gae_lambda": gae_lambda,
          # "sde_sample_freq": sde_sample_freq,
          "policy_kwargs": dict(
              # log_std_init=log_std_init,
              net_arch=net_arch,
              activation_fn=activation_fn,
              ortho_init=ortho_init,
          ),
      }
  
file_path: FinRL/finrl/agents/stablebaselines3/hyperparams_opt.py
imports: from __future__ import annotations
  from typing import Any
  from typing import Dict
  import numpy
  import optuna
  from stable_baselines3.common.noise import NormalActionNoise
  from stable_baselines3.common.noise import OrnsteinUhlenbeckActionNoise
  from torch import nn
  from utils import linear_schedule
label_desc: Use image node_id 2 for calling a global function with example usage: sample_trpo_params(trial) and returns: dict