code: def test_results_output_bayesian_search_optuna_ForecasterAutoreg_with_mocked_when_kwargs_create_study():
      """
      Test output of _bayesian_search_optuna in ForecasterAutoreg when
      kwargs_create_study with mocked (mocked done in Skforecast v0.4.3).
      """
      forecaster = ForecasterAutoreg(
          regressor=Ridge(random_state=123),
          lags=2,  # Placeholder, the value will be overwritten
      )
  
      steps = 3
      n_validation = 12
      y_train = y[:-n_validation]
      lags_grid = [4, 2]
  
      def search_space(trial):
          search_space = {
              "alpha": trial.suggest_float("alpha", 1e-2, 1.0)
          }
  
          return search_space
  
      # kwargs_create_study
      sampler = TPESampler(
          seed=123, prior_weight=2.0, consider_magic_clip=False
      )
  
      results = _bayesian_search_optuna(
          forecaster=forecaster,
          y=y,
          lags_grid=lags_grid,
          search_space=search_space,
          steps=steps,
          metric="mean_absolute_error",
          refit=True,
          initial_train_size=len(y_train),
          fixed_train_size=True,
          n_trials=10,
          random_state=123,
          return_best=False,
          verbose=False,
          kwargs_create_study={"sampler": sampler},
      )[0]
  
      expected_results = pd.DataFrame(
          {
              "lags": [
                  [1, 2, 3, 4],
                  [1, 2, 3, 4],
                  [1, 2, 3, 4],
                  [1, 2, 3, 4],
                  [1, 2, 3, 4],
                  [1, 2, 3, 4],
                  [1, 2, 3, 4],
                  [1, 2, 3, 4],
                  [1, 2, 3, 4],
                  [1, 2, 3, 4],
                  [1, 2],
                  [1, 2],
                  [1, 2],
                  [1, 2],
                  [1, 2],
                  [1, 2],
                  [1, 2],
                  [1, 2],
                  [1, 2],
                  [1, 2],
              ],
              "params": [
                  {"alpha": 0.6995044937418831},
                  {"alpha": 0.29327794160087567},
                  {"alpha": 0.2345829390285611},
                  {"alpha": 0.5558016213920624},
                  {"alpha": 0.7222742800877074},
                  {"alpha": 0.42887539552321635},
                  {"alpha": 0.9809565564007693},
                  {"alpha": 0.6879814411990146},
                  {"alpha": 0.48612258246951734},
                  {"alpha": 0.398196343012209},
                  {"alpha": 0.6995044937418831},
                  {"alpha": 0.29327794160087567},
                  {"alpha": 0.2345829390285611},
                  {"alpha": 0.5558016213920624},
                  {"alpha": 0.7222742800877074},
                  {"alpha": 0.42887539552321635},
                  {"alpha": 0.9809565564007693},
                  {"alpha": 0.6879814411990146},
                  {"alpha": 0.48612258246951734},
                  {"alpha": 0.398196343012209},
              ],
              "mean_absolute_error": np.array(
                  [
                      0.2157946,
                      0.21639339,
                      0.21647289,
                      0.21600778,
                      0.21576132,
                      0.21619734,
                      0.21539791,
                      0.21581151,
                      0.21611205,
                      0.21624265,
                      0.21316446,
                      0.21251148,
                      0.21238838,
                      0.21296631,
                      0.21319325,
                      0.21276374,
                      0.21347973,
                      0.21314963,
                      0.21285869,
                      0.21271021,
                  ]
              ),
              "alpha": np.array(
                  [
                      0.69950449,
                      0.29327794,
                      0.23458294,
                      0.55580162,
                      0.72227428,
                      0.4288754,
                      0.98095656,
                      0.68798144,
                      0.48612258,
                      0.39819634,
                      0.69950449,
                      0.29327794,
                      0.23458294,
                      0.55580162,
                      0.72227428,
                      0.4288754,
                      0.98095656,
                      0.68798144,
                      0.48612258,
                      0.39819634,
                  ]
              ),
          },
          index=pd.RangeIndex(start=0, stop=20, step=1),
      ).sort_values(by="mean_absolute_error", ascending=True)
  
      pd.testing.assert_frame_equal(results, expected_results)
  
imports: import re
  import pytest
  import numpy
  import pandas
  import sys
  from sklearn.ensemble import RandomForestRegressor
  from sklearn.linear_model import Ridge
  from sklearn.metrics import mean_absolute_error
  from skforecast.ForecasterAutoreg import ForecasterAutoreg
  from skforecast.ForecasterAutoregCustom import ForecasterAutoregCustom
  from skforecast.model_selection import backtesting_forecaster
  from skforecast.model_selection.model_selection import _bayesian_search_optuna
  import optuna
  from optuna.samplers import TPESampler
  from tqdm import tqdm
  from functools import partialmethod
  from .fixtures_model_selection import y
label_desc: Use image node_id 6 for calling a global function with example usage: test_results_output_bayesian_search_optuna_ForecasterAutoreg_with_mocked_when_kwargs_create_study() and returns: search_space