How to Implement Your Sampler with OptunaHub

OptunaHub is an Optuna package registry, which is a platform to share algorithms developed by contributors. This recipe shows how to implement your own algorithm with OptunaHub.

Here, we show how to implement your own sampler, i.e., optimizaiton algorithm. If you want to implement algorithms other than a sampler, please refer to the other recipes.

Usually, Optuna provides BaseSampler class to implement your own sampler. However, it is a bit complicated to implement a sampler from scratch. Instead, in OptunaHub, you can use optunahub.samplers.SimpleBaseSampler class, which is a sampler template that can be easily extended.

You need to install optuna to implement your own sampler, and optunahub to use the template SimpleBaseSampler.

$ pip install optuna optunahub

First of all, import optuna, optunahub, and other required modules.

from __future__ import annotations

from typing import Any

import numpy as np
import optuna
import optunahub

Next, define your own sampler class by inheriting SimpleBaseSampler class. In this example, we implement a sampler that returns a random value.

class MySampler(optunahub.samplers.SimpleBaseSampler):
    # By default, search space will be estimated automatically like Optuna's built-in samplers.
    # You can fix the search spacd by `search_space` argument of `SimpleSampler` class.
    def __init__(
        self, search_space: dict[str, optuna.distributions.BaseDistribution] | None = None
    ) -> None:
        super().__init__(search_space)
        self._rng = np.random.RandomState()

    # You need to implement sample_relative method.
    # This method returns a dictionary of hyperparameters.
    # The keys of the dictionary are the names of the hyperparameters, which must be the same as the keys of the search_space argument.
    # The values of the dictionary are the values of the hyperparameters.
    # In this example, sample_relative method returns a dictionary of randomly sampled hyperparameters.
    def sample_relative(
        self,
        study: optuna.study.Study,
        trial: optuna.trial.FrozenTrial,
        search_space: dict[str, optuna.distributions.BaseDistribution],
    ) -> dict[str, Any]:
        # search_space argument must be identical to search_space argument input to __init__ method.
        # This method is automatically invoked by Optuna and SimpleBaseSampler.

        # If search space is empty, all parameter values are sampled randomly by SimpleBaseSampler.
        if search_space == {}:
            return {}

        params = {}  # type: dict[str, Any]
        for n, d in search_space.items():
            if isinstance(d, optuna.distributions.FloatDistribution):
                params[n] = self._rng.uniform(d.low, d.high)
            elif isinstance(d, optuna.distributions.IntDistribution):
                params[n] = self._rng.randint(d.low, d.high)
            elif isinstance(d, optuna.distributions.CategoricalDistribution):
                params[n] = d.choices[self._rng.randint(len(d.choices))]
            else:
                raise NotImplementedError
        return params

Here, as an example, the objective function is defined as follows.

def objective(trial: optuna.trial.Trial) -> float:
    x = trial.suggest_float("x", -10, 10)
    y = trial.suggest_int("y", -10, 10)
    z = trial.suggest_categorical("z", ["a", "b", "c"])
    return x**2 + y**2 + {"a": -10, "b": 0, "c": 10}[z] ** 2

This sampler can be used in the same way as other Optuna samplers. In the following example, we create a study and optimize it using MySampler class.

sampler = MySampler()
study = optuna.create_study(sampler=sampler)
study.optimize(objective, n_trials=100)
[I 2025-05-31 07:02:29,182] A new study created in memory with name: no-name-6a6e876d-6325-4466-9feb-731207ed588b
[I 2025-05-31 07:02:29,183] Trial 0 finished with value: 149.43060199677322 and parameters: {'x': 0.6562027101233436, 'y': 7, 'z': 'a'}. Best is trial 0 with value: 149.43060199677322.
[I 2025-05-31 07:02:29,183] Trial 1 finished with value: 190.25344908639707 and parameters: {'x': -3.041948238612397, 'y': -9, 'z': 'c'}. Best is trial 0 with value: 149.43060199677322.
[I 2025-05-31 07:02:29,184] Trial 2 finished with value: 112.78045344223375 and parameters: {'x': -3.4322665167835886, 'y': -1, 'z': 'c'}. Best is trial 2 with value: 112.78045344223375.
[I 2025-05-31 07:02:29,184] Trial 3 finished with value: 279.1587889628422 and parameters: {'x': -9.907511744269708, 'y': -9, 'z': 'c'}. Best is trial 2 with value: 112.78045344223375.
[I 2025-05-31 07:02:29,185] Trial 4 finished with value: 4.6933646209677775 and parameters: {'x': -2.166417462302171, 'y': 0, 'z': 'b'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,185] Trial 5 finished with value: 81.07301094112614 and parameters: {'x': 7.48819143325851, 'y': -5, 'z': 'b'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,186] Trial 6 finished with value: 185.76888920381995 and parameters: {'x': 7.795440282871773, 'y': 5, 'z': 'a'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,186] Trial 7 finished with value: 82.0150315325962 and parameters: {'x': -7.550829857214119, 'y': -5, 'z': 'b'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,186] Trial 8 finished with value: 75.38795667380472 and parameters: {'x': -3.3746046692619753, 'y': -8, 'z': 'b'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,187] Trial 9 finished with value: 192.6859429330044 and parameters: {'x': 6.6095342447864205, 'y': -7, 'z': 'c'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,187] Trial 10 finished with value: 203.10434210868118 and parameters: {'x': -8.19172400100743, 'y': -6, 'z': 'a'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,188] Trial 11 finished with value: 186.21826520134005 and parameters: {'x': 6.100677437903109, 'y': -7, 'z': 'a'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,188] Trial 12 finished with value: 106.10474017138073 and parameters: {'x': 1.4507722672358767, 'y': 2, 'z': 'a'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,188] Trial 13 finished with value: 25.171848607511052 and parameters: {'x': 0.41454626703306907, 'y': -5, 'z': 'b'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,189] Trial 14 finished with value: 229.90013797902398 and parameters: {'x': -6.992863360528645, 'y': -9, 'z': 'a'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,189] Trial 15 finished with value: 221.72138122239505 and parameters: {'x': -8.527683227137079, 'y': -7, 'z': 'a'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,189] Trial 16 finished with value: 182.83137872106016 and parameters: {'x': 1.3532844198690022, 'y': -9, 'z': 'c'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,190] Trial 17 finished with value: 151.02344420240965 and parameters: {'x': -1.422478190486462, 'y': -7, 'z': 'a'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,190] Trial 18 finished with value: 145.1510219911908 and parameters: {'x': -3.02506561766696, 'y': -6, 'z': 'a'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,191] Trial 19 finished with value: 177.46669289939163 and parameters: {'x': 5.335418718281783, 'y': -7, 'z': 'c'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,191] Trial 20 finished with value: 175.6700011498977 and parameters: {'x': -6.298412589684618, 'y': 6, 'z': 'c'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,191] Trial 21 finished with value: 194.92384162911281 and parameters: {'x': -8.883909141200894, 'y': 4, 'z': 'a'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,192] Trial 22 finished with value: 216.52645203462018 and parameters: {'x': 8.217448024455049, 'y': 7, 'z': 'a'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,192] Trial 23 finished with value: 6.028277253797636 and parameters: {'x': -1.424175991160375, 'y': 2, 'z': 'b'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,192] Trial 24 finished with value: 165.6694839794294 and parameters: {'x': -5.446970165094482, 'y': -6, 'z': 'a'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,193] Trial 25 finished with value: 101.95457924501503 and parameters: {'x': 7.276989710382654, 'y': -7, 'z': 'b'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,193] Trial 26 finished with value: 34.70411188436485 and parameters: {'x': -4.3248250697993385, 'y': -4, 'z': 'b'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,194] Trial 27 finished with value: 183.75699506083805 and parameters: {'x': -5.895506344737324, 'y': -7, 'z': 'a'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,194] Trial 28 finished with value: 132.14522799749034 and parameters: {'x': -8.255012295417272, 'y': -8, 'z': 'b'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,194] Trial 29 finished with value: 41.81760059036561 and parameters: {'x': 2.4119702714514553, 'y': -6, 'z': 'b'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,195] Trial 30 finished with value: 135.494241706315 and parameters: {'x': -5.611973067140914, 'y': -2, 'z': 'a'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,195] Trial 31 finished with value: 51.2249665853096 and parameters: {'x': 5.121031789132889, 'y': -5, 'z': 'b'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,195] Trial 32 finished with value: 116.61177911847992 and parameters: {'x': 0.7821631022235174, 'y': -4, 'z': 'c'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,196] Trial 33 finished with value: 190.27877437833382 and parameters: {'x': 3.046108070691817, 'y': -9, 'z': 'c'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,196] Trial 34 finished with value: 157.9989062706167 and parameters: {'x': 6.999921876036666, 'y': 3, 'z': 'a'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,197] Trial 35 finished with value: 196.75469530164403 and parameters: {'x': 8.986361627580099, 'y': 4, 'z': 'a'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,197] Trial 36 finished with value: 181.57196086272663 and parameters: {'x': 0.7562809416656151, 'y': -9, 'z': 'a'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,197] Trial 37 finished with value: 166.53262400367404 and parameters: {'x': 6.444580979681614, 'y': -5, 'z': 'a'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,198] Trial 38 finished with value: 162.77089568453673 and parameters: {'x': -7.8594462708601, 'y': 1, 'z': 'a'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,198] Trial 39 finished with value: 179.03045035391983 and parameters: {'x': 8.368419824191413, 'y': -3, 'z': 'c'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,198] Trial 40 finished with value: 67.24790243257277 and parameters: {'x': 7.632031343788675, 'y': -3, 'z': 'b'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,199] Trial 41 finished with value: 259.95186015078747 and parameters: {'x': 9.795502036689467, 'y': 8, 'z': 'a'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,199] Trial 42 finished with value: 67.16755660658258 and parameters: {'x': -1.779763075968983, 'y': 8, 'z': 'b'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,200] Trial 43 finished with value: 143.58860806626217 and parameters: {'x': 7.911296231734859, 'y': 9, 'z': 'b'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,200] Trial 44 finished with value: 201.95486904608973 and parameters: {'x': 9.897215216720799, 'y': 2, 'z': 'c'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,200] Trial 45 finished with value: 258.2175465638504 and parameters: {'x': -8.78735151020206, 'y': 9, 'z': 'c'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,201] Trial 46 finished with value: 149.92105445588646 and parameters: {'x': -0.9597158203793743, 'y': -7, 'z': 'c'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,201] Trial 47 finished with value: 260.5898802222752 and parameters: {'x': -9.828015070311768, 'y': -8, 'z': 'c'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,201] Trial 48 finished with value: 117.33831262763121 and parameters: {'x': -2.8876136562274413, 'y': -3, 'z': 'c'}. Best is trial 4 with value: 4.6933646209677775.
[I 2025-05-31 07:02:29,202] Trial 49 finished with value: 4.274843356313175 and parameters: {'x': 1.809652827564772, 'y': 1, 'z': 'b'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,202] Trial 50 finished with value: 169.32337222415373 and parameters: {'x': 2.3072434254221523, 'y': 8, 'z': 'c'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,203] Trial 51 finished with value: 104.90918180256823 and parameters: {'x': -1.977165092390674, 'y': 1, 'z': 'c'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,203] Trial 52 finished with value: 164.34096890106537 and parameters: {'x': 7.439151087393331, 'y': 3, 'z': 'c'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,203] Trial 53 finished with value: 71.66221272803256 and parameters: {'x': 5.971784718828413, 'y': -6, 'z': 'b'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,204] Trial 54 finished with value: 246.97785938895092 and parameters: {'x': 9.89837660371391, 'y': -7, 'z': 'c'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,204] Trial 55 finished with value: 39.718178038331 and parameters: {'x': 1.9282577727915413, 'y': 6, 'z': 'b'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,204] Trial 56 finished with value: 117.74826762553835 and parameters: {'x': 9.63059020130845, 'y': 5, 'z': 'b'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,205] Trial 57 finished with value: 210.3885102304071 and parameters: {'x': -9.24059036157361, 'y': 5, 'z': 'a'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,205] Trial 58 finished with value: 220.72686983665136 and parameters: {'x': -7.531724227336749, 'y': -8, 'z': 'c'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,205] Trial 59 finished with value: 181.02920063598495 and parameters: {'x': 0.17088193580643285, 'y': 9, 'z': 'a'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,206] Trial 60 finished with value: 193.31728103079513 and parameters: {'x': 6.657122578922152, 'y': 7, 'z': 'a'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,206] Trial 61 finished with value: 163.23776244665652 and parameters: {'x': -6.183669011732153, 'y': -5, 'z': 'c'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,207] Trial 62 finished with value: 65.70338412955465 and parameters: {'x': -4.0869773830490725, 'y': 7, 'z': 'b'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,207] Trial 63 finished with value: 73.00655127821562 and parameters: {'x': 8.485667403228554, 'y': 1, 'z': 'b'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,207] Trial 64 finished with value: 97.02188513311253 and parameters: {'x': 5.746467187160519, 'y': 8, 'z': 'b'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,208] Trial 65 finished with value: 176.68973853785832 and parameters: {'x': -3.562265927448191, 'y': -8, 'z': 'c'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,208] Trial 66 finished with value: 18.496558581045733 and parameters: {'x': -3.0816486790427184, 'y': -3, 'z': 'b'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,208] Trial 67 finished with value: 192.30615252636636 and parameters: {'x': 5.3203526693600285, 'y': 8, 'z': 'a'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,209] Trial 68 finished with value: 26.038082434663913 and parameters: {'x': -5.10275243713272, 'y': 0, 'z': 'b'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,209] Trial 69 finished with value: 63.36666327018823 and parameters: {'x': 7.897256692686913, 'y': -1, 'z': 'b'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,209] Trial 70 finished with value: 172.7522149565255 and parameters: {'x': 7.533406597053254, 'y': -4, 'z': 'c'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,210] Trial 71 finished with value: 13.550914281878903 and parameters: {'x': 3.090455351866275, 'y': 2, 'z': 'b'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,210] Trial 72 finished with value: 96.47449504736642 and parameters: {'x': 8.970757774422761, 'y': 4, 'z': 'b'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,210] Trial 73 finished with value: 125.03264754333864 and parameters: {'x': 0.18068631198472218, 'y': 5, 'z': 'c'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,211] Trial 74 finished with value: 95.46228602819039 and parameters: {'x': 6.816324964978591, 'y': 7, 'z': 'b'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,211] Trial 75 finished with value: 125.01365463338664 and parameters: {'x': 5.00136527694055, 'y': 0, 'z': 'a'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,212] Trial 76 finished with value: 174.20408979266014 and parameters: {'x': -3.19438410224258, 'y': -8, 'z': 'a'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,212] Trial 77 finished with value: 211.27827881637722 and parameters: {'x': 5.5025702009494815, 'y': -9, 'z': 'a'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,212] Trial 78 finished with value: 157.6677707226595 and parameters: {'x': 7.32582901265512, 'y': -2, 'z': 'c'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,213] Trial 79 finished with value: 118.97513175282762 and parameters: {'x': 1.7248570238798422, 'y': 4, 'z': 'a'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,213] Trial 80 finished with value: 137.5469685058071 and parameters: {'x': 1.2437718865640424, 'y': 6, 'z': 'c'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,213] Trial 81 finished with value: 200.10226142586328 and parameters: {'x': 6.008515742332982, 'y': 8, 'z': 'a'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,214] Trial 82 finished with value: 207.95289652232287 and parameters: {'x': 8.482505321090159, 'y': 6, 'z': 'c'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,215] Trial 83 finished with value: 211.06377441657787 and parameters: {'x': 5.483044265422073, 'y': 9, 'z': 'c'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,215] Trial 84 finished with value: 141.52198256673327 and parameters: {'x': -7.779587557623686, 'y': -9, 'z': 'b'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,215] Trial 85 finished with value: 206.104158546631 and parameters: {'x': -6.488771728657974, 'y': -8, 'z': 'c'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,216] Trial 86 finished with value: 185.17534831706809 and parameters: {'x': 9.009736306744394, 'y': 2, 'z': 'a'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,216] Trial 87 finished with value: 51.345769079123734 and parameters: {'x': -6.880826191608369, 'y': -2, 'z': 'b'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,216] Trial 88 finished with value: 201.56843699541548 and parameters: {'x': 9.87767366313625, 'y': -2, 'z': 'c'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,217] Trial 89 finished with value: 13.129335525933648 and parameters: {'x': -3.0214790295372973, 'y': -2, 'z': 'b'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,217] Trial 90 finished with value: 95.22677124241991 and parameters: {'x': -3.7718392386765265, 'y': -9, 'z': 'b'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,217] Trial 91 finished with value: 161.25876393685985 and parameters: {'x': 3.501251767134125, 'y': -7, 'z': 'a'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,218] Trial 92 finished with value: 93.23897232315649 and parameters: {'x': -9.604112261065907, 'y': -1, 'z': 'b'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,218] Trial 93 finished with value: 229.0858310773445 and parameters: {'x': -9.648099868748483, 'y': 6, 'z': 'c'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,219] Trial 94 finished with value: 205.1977418950063 and parameters: {'x': 2.2798556741614746, 'y': -10, 'z': 'c'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,219] Trial 95 finished with value: 196.20553011813394 and parameters: {'x': -8.955754022868982, 'y': -4, 'z': 'a'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,219] Trial 96 finished with value: 65.21430409513299 and parameters: {'x': -1.1019546701806693, 'y': 8, 'z': 'b'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,220] Trial 97 finished with value: 125.23727942034144 and parameters: {'x': -0.48711335471472594, 'y': 5, 'z': 'a'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,220] Trial 98 finished with value: 146.8274189264385 and parameters: {'x': -8.113409821181136, 'y': -9, 'z': 'b'}. Best is trial 49 with value: 4.274843356313175.
[I 2025-05-31 07:02:29,221] Trial 99 finished with value: 9.381626239594556 and parameters: {'x': -0.6177590465501552, 'y': -3, 'z': 'b'}. Best is trial 49 with value: 4.274843356313175.

The best parameters can be fetched as follows.

best_params = study.best_params
best_value = study.best_value
print(f"Best params: {best_params}, Best value: {best_value}")
Best params: {'x': 1.809652827564772, 'y': 1, 'z': 'b'}, Best value: 4.274843356313175

We can see that best_params value found by Optuna is close to the optimal value {"x":0, "y": 0, "z": "b"}.

In the above examples, search space is estimated at the first trial and updated dynamically through optimization. If your sampler requires the search space to be fixed before optimization, you can pass the search space to the sampler at initialization. Passing the search space also allows the sampler to avoid the overhead of estimating the search space. See the documentation for more information about the optuna.distributions to define search space.

sampler = MySampler(
    search_space={
        "x": optuna.distributions.FloatDistribution(-10, 10),
        "y": optuna.distributions.IntDistribution(-10, 10),
        "z": optuna.distributions.CategoricalDistribution(["a", "b", "c"]),
    }
)
study = optuna.create_study(sampler=sampler)
study.optimize(objective, n_trials=100)
[I 2025-05-31 07:02:29,222] A new study created in memory with name: no-name-8a84c08f-00b2-4ce7-99fc-3bbcf23ad3ed
[I 2025-05-31 07:02:29,222] Trial 0 finished with value: 186.5629985461226 and parameters: {'x': 9.303923825253655, 'y': 0, 'z': 'c'}. Best is trial 0 with value: 186.5629985461226.
[I 2025-05-31 07:02:29,222] Trial 1 finished with value: 40.61324254392098 and parameters: {'x': 3.951359581703617, 'y': -5, 'z': 'b'}. Best is trial 1 with value: 40.61324254392098.
[I 2025-05-31 07:02:29,223] Trial 2 finished with value: 107.61260051012457 and parameters: {'x': 2.571497717308839, 'y': 1, 'z': 'c'}. Best is trial 1 with value: 40.61324254392098.
[I 2025-05-31 07:02:29,223] Trial 3 finished with value: 91.78024151130845 and parameters: {'x': -8.705184748832643, 'y': 4, 'z': 'b'}. Best is trial 1 with value: 40.61324254392098.
[I 2025-05-31 07:02:29,223] Trial 4 finished with value: 58.128456945142865 and parameters: {'x': 7.357204424585664, 'y': -2, 'z': 'b'}. Best is trial 1 with value: 40.61324254392098.
[I 2025-05-31 07:02:29,224] Trial 5 finished with value: 202.09090528178473 and parameters: {'x': -9.278518485285499, 'y': -4, 'z': 'a'}. Best is trial 1 with value: 40.61324254392098.
[I 2025-05-31 07:02:29,224] Trial 6 finished with value: 161.7838459366617 and parameters: {'x': -7.601568649736823, 'y': -2, 'z': 'c'}. Best is trial 1 with value: 40.61324254392098.
[I 2025-05-31 07:02:29,224] Trial 7 finished with value: 56.05951514558951 and parameters: {'x': -6.859993815273415, 'y': -3, 'z': 'b'}. Best is trial 1 with value: 40.61324254392098.
[I 2025-05-31 07:02:29,225] Trial 8 finished with value: 69.48390497929678 and parameters: {'x': 8.275500285740844, 'y': -1, 'z': 'b'}. Best is trial 1 with value: 40.61324254392098.
[I 2025-05-31 07:02:29,225] Trial 9 finished with value: 110.96001860759561 and parameters: {'x': -5.4735745731282055, 'y': 9, 'z': 'b'}. Best is trial 1 with value: 40.61324254392098.
[I 2025-05-31 07:02:29,225] Trial 10 finished with value: 116.15663036139355 and parameters: {'x': -0.3957655384107497, 'y': 4, 'z': 'a'}. Best is trial 1 with value: 40.61324254392098.
[I 2025-05-31 07:02:29,226] Trial 11 finished with value: 49.66921798836165 and parameters: {'x': -6.377242193014285, 'y': 3, 'z': 'b'}. Best is trial 1 with value: 40.61324254392098.
[I 2025-05-31 07:02:29,226] Trial 12 finished with value: 23.715413195360938 and parameters: {'x': -4.440204183971829, 'y': -2, 'z': 'b'}. Best is trial 12 with value: 23.715413195360938.
[I 2025-05-31 07:02:29,226] Trial 13 finished with value: 55.671561651725824 and parameters: {'x': -7.394022021317344, 'y': -1, 'z': 'b'}. Best is trial 12 with value: 23.715413195360938.
[I 2025-05-31 07:02:29,227] Trial 14 finished with value: 120.06534688461004 and parameters: {'x': -4.366388311248787, 'y': 1, 'z': 'c'}. Best is trial 12 with value: 23.715413195360938.
[I 2025-05-31 07:02:29,227] Trial 15 finished with value: 132.5894616106066 and parameters: {'x': -5.3469114085242335, 'y': -2, 'z': 'c'}. Best is trial 12 with value: 23.715413195360938.
[I 2025-05-31 07:02:29,227] Trial 16 finished with value: 129.01941695020625 and parameters: {'x': -2.0048483609007057, 'y': -5, 'z': 'c'}. Best is trial 12 with value: 23.715413195360938.
[I 2025-05-31 07:02:29,228] Trial 17 finished with value: 179.09908492452172 and parameters: {'x': -5.48626329340123, 'y': -7, 'z': 'a'}. Best is trial 12 with value: 23.715413195360938.
[I 2025-05-31 07:02:29,228] Trial 18 finished with value: 133.4764478661458 and parameters: {'x': -5.698811092337226, 'y': 1, 'z': 'a'}. Best is trial 12 with value: 23.715413195360938.
[I 2025-05-31 07:02:29,228] Trial 19 finished with value: 121.5626012873332 and parameters: {'x': 4.534600455093392, 'y': 1, 'z': 'c'}. Best is trial 12 with value: 23.715413195360938.
[I 2025-05-31 07:02:29,228] Trial 20 finished with value: 22.469449776102284 and parameters: {'x': 4.297609774758788, 'y': 2, 'z': 'b'}. Best is trial 20 with value: 22.469449776102284.
[I 2025-05-31 07:02:29,229] Trial 21 finished with value: 150.76328602069992 and parameters: {'x': 6.838368666626561, 'y': -2, 'z': 'a'}. Best is trial 20 with value: 22.469449776102284.
[I 2025-05-31 07:02:29,229] Trial 22 finished with value: 67.65404246377493 and parameters: {'x': -1.911554985809964, 'y': 8, 'z': 'b'}. Best is trial 20 with value: 22.469449776102284.
[I 2025-05-31 07:02:29,229] Trial 23 finished with value: 11.233020466506801 and parameters: {'x': -1.4943294370743025, 'y': -3, 'z': 'b'}. Best is trial 23 with value: 11.233020466506801.
[I 2025-05-31 07:02:29,230] Trial 24 finished with value: 139.1084207409957 and parameters: {'x': -1.7630713941856442, 'y': 6, 'z': 'a'}. Best is trial 23 with value: 11.233020466506801.
[I 2025-05-31 07:02:29,230] Trial 25 finished with value: 110.27959307303271 and parameters: {'x': 1.1311909975917889, 'y': 3, 'z': 'c'}. Best is trial 23 with value: 11.233020466506801.
[I 2025-05-31 07:02:29,230] Trial 26 finished with value: 162.16933052262195 and parameters: {'x': -3.628957222484434, 'y': 7, 'z': 'a'}. Best is trial 23 with value: 11.233020466506801.
[I 2025-05-31 07:02:29,231] Trial 27 finished with value: 144.5754854573036 and parameters: {'x': -6.601173036461294, 'y': 1, 'z': 'a'}. Best is trial 23 with value: 11.233020466506801.
[I 2025-05-31 07:02:29,231] Trial 28 finished with value: 157.51681654638546 and parameters: {'x': 5.702351843440166, 'y': -5, 'z': 'c'}. Best is trial 23 with value: 11.233020466506801.
[I 2025-05-31 07:02:29,231] Trial 29 finished with value: 48.64743015784996 and parameters: {'x': -6.296620534687632, 'y': 3, 'z': 'b'}. Best is trial 23 with value: 11.233020466506801.
[I 2025-05-31 07:02:29,232] Trial 30 finished with value: 109.63850468684794 and parameters: {'x': -0.7990648827522957, 'y': -3, 'z': 'c'}. Best is trial 23 with value: 11.233020466506801.
[I 2025-05-31 07:02:29,232] Trial 31 finished with value: 174.3262521950349 and parameters: {'x': 8.563074926393842, 'y': -1, 'z': 'a'}. Best is trial 23 with value: 11.233020466506801.
[I 2025-05-31 07:02:29,232] Trial 32 finished with value: 65.03929335794268 and parameters: {'x': -5.388811868857799, 'y': 6, 'z': 'b'}. Best is trial 23 with value: 11.233020466506801.
[I 2025-05-31 07:02:29,233] Trial 33 finished with value: 28.349314032545024 and parameters: {'x': 1.83011312014996, 'y': 5, 'z': 'b'}. Best is trial 23 with value: 11.233020466506801.
[I 2025-05-31 07:02:29,233] Trial 34 finished with value: 207.1662411870514 and parameters: {'x': -8.436008605202545, 'y': 6, 'z': 'a'}. Best is trial 23 with value: 11.233020466506801.
[I 2025-05-31 07:02:29,233] Trial 35 finished with value: 206.76971366347672 and parameters: {'x': -5.0763878558948505, 'y': -9, 'z': 'a'}. Best is trial 23 with value: 11.233020466506801.
[I 2025-05-31 07:02:29,234] Trial 36 finished with value: 199.91652249769214 and parameters: {'x': -9.535015600285725, 'y': -3, 'z': 'c'}. Best is trial 23 with value: 11.233020466506801.
[I 2025-05-31 07:02:29,234] Trial 37 finished with value: 156.94501710682505 and parameters: {'x': -7.479640172282691, 'y': -1, 'z': 'c'}. Best is trial 23 with value: 11.233020466506801.
[I 2025-05-31 07:02:29,234] Trial 38 finished with value: 132.99398054478957 and parameters: {'x': 5.744038696317215, 'y': -10, 'z': 'b'}. Best is trial 23 with value: 11.233020466506801.
[I 2025-05-31 07:02:29,235] Trial 39 finished with value: 171.17283681750703 and parameters: {'x': 6.7950597361249905, 'y': 5, 'z': 'c'}. Best is trial 23 with value: 11.233020466506801.
[I 2025-05-31 07:02:29,235] Trial 40 finished with value: 62.45042093609999 and parameters: {'x': -7.839031887682304, 'y': 1, 'z': 'b'}. Best is trial 23 with value: 11.233020466506801.
[I 2025-05-31 07:02:29,235] Trial 41 finished with value: 24.06631191487909 and parameters: {'x': 4.90574274854268, 'y': 0, 'z': 'b'}. Best is trial 23 with value: 11.233020466506801.
[I 2025-05-31 07:02:29,236] Trial 42 finished with value: 171.58319911539616 and parameters: {'x': 4.752178354754392, 'y': -7, 'z': 'c'}. Best is trial 23 with value: 11.233020466506801.
[I 2025-05-31 07:02:29,236] Trial 43 finished with value: 144.49018689200352 and parameters: {'x': -4.414769177658502, 'y': -5, 'z': 'c'}. Best is trial 23 with value: 11.233020466506801.
[I 2025-05-31 07:02:29,236] Trial 44 finished with value: 107.872474904999 and parameters: {'x': -2.8057930973254237, 'y': 0, 'z': 'c'}. Best is trial 23 with value: 11.233020466506801.
[I 2025-05-31 07:02:29,236] Trial 45 finished with value: 2.2137102579400763 and parameters: {'x': -1.1016851900339208, 'y': 1, 'z': 'b'}. Best is trial 45 with value: 2.2137102579400763.
[I 2025-05-31 07:02:29,237] Trial 46 finished with value: 39.00039774835366 and parameters: {'x': -5.477261884222231, 'y': -3, 'z': 'b'}. Best is trial 45 with value: 2.2137102579400763.
[I 2025-05-31 07:02:29,237] Trial 47 finished with value: 115.33145502962364 and parameters: {'x': -9.504286139927798, 'y': -5, 'z': 'b'}. Best is trial 45 with value: 2.2137102579400763.
[I 2025-05-31 07:02:29,237] Trial 48 finished with value: 126.94699323775843 and parameters: {'x': -1.3953469954668751, 'y': -5, 'z': 'c'}. Best is trial 45 with value: 2.2137102579400763.
[I 2025-05-31 07:02:29,238] Trial 49 finished with value: 103.8120420627281 and parameters: {'x': -1.9524451497361195, 'y': -10, 'z': 'b'}. Best is trial 45 with value: 2.2137102579400763.
[I 2025-05-31 07:02:29,238] Trial 50 finished with value: 120.13018181268453 and parameters: {'x': 2.032284874884553, 'y': 4, 'z': 'a'}. Best is trial 45 with value: 2.2137102579400763.
[I 2025-05-31 07:02:29,238] Trial 51 finished with value: 115.46517097061786 and parameters: {'x': -3.9325781582338397, 'y': -10, 'z': 'b'}. Best is trial 45 with value: 2.2137102579400763.
[I 2025-05-31 07:02:29,239] Trial 52 finished with value: 262.6519652900341 and parameters: {'x': -9.03614770187131, 'y': -9, 'z': 'a'}. Best is trial 45 with value: 2.2137102579400763.
[I 2025-05-31 07:02:29,239] Trial 53 finished with value: 149.23971873977004 and parameters: {'x': -6.72604778006892, 'y': 2, 'z': 'a'}. Best is trial 45 with value: 2.2137102579400763.
[I 2025-05-31 07:02:29,239] Trial 54 finished with value: 23.390034818266532 and parameters: {'x': -4.836324515400774, 'y': 0, 'z': 'b'}. Best is trial 45 with value: 2.2137102579400763.
[I 2025-05-31 07:02:29,240] Trial 55 finished with value: 31.251999128458728 and parameters: {'x': 2.500399793724741, 'y': 5, 'z': 'b'}. Best is trial 45 with value: 2.2137102579400763.
[I 2025-05-31 07:02:29,240] Trial 56 finished with value: 153.26844645433442 and parameters: {'x': -2.066021891058856, 'y': -7, 'z': 'c'}. Best is trial 45 with value: 2.2137102579400763.
[I 2025-05-31 07:02:29,240] Trial 57 finished with value: 81.76245192833808 and parameters: {'x': -8.98679319492432, 'y': 1, 'z': 'b'}. Best is trial 45 with value: 2.2137102579400763.
[I 2025-05-31 07:02:29,240] Trial 58 finished with value: 171.8346679220743 and parameters: {'x': 6.8435858964489, 'y': -5, 'z': 'c'}. Best is trial 45 with value: 2.2137102579400763.
[I 2025-05-31 07:02:29,241] Trial 59 finished with value: 132.83210446302738 and parameters: {'x': -5.369553469612476, 'y': 2, 'z': 'c'}. Best is trial 45 with value: 2.2137102579400763.
[I 2025-05-31 07:02:29,241] Trial 60 finished with value: 103.51849866773337 and parameters: {'x': -1.5869778409711248, 'y': 1, 'z': 'c'}. Best is trial 45 with value: 2.2137102579400763.
[I 2025-05-31 07:02:29,241] Trial 61 finished with value: 141.59535229085594 and parameters: {'x': -6.131504896096547, 'y': -2, 'z': 'c'}. Best is trial 45 with value: 2.2137102579400763.
[I 2025-05-31 07:02:29,242] Trial 62 finished with value: 156.88859420621333 and parameters: {'x': -6.394418988947576, 'y': -4, 'z': 'a'}. Best is trial 45 with value: 2.2137102579400763.
[I 2025-05-31 07:02:29,242] Trial 63 finished with value: 186.94057542432103 and parameters: {'x': 6.159592147563103, 'y': 7, 'z': 'a'}. Best is trial 45 with value: 2.2137102579400763.
[I 2025-05-31 07:02:29,242] Trial 64 finished with value: 85.50581112405408 and parameters: {'x': 7.7785481372846235, 'y': -5, 'z': 'b'}. Best is trial 45 with value: 2.2137102579400763.
[I 2025-05-31 07:02:29,243] Trial 65 finished with value: 117.71055499672734 and parameters: {'x': -2.9513649379104816, 'y': -3, 'z': 'c'}. Best is trial 45 with value: 2.2137102579400763.
[I 2025-05-31 07:02:29,243] Trial 66 finished with value: 4.012916027827629 and parameters: {'x': -0.11364870358974244, 'y': 2, 'z': 'b'}. Best is trial 45 with value: 2.2137102579400763.
[I 2025-05-31 07:02:29,243] Trial 67 finished with value: 186.8018642331891 and parameters: {'x': 2.408705925012246, 'y': 9, 'z': 'a'}. Best is trial 45 with value: 2.2137102579400763.
[I 2025-05-31 07:02:29,244] Trial 68 finished with value: 1.496862109441608 and parameters: {'x': -0.7048844653144286, 'y': 1, 'z': 'b'}. Best is trial 68 with value: 1.496862109441608.
[I 2025-05-31 07:02:29,244] Trial 69 finished with value: 172.42550295915404 and parameters: {'x': 2.902671693311877, 'y': -8, 'z': 'c'}. Best is trial 68 with value: 1.496862109441608.
[I 2025-05-31 07:02:29,244] Trial 70 finished with value: 15.635235209119337 and parameters: {'x': 3.4110460579006165, 'y': -2, 'z': 'b'}. Best is trial 68 with value: 1.496862109441608.
[I 2025-05-31 07:02:29,245] Trial 71 finished with value: 129.98933539936456 and parameters: {'x': -5.476251948126983, 'y': 0, 'z': 'a'}. Best is trial 68 with value: 1.496862109441608.
[I 2025-05-31 07:02:29,245] Trial 72 finished with value: 178.38450667723666 and parameters: {'x': -3.792691218282429, 'y': 8, 'z': 'a'}. Best is trial 68 with value: 1.496862109441608.
[I 2025-05-31 07:02:29,245] Trial 73 finished with value: 135.6989751006842 and parameters: {'x': -3.270928782576017, 'y': -5, 'z': 'a'}. Best is trial 68 with value: 1.496862109441608.
[I 2025-05-31 07:02:29,245] Trial 74 finished with value: 172.34687814458474 and parameters: {'x': -2.8890964235526546, 'y': -8, 'z': 'a'}. Best is trial 68 with value: 1.496862109441608.
[I 2025-05-31 07:02:29,246] Trial 75 finished with value: 141.31907610155446 and parameters: {'x': -5.684986904255316, 'y': 3, 'z': 'c'}. Best is trial 68 with value: 1.496862109441608.
[I 2025-05-31 07:02:29,246] Trial 76 finished with value: 142.16163518361046 and parameters: {'x': -2.482264124465898, 'y': -6, 'z': 'a'}. Best is trial 68 with value: 1.496862109441608.
[I 2025-05-31 07:02:29,246] Trial 77 finished with value: 5.671460153599227 and parameters: {'x': 1.2928496252848696, 'y': -2, 'z': 'b'}. Best is trial 68 with value: 1.496862109441608.
[I 2025-05-31 07:02:29,247] Trial 78 finished with value: 192.6696027829191 and parameters: {'x': 9.14710898497001, 'y': 3, 'z': 'a'}. Best is trial 68 with value: 1.496862109441608.
[I 2025-05-31 07:02:29,247] Trial 79 finished with value: 155.1322717534064 and parameters: {'x': -2.4763424144100927, 'y': 7, 'z': 'c'}. Best is trial 68 with value: 1.496862109441608.
[I 2025-05-31 07:02:29,247] Trial 80 finished with value: 17.50298481941671 and parameters: {'x': 2.915987794798996, 'y': 3, 'z': 'b'}. Best is trial 68 with value: 1.496862109441608.
[I 2025-05-31 07:02:29,248] Trial 81 finished with value: 164.44787409543557 and parameters: {'x': 0.6692339616573246, 'y': 8, 'z': 'a'}. Best is trial 68 with value: 1.496862109441608.
[I 2025-05-31 07:02:29,248] Trial 82 finished with value: 162.34832576267303 and parameters: {'x': -3.653536062867455, 'y': 7, 'z': 'c'}. Best is trial 68 with value: 1.496862109441608.
[I 2025-05-31 07:02:29,248] Trial 83 finished with value: 165.4552243779655 and parameters: {'x': -6.360442152709629, 'y': -5, 'z': 'a'}. Best is trial 68 with value: 1.496862109441608.
[I 2025-05-31 07:02:29,249] Trial 84 finished with value: 155.00068272785035 and parameters: {'x': 4.3589772570925795, 'y': -6, 'z': 'a'}. Best is trial 68 with value: 1.496862109441608.
[I 2025-05-31 07:02:29,249] Trial 85 finished with value: 177.39696497386603 and parameters: {'x': 5.3288802739286645, 'y': 7, 'z': 'a'}. Best is trial 68 with value: 1.496862109441608.
[I 2025-05-31 07:02:29,249] Trial 86 finished with value: 192.97116125777703 and parameters: {'x': -3.459936597363747, 'y': 9, 'z': 'c'}. Best is trial 68 with value: 1.496862109441608.
[I 2025-05-31 07:02:29,249] Trial 87 finished with value: 130.43970044651695 and parameters: {'x': 2.3323165408059303, 'y': -5, 'z': 'a'}. Best is trial 68 with value: 1.496862109441608.
[I 2025-05-31 07:02:29,250] Trial 88 finished with value: 1.008675310577827 and parameters: {'x': -0.09314134730519541, 'y': 1, 'z': 'b'}. Best is trial 88 with value: 1.008675310577827.
[I 2025-05-31 07:02:29,250] Trial 89 finished with value: 208.45999130570127 and parameters: {'x': -7.711030495705568, 'y': 7, 'z': 'c'}. Best is trial 88 with value: 1.008675310577827.
[I 2025-05-31 07:02:29,250] Trial 90 finished with value: 203.91607867724815 and parameters: {'x': -1.9789084560050156, 'y': -10, 'z': 'c'}. Best is trial 88 with value: 1.008675310577827.
[I 2025-05-31 07:02:29,251] Trial 91 finished with value: 149.79821584344796 and parameters: {'x': -5.813623297346327, 'y': -4, 'z': 'c'}. Best is trial 88 with value: 1.008675310577827.
[I 2025-05-31 07:02:29,251] Trial 92 finished with value: 192.39178553006522 and parameters: {'x': 9.559905100473813, 'y': -1, 'z': 'c'}. Best is trial 88 with value: 1.008675310577827.
[I 2025-05-31 07:02:29,251] Trial 93 finished with value: 130.52308740328186 and parameters: {'x': -3.8109168717359676, 'y': 4, 'z': 'c'}. Best is trial 88 with value: 1.008675310577827.
[I 2025-05-31 07:02:29,252] Trial 94 finished with value: 133.7622868181524 and parameters: {'x': -2.9601160143062666, 'y': -5, 'z': 'c'}. Best is trial 88 with value: 1.008675310577827.
[I 2025-05-31 07:02:29,252] Trial 95 finished with value: 201.0330295928381 and parameters: {'x': -9.22133556448512, 'y': -4, 'z': 'c'}. Best is trial 88 with value: 1.008675310577827.
[I 2025-05-31 07:02:29,252] Trial 96 finished with value: 272.2546760482478 and parameters: {'x': 9.552731339687504, 'y': 9, 'z': 'a'}. Best is trial 88 with value: 1.008675310577827.
[I 2025-05-31 07:02:29,253] Trial 97 finished with value: 123.46549815016101 and parameters: {'x': 2.732306379262951, 'y': 4, 'z': 'c'}. Best is trial 88 with value: 1.008675310577827.
[I 2025-05-31 07:02:29,253] Trial 98 finished with value: 191.01416623170627 and parameters: {'x': 7.4171535127504455, 'y': -6, 'z': 'c'}. Best is trial 88 with value: 1.008675310577827.
[I 2025-05-31 07:02:29,253] Trial 99 finished with value: 107.75818656563843 and parameters: {'x': -2.7853521439197637, 'y': 0, 'z': 'c'}. Best is trial 88 with value: 1.008675310577827.

In the next recipe, we will show how to register your sampler to OptunaHub. Let’s move on to How to Register Your Package with OptunaHub. See the User-Defined Sampler documentation for more information to implement a sampler.

Total running time of the script: (0 minutes 0.191 seconds)

Gallery generated by Sphinx-Gallery