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 2024-11-22 05:51:14,358] A new study created in memory with name: no-name-037fe885-a92a-4c42-8277-edeea90d3545
[I 2024-11-22 05:51:14,359] Trial 0 finished with value: 233.93168955631296 and parameters: {'x': 9.215839058724548, 'y': -7, 'z': 'c'}. Best is trial 0 with value: 233.93168955631296.
[I 2024-11-22 05:51:14,359] Trial 1 finished with value: 110.27325917275692 and parameters: {'x': 7.827723754244072, 'y': 7, 'z': 'b'}. Best is trial 1 with value: 110.27325917275692.
[I 2024-11-22 05:51:14,360] Trial 2 finished with value: 265.7246062467391 and parameters: {'x': 9.204597017074626, 'y': 9, 'z': 'a'}. Best is trial 1 with value: 110.27325917275692.
[I 2024-11-22 05:51:14,360] Trial 3 finished with value: 181.39761277573336 and parameters: {'x': 0.6305654412773869, 'y': -9, 'z': 'c'}. Best is trial 1 with value: 110.27325917275692.
[I 2024-11-22 05:51:14,361] Trial 4 finished with value: 83.9344424567358 and parameters: {'x': 9.106834930794331, 'y': -1, 'z': 'b'}. Best is trial 4 with value: 83.9344424567358.
[I 2024-11-22 05:51:14,361] Trial 5 finished with value: 82.33401447256689 and parameters: {'x': -1.1549954426606597, 'y': -9, 'z': 'b'}. Best is trial 5 with value: 82.33401447256689.
[I 2024-11-22 05:51:14,361] Trial 6 finished with value: 33.16463573709966 and parameters: {'x': 5.400429217858489, 'y': -2, 'z': 'b'}. Best is trial 6 with value: 33.16463573709966.
[I 2024-11-22 05:51:14,362] Trial 7 finished with value: 121.30357169024936 and parameters: {'x': -3.507644749721579, 'y': 3, 'z': 'a'}. Best is trial 6 with value: 33.16463573709966.
[I 2024-11-22 05:51:14,362] Trial 8 finished with value: 57.97987377071861 and parameters: {'x': 4.688269805665904, 'y': 6, 'z': 'b'}. Best is trial 6 with value: 33.16463573709966.
[I 2024-11-22 05:51:14,363] Trial 9 finished with value: 70.6544452754111 and parameters: {'x': -2.579621149589819, 'y': 8, 'z': 'b'}. Best is trial 6 with value: 33.16463573709966.
[I 2024-11-22 05:51:14,363] Trial 10 finished with value: 18.441766084527824 and parameters: {'x': -4.294387742685542, 'y': 0, 'z': 'b'}. Best is trial 10 with value: 18.441766084527824.
[I 2024-11-22 05:51:14,364] Trial 11 finished with value: 223.69894826142337 and parameters: {'x': 4.8681565567906055, 'y': -10, 'z': 'a'}. Best is trial 10 with value: 18.441766084527824.
[I 2024-11-22 05:51:14,364] Trial 12 finished with value: 167.00019709649064 and parameters: {'x': 5.567782062589252, 'y': 6, 'z': 'c'}. Best is trial 10 with value: 18.441766084527824.
[I 2024-11-22 05:51:14,364] Trial 13 finished with value: 130.7131004827995 and parameters: {'x': -8.167808793232092, 'y': -8, 'z': 'b'}. Best is trial 10 with value: 18.441766084527824.
[I 2024-11-22 05:51:14,365] Trial 14 finished with value: 255.48046085185854 and parameters: {'x': -8.630206304130773, 'y': -9, 'z': 'a'}. Best is trial 10 with value: 18.441766084527824.
[I 2024-11-22 05:51:14,365] Trial 15 finished with value: 81.70990871778294 and parameters: {'x': 4.208314237052996, 'y': 8, 'z': 'b'}. Best is trial 10 with value: 18.441766084527824.
[I 2024-11-22 05:51:14,365] Trial 16 finished with value: 240.57798377123896 and parameters: {'x': 9.569638643712675, 'y': 7, 'z': 'a'}. Best is trial 10 with value: 18.441766084527824.
[I 2024-11-22 05:51:14,366] Trial 17 finished with value: 105.58951109878953 and parameters: {'x': -2.3642146896569134, 'y': -10, 'z': 'b'}. Best is trial 10 with value: 18.441766084527824.
[I 2024-11-22 05:51:14,366] Trial 18 finished with value: 113.22911642777973 and parameters: {'x': -3.6371852341858713, 'y': -10, 'z': 'b'}. Best is trial 10 with value: 18.441766084527824.
[I 2024-11-22 05:51:14,367] Trial 19 finished with value: 195.3115251916337 and parameters: {'x': 8.905701835994382, 'y': 4, 'z': 'a'}. Best is trial 10 with value: 18.441766084527824.
[I 2024-11-22 05:51:14,367] Trial 20 finished with value: 183.3901884306676 and parameters: {'x': 1.5460234250060996, 'y': -9, 'z': 'a'}. Best is trial 10 with value: 18.441766084527824.
[I 2024-11-22 05:51:14,367] Trial 21 finished with value: 139.90803317123368 and parameters: {'x': -3.8610922251655255, 'y': -5, 'z': 'c'}. Best is trial 10 with value: 18.441766084527824.
[I 2024-11-22 05:51:14,368] Trial 22 finished with value: 149.25049963108177 and parameters: {'x': 0.5004993816996866, 'y': -7, 'z': 'a'}. Best is trial 10 with value: 18.441766084527824.
[I 2024-11-22 05:51:14,368] Trial 23 finished with value: 110.60303768786676 and parameters: {'x': -1.2661112462444812, 'y': -3, 'z': 'a'}. Best is trial 10 with value: 18.441766084527824.
[I 2024-11-22 05:51:14,368] Trial 24 finished with value: 15.178576277347242 and parameters: {'x': -2.4856742098165725, 'y': 3, 'z': 'b'}. Best is trial 24 with value: 15.178576277347242.
[I 2024-11-22 05:51:14,369] Trial 25 finished with value: 78.91375126771428 and parameters: {'x': -8.826876642828667, 'y': -1, 'z': 'b'}. Best is trial 24 with value: 15.178576277347242.
[I 2024-11-22 05:51:14,369] Trial 26 finished with value: 150.06841441562057 and parameters: {'x': 1.0336413379991, 'y': -7, 'z': 'a'}. Best is trial 24 with value: 15.178576277347242.
[I 2024-11-22 05:51:14,370] Trial 27 finished with value: 131.6989006354076 and parameters: {'x': 4.764336326856826, 'y': 3, 'z': 'c'}. Best is trial 24 with value: 15.178576277347242.
[I 2024-11-22 05:51:14,370] Trial 28 finished with value: 7.587933422012623 and parameters: {'x': -2.754620377114172, 'y': 0, 'z': 'b'}. Best is trial 28 with value: 7.587933422012623.
[I 2024-11-22 05:51:14,370] Trial 29 finished with value: 65.35033272089478 and parameters: {'x': -7.506685868004254, 'y': -3, 'z': 'b'}. Best is trial 28 with value: 7.587933422012623.
[I 2024-11-22 05:51:14,371] Trial 30 finished with value: 158.77743481288158 and parameters: {'x': 8.819151592578596, 'y': -9, 'z': 'b'}. Best is trial 28 with value: 7.587933422012623.
[I 2024-11-22 05:51:14,371] Trial 31 finished with value: 197.6532482518602 and parameters: {'x': 4.08083916025371, 'y': -9, 'z': 'a'}. Best is trial 28 with value: 7.587933422012623.
[I 2024-11-22 05:51:14,371] Trial 32 finished with value: 145.04379437845708 and parameters: {'x': -6.636549885178072, 'y': -1, 'z': 'c'}. Best is trial 28 with value: 7.587933422012623.
[I 2024-11-22 05:51:14,372] Trial 33 finished with value: 125.01758819976232 and parameters: {'x': -0.13262051033799693, 'y': 5, 'z': 'a'}. Best is trial 28 with value: 7.587933422012623.
[I 2024-11-22 05:51:14,372] Trial 34 finished with value: 93.4033690368568 and parameters: {'x': 7.576501107823901, 'y': 6, 'z': 'b'}. Best is trial 28 with value: 7.587933422012623.
[I 2024-11-22 05:51:14,373] Trial 35 finished with value: 87.5885238961059 and parameters: {'x': -2.56681201027771, 'y': 9, 'z': 'b'}. Best is trial 28 with value: 7.587933422012623.
[I 2024-11-22 05:51:14,373] Trial 36 finished with value: 90.4807381252265 and parameters: {'x': -9.512136359684217, 'y': 0, 'z': 'b'}. Best is trial 28 with value: 7.587933422012623.
[I 2024-11-22 05:51:14,373] Trial 37 finished with value: 98.27532530672872 and parameters: {'x': 7.891471681931623, 'y': 6, 'z': 'b'}. Best is trial 28 with value: 7.587933422012623.
[I 2024-11-22 05:51:14,374] Trial 38 finished with value: 165.1352832924704 and parameters: {'x': 1.0654967350820037, 'y': -8, 'z': 'c'}. Best is trial 28 with value: 7.587933422012623.
[I 2024-11-22 05:51:14,374] Trial 39 finished with value: 190.95900364667108 and parameters: {'x': 5.1922060481717285, 'y': -8, 'z': 'a'}. Best is trial 28 with value: 7.587933422012623.
[I 2024-11-22 05:51:14,374] Trial 40 finished with value: 161.88744131720796 and parameters: {'x': 3.5899082602774044, 'y': -7, 'z': 'a'}. Best is trial 28 with value: 7.587933422012623.
[I 2024-11-22 05:51:14,375] Trial 41 finished with value: 151.49803839436152 and parameters: {'x': 3.9367548049582055, 'y': 6, 'z': 'c'}. Best is trial 28 with value: 7.587933422012623.
[I 2024-11-22 05:51:14,375] Trial 42 finished with value: 88.34257254570029 and parameters: {'x': 7.958804718404661, 'y': -5, 'z': 'b'}. Best is trial 28 with value: 7.587933422012623.
[I 2024-11-22 05:51:14,376] Trial 43 finished with value: 142.98110566262747 and parameters: {'x': 6.555997686289057, 'y': -10, 'z': 'b'}. Best is trial 28 with value: 7.587933422012623.
[I 2024-11-22 05:51:14,376] Trial 44 finished with value: 298.72893056396924 and parameters: {'x': -9.93624328224552, 'y': -10, 'z': 'a'}. Best is trial 28 with value: 7.587933422012623.
[I 2024-11-22 05:51:14,376] Trial 45 finished with value: 22.072948842585596 and parameters: {'x': 4.251229097871061, 'y': 2, 'z': 'b'}. Best is trial 28 with value: 7.587933422012623.
[I 2024-11-22 05:51:14,377] Trial 46 finished with value: 132.29597742711974 and parameters: {'x': -4.826590662892363, 'y': 3, 'z': 'a'}. Best is trial 28 with value: 7.587933422012623.
[I 2024-11-22 05:51:14,377] Trial 47 finished with value: 25.863577547570863 and parameters: {'x': -3.140633303582394, 'y': 4, 'z': 'b'}. Best is trial 28 with value: 7.587933422012623.
[I 2024-11-22 05:51:14,377] Trial 48 finished with value: 161.90599421426015 and parameters: {'x': 7.2736506799722065, 'y': 3, 'z': 'a'}. Best is trial 28 with value: 7.587933422012623.
[I 2024-11-22 05:51:14,378] Trial 49 finished with value: 126.30815499836265 and parameters: {'x': 1.1437460375287234, 'y': 5, 'z': 'c'}. Best is trial 28 with value: 7.587933422012623.
[I 2024-11-22 05:51:14,378] Trial 50 finished with value: 164.71002303621404 and parameters: {'x': 0.8426286466849113, 'y': -8, 'z': 'a'}. Best is trial 28 with value: 7.587933422012623.
[I 2024-11-22 05:51:14,379] Trial 51 finished with value: 187.7534129289902 and parameters: {'x': 8.470738629481506, 'y': 4, 'z': 'a'}. Best is trial 28 with value: 7.587933422012623.
[I 2024-11-22 05:51:14,379] Trial 52 finished with value: 228.05356353757276 and parameters: {'x': 8.003347020938975, 'y': 8, 'z': 'c'}. Best is trial 28 with value: 7.587933422012623.
[I 2024-11-22 05:51:14,379] Trial 53 finished with value: 117.72529554709473 and parameters: {'x': -1.3135050616936113, 'y': -4, 'z': 'c'}. Best is trial 28 with value: 7.587933422012623.
[I 2024-11-22 05:51:14,380] Trial 54 finished with value: 54.98179190480363 and parameters: {'x': -6.780987531680296, 'y': -3, 'z': 'b'}. Best is trial 28 with value: 7.587933422012623.
[I 2024-11-22 05:51:14,380] Trial 55 finished with value: 124.13225784927295 and parameters: {'x': 4.912459450140322, 'y': 0, 'z': 'c'}. Best is trial 28 with value: 7.587933422012623.
[I 2024-11-22 05:51:14,380] Trial 56 finished with value: 47.622098006886766 and parameters: {'x': -5.62335291502203, 'y': 4, 'z': 'b'}. Best is trial 28 with value: 7.587933422012623.
[I 2024-11-22 05:51:14,381] Trial 57 finished with value: 199.27355168521416 and parameters: {'x': -5.939154122029007, 'y': -8, 'z': 'a'}. Best is trial 28 with value: 7.587933422012623.
[I 2024-11-22 05:51:14,381] Trial 58 finished with value: 187.13899696104613 and parameters: {'x': -7.15115354058673, 'y': 6, 'z': 'a'}. Best is trial 28 with value: 7.587933422012623.
[I 2024-11-22 05:51:14,382] Trial 59 finished with value: 153.99935839769728 and parameters: {'x': 9.486799165034395, 'y': 8, 'z': 'b'}. Best is trial 28 with value: 7.587933422012623.
[I 2024-11-22 05:51:14,382] Trial 60 finished with value: 1.222829948521289 and parameters: {'x': 0.47204867177155485, 'y': -1, 'z': 'b'}. Best is trial 60 with value: 1.222829948521289.
[I 2024-11-22 05:51:14,382] Trial 61 finished with value: 183.10825041381747 and parameters: {'x': 5.840226914582811, 'y': -7, 'z': 'a'}. Best is trial 60 with value: 1.222829948521289.
[I 2024-11-22 05:51:14,383] Trial 62 finished with value: 206.4962898528896 and parameters: {'x': 6.518917843698414, 'y': 8, 'z': 'a'}. Best is trial 60 with value: 1.222829948521289.
[I 2024-11-22 05:51:14,383] Trial 63 finished with value: 141.94741917414035 and parameters: {'x': -6.4766827291554385, 'y': 0, 'z': 'a'}. Best is trial 60 with value: 1.222829948521289.
[I 2024-11-22 05:51:14,383] Trial 64 finished with value: 184.86555559456067 and parameters: {'x': 5.98878581972679, 'y': -7, 'z': 'c'}. Best is trial 60 with value: 1.222829948521289.
[I 2024-11-22 05:51:14,384] Trial 65 finished with value: 233.988074617893 and parameters: {'x': 9.218897689956918, 'y': -7, 'z': 'c'}. Best is trial 60 with value: 1.222829948521289.
[I 2024-11-22 05:51:14,384] Trial 66 finished with value: 53.87817321429241 and parameters: {'x': 5.373841569519184, 'y': -5, 'z': 'b'}. Best is trial 60 with value: 1.222829948521289.
[I 2024-11-22 05:51:14,385] Trial 67 finished with value: 183.61593719882217 and parameters: {'x': 6.900430218386543, 'y': 6, 'z': 'a'}. Best is trial 60 with value: 1.222829948521289.
[I 2024-11-22 05:51:14,385] Trial 68 finished with value: 187.58208768272854 and parameters: {'x': 4.856139174563323, 'y': -8, 'z': 'a'}. Best is trial 60 with value: 1.222829948521289.
[I 2024-11-22 05:51:14,385] Trial 69 finished with value: 107.53394686539569 and parameters: {'x': -2.556158615069826, 'y': 1, 'z': 'a'}. Best is trial 60 with value: 1.222829948521289.
[I 2024-11-22 05:51:14,386] Trial 70 finished with value: 64.31359414571095 and parameters: {'x': -3.9132587629379874, 'y': 7, 'z': 'b'}. Best is trial 60 with value: 1.222829948521289.
[I 2024-11-22 05:51:14,386] Trial 71 finished with value: 14.458677807053942 and parameters: {'x': 3.2339879107773335, 'y': 2, 'z': 'b'}. Best is trial 60 with value: 1.222829948521289.
[I 2024-11-22 05:51:14,386] Trial 72 finished with value: 200.22572610282214 and parameters: {'x': 9.551215948915726, 'y': 3, 'z': 'c'}. Best is trial 60 with value: 1.222829948521289.
[I 2024-11-22 05:51:14,387] Trial 73 finished with value: 172.60916337612792 and parameters: {'x': 8.52110106594963, 'y': -10, 'z': 'b'}. Best is trial 60 with value: 1.222829948521289.
[I 2024-11-22 05:51:14,387] Trial 74 finished with value: 27.82915892614176 and parameters: {'x': 1.6820103822930932, 'y': -5, 'z': 'b'}. Best is trial 60 with value: 1.222829948521289.
[I 2024-11-22 05:51:14,388] Trial 75 finished with value: 132.77916976537983 and parameters: {'x': -5.364622052426419, 'y': 2, 'z': 'c'}. Best is trial 60 with value: 1.222829948521289.
[I 2024-11-22 05:51:14,388] Trial 76 finished with value: 127.95580235566706 and parameters: {'x': -3.4577163497989627, 'y': 4, 'z': 'c'}. Best is trial 60 with value: 1.222829948521289.
[I 2024-11-22 05:51:14,388] Trial 77 finished with value: 232.22799008797 and parameters: {'x': -9.809586642054292, 'y': -6, 'z': 'a'}. Best is trial 60 with value: 1.222829948521289.
[I 2024-11-22 05:51:14,389] Trial 78 finished with value: 88.84768624204695 and parameters: {'x': -9.372709653139104, 'y': -1, 'z': 'b'}. Best is trial 60 with value: 1.222829948521289.
[I 2024-11-22 05:51:14,389] Trial 79 finished with value: 143.7979890677654 and parameters: {'x': 4.335664778066381, 'y': -5, 'z': 'c'}. Best is trial 60 with value: 1.222829948521289.
[I 2024-11-22 05:51:14,389] Trial 80 finished with value: 64.02240933055936 and parameters: {'x': 0.1496974634366346, 'y': -8, 'z': 'b'}. Best is trial 60 with value: 1.222829948521289.
[I 2024-11-22 05:51:14,390] Trial 81 finished with value: 212.5394942117111 and parameters: {'x': 9.356254283189994, 'y': 5, 'z': 'c'}. Best is trial 60 with value: 1.222829948521289.
[I 2024-11-22 05:51:14,390] Trial 82 finished with value: 196.43118944923842 and parameters: {'x': 7.773750024874637, 'y': 6, 'z': 'a'}. Best is trial 60 with value: 1.222829948521289.
[I 2024-11-22 05:51:14,391] Trial 83 finished with value: 140.96189891407607 and parameters: {'x': 3.9952345255411554, 'y': -5, 'z': 'a'}. Best is trial 60 with value: 1.222829948521289.
[I 2024-11-22 05:51:14,391] Trial 84 finished with value: 136.53039365303368 and parameters: {'x': 0.7282813007579527, 'y': 6, 'z': 'a'}. Best is trial 60 with value: 1.222829948521289.
[I 2024-11-22 05:51:14,391] Trial 85 finished with value: 181.73467234673134 and parameters: {'x': 7.53224218587874, 'y': 5, 'z': 'c'}. Best is trial 60 with value: 1.222829948521289.
[I 2024-11-22 05:51:14,392] Trial 86 finished with value: 212.4044204318032 and parameters: {'x': 7.9626892713330975, 'y': -7, 'z': 'c'}. Best is trial 60 with value: 1.222829948521289.
[I 2024-11-22 05:51:14,392] Trial 87 finished with value: 49.27023012109825 and parameters: {'x': -0.5198366292386947, 'y': -7, 'z': 'b'}. Best is trial 60 with value: 1.222829948521289.
[I 2024-11-22 05:51:14,393] Trial 88 finished with value: 106.4597211662885 and parameters: {'x': -1.5683498226762111, 'y': 2, 'z': 'a'}. Best is trial 60 with value: 1.222829948521289.
[I 2024-11-22 05:51:14,393] Trial 89 finished with value: 135.36866179566255 and parameters: {'x': -5.947155773616708, 'y': 0, 'z': 'a'}. Best is trial 60 with value: 1.222829948521289.
[I 2024-11-22 05:51:14,393] Trial 90 finished with value: 132.49689244338091 and parameters: {'x': 5.338248068737618, 'y': 2, 'z': 'c'}. Best is trial 60 with value: 1.222829948521289.
[I 2024-11-22 05:51:14,394] Trial 91 finished with value: 230.6872795505166 and parameters: {'x': -5.53961005401252, 'y': -10, 'z': 'c'}. Best is trial 60 with value: 1.222829948521289.
[I 2024-11-22 05:51:14,394] Trial 92 finished with value: 81.09782942971748 and parameters: {'x': 8.949739070482305, 'y': -1, 'z': 'b'}. Best is trial 60 with value: 1.222829948521289.
[I 2024-11-22 05:51:14,394] Trial 93 finished with value: 57.8225804435946 and parameters: {'x': 5.729099444379946, 'y': -5, 'z': 'b'}. Best is trial 60 with value: 1.222829948521289.
[I 2024-11-22 05:51:14,395] Trial 94 finished with value: 108.29531828714377 and parameters: {'x': 8.502665363704711, 'y': -6, 'z': 'b'}. Best is trial 60 with value: 1.222829948521289.
[I 2024-11-22 05:51:14,395] Trial 95 finished with value: 55.86655772460287 and parameters: {'x': 5.555767968931287, 'y': 5, 'z': 'b'}. Best is trial 60 with value: 1.222829948521289.
[I 2024-11-22 05:51:14,396] Trial 96 finished with value: 253.45865091059702 and parameters: {'x': -7.311542307242503, 'y': -10, 'z': 'c'}. Best is trial 60 with value: 1.222829948521289.
[I 2024-11-22 05:51:14,396] Trial 97 finished with value: 116.76091508262357 and parameters: {'x': -0.8723044666993136, 'y': -4, 'z': 'c'}. Best is trial 60 with value: 1.222829948521289.
[I 2024-11-22 05:51:14,396] Trial 98 finished with value: 117.33888442262788 and parameters: {'x': -1.1571017339144731, 'y': 4, 'z': 'c'}. Best is trial 60 with value: 1.222829948521289.
[I 2024-11-22 05:51:14,397] Trial 99 finished with value: 20.336444403759202 and parameters: {'x': 3.3669636772259963, 'y': -3, 'z': 'b'}. Best is trial 60 with value: 1.222829948521289.

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': 0.47204867177155485, 'y': -1, 'z': 'b'}, Best value: 1.222829948521289

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 2024-11-22 05:51:14,398] A new study created in memory with name: no-name-8bd01b9c-07ef-4c00-ba83-b007f832c56e
[I 2024-11-22 05:51:14,398] Trial 0 finished with value: 275.06257791494676 and parameters: {'x': 9.698586387455997, 'y': -9, 'z': 'a'}. Best is trial 0 with value: 275.06257791494676.
[I 2024-11-22 05:51:14,399] Trial 1 finished with value: 205.56619948933204 and parameters: {'x': -9.463942069208372, 'y': 4, 'z': 'a'}. Best is trial 1 with value: 205.56619948933204.
[I 2024-11-22 05:51:14,399] Trial 2 finished with value: 166.08128819851868 and parameters: {'x': 1.4426670435407711, 'y': -8, 'z': 'a'}. Best is trial 2 with value: 166.08128819851868.
[I 2024-11-22 05:51:14,399] Trial 3 finished with value: 199.4185021976397 and parameters: {'x': -9.920609971047128, 'y': 1, 'z': 'a'}. Best is trial 2 with value: 166.08128819851868.
[I 2024-11-22 05:51:14,400] Trial 4 finished with value: 165.35479948900172 and parameters: {'x': -6.352542757746833, 'y': -5, 'z': 'a'}. Best is trial 4 with value: 165.35479948900172.
[I 2024-11-22 05:51:14,400] Trial 5 finished with value: 25.03975617418837 and parameters: {'x': 0.1993895037066089, 'y': -5, 'z': 'b'}. Best is trial 5 with value: 25.03975617418837.
[I 2024-11-22 05:51:14,400] Trial 6 finished with value: 162.66054732558447 and parameters: {'x': 9.932801584929827, 'y': 8, 'z': 'b'}. Best is trial 5 with value: 25.03975617418837.
[I 2024-11-22 05:51:14,400] Trial 7 finished with value: 64.97322313337725 and parameters: {'x': 6.32243806876566, 'y': 5, 'z': 'b'}. Best is trial 5 with value: 25.03975617418837.
[I 2024-11-22 05:51:14,401] Trial 8 finished with value: 193.12549243970892 and parameters: {'x': 3.482167778799427, 'y': 9, 'z': 'a'}. Best is trial 5 with value: 25.03975617418837.
[I 2024-11-22 05:51:14,401] Trial 9 finished with value: 191.36852539007162 and parameters: {'x': 3.2200194704491523, 'y': 9, 'z': 'c'}. Best is trial 5 with value: 25.03975617418837.
[I 2024-11-22 05:51:14,401] Trial 10 finished with value: 233.19105190905924 and parameters: {'x': 8.318115886969792, 'y': 8, 'z': 'c'}. Best is trial 5 with value: 25.03975617418837.
[I 2024-11-22 05:51:14,402] Trial 11 finished with value: 202.9304931558949 and parameters: {'x': -1.7118683231764358, 'y': -10, 'z': 'c'}. Best is trial 5 with value: 25.03975617418837.
[I 2024-11-22 05:51:14,402] Trial 12 finished with value: 12.579350699291252 and parameters: {'x': 3.4028445011917974, 'y': 1, 'z': 'b'}. Best is trial 12 with value: 12.579350699291252.
[I 2024-11-22 05:51:14,402] Trial 13 finished with value: 172.8398028553757 and parameters: {'x': -4.882602057855594, 'y': 7, 'z': 'c'}. Best is trial 12 with value: 12.579350699291252.
[I 2024-11-22 05:51:14,403] Trial 14 finished with value: 182.54650648877487 and parameters: {'x': 1.2435861404723347, 'y': -9, 'z': 'c'}. Best is trial 12 with value: 12.579350699291252.
[I 2024-11-22 05:51:14,403] Trial 15 finished with value: 80.50278679923144 and parameters: {'x': 4.062362219107429, 'y': -8, 'z': 'b'}. Best is trial 12 with value: 12.579350699291252.
[I 2024-11-22 05:51:14,403] Trial 16 finished with value: 184.08310563500896 and parameters: {'x': 8.665050815489138, 'y': -3, 'z': 'c'}. Best is trial 12 with value: 12.579350699291252.
[I 2024-11-22 05:51:14,404] Trial 17 finished with value: 109.00984016740664 and parameters: {'x': -0.09919761794837711, 'y': 3, 'z': 'a'}. Best is trial 12 with value: 12.579350699291252.
[I 2024-11-22 05:51:14,404] Trial 18 finished with value: 241.99648608507553 and parameters: {'x': 6.480469588314996, 'y': -10, 'z': 'a'}. Best is trial 12 with value: 12.579350699291252.
[I 2024-11-22 05:51:14,404] Trial 19 finished with value: 210.0899243078511 and parameters: {'x': 9.699996098342055, 'y': -4, 'z': 'c'}. Best is trial 12 with value: 12.579350699291252.
[I 2024-11-22 05:51:14,405] Trial 20 finished with value: 153.96963053264102 and parameters: {'x': 5.382344334269316, 'y': -5, 'z': 'a'}. Best is trial 12 with value: 12.579350699291252.
[I 2024-11-22 05:51:14,405] Trial 21 finished with value: 101.37072008072664 and parameters: {'x': -0.6088678680359454, 'y': 1, 'z': 'c'}. Best is trial 12 with value: 12.579350699291252.
[I 2024-11-22 05:51:14,405] Trial 22 finished with value: 44.810078009265695 and parameters: {'x': 6.618918190253275, 'y': 1, 'z': 'b'}. Best is trial 12 with value: 12.579350699291252.
[I 2024-11-22 05:51:14,405] Trial 23 finished with value: 174.8749568212908 and parameters: {'x': -7.673001812934153, 'y': -4, 'z': 'c'}. Best is trial 12 with value: 12.579350699291252.
[I 2024-11-22 05:51:14,406] Trial 24 finished with value: 170.1321409838554 and parameters: {'x': -8.314574010967453, 'y': 1, 'z': 'a'}. Best is trial 12 with value: 12.579350699291252.
[I 2024-11-22 05:51:14,406] Trial 25 finished with value: 166.39120887048395 and parameters: {'x': -7.898810598468858, 'y': -2, 'z': 'a'}. Best is trial 12 with value: 12.579350699291252.
[I 2024-11-22 05:51:14,406] Trial 26 finished with value: 261.45910875753725 and parameters: {'x': 9.872138003367724, 'y': 8, 'z': 'a'}. Best is trial 12 with value: 12.579350699291252.
[I 2024-11-22 05:51:14,407] Trial 27 finished with value: 200.5818996226213 and parameters: {'x': 6.048297249856468, 'y': -8, 'z': 'c'}. Best is trial 12 with value: 12.579350699291252.
[I 2024-11-22 05:51:14,407] Trial 28 finished with value: 104.11236378162408 and parameters: {'x': -0.335207072753672, 'y': 2, 'z': 'a'}. Best is trial 12 with value: 12.579350699291252.
[I 2024-11-22 05:51:14,407] Trial 29 finished with value: 102.94576614649507 and parameters: {'x': 1.394907217880485, 'y': -1, 'z': 'a'}. Best is trial 12 with value: 12.579350699291252.
[I 2024-11-22 05:51:14,408] Trial 30 finished with value: 222.25503012707767 and parameters: {'x': 6.423007872257177, 'y': 9, 'z': 'c'}. Best is trial 12 with value: 12.579350699291252.
[I 2024-11-22 05:51:14,408] Trial 31 finished with value: 205.78282863820425 and parameters: {'x': 9.47538013159389, 'y': -4, 'z': 'c'}. Best is trial 12 with value: 12.579350699291252.
[I 2024-11-22 05:51:14,408] Trial 32 finished with value: 69.27749251268445 and parameters: {'x': 7.763858094574143, 'y': 3, 'z': 'b'}. Best is trial 12 with value: 12.579350699291252.
[I 2024-11-22 05:51:14,409] Trial 33 finished with value: 133.4328938084381 and parameters: {'x': 2.9039445257163763, 'y': 5, 'z': 'c'}. Best is trial 12 with value: 12.579350699291252.
[I 2024-11-22 05:51:14,409] Trial 34 finished with value: 113.93363250915604 and parameters: {'x': 3.151766569585387, 'y': -2, 'z': 'c'}. Best is trial 12 with value: 12.579350699291252.
[I 2024-11-22 05:51:14,409] Trial 35 finished with value: 116.22519707646737 and parameters: {'x': -0.4745493403929366, 'y': 4, 'z': 'a'}. Best is trial 12 with value: 12.579350699291252.
[I 2024-11-22 05:51:14,410] Trial 36 finished with value: 217.67754158394294 and parameters: {'x': 7.326495859818863, 'y': -8, 'z': 'a'}. Best is trial 12 with value: 12.579350699291252.
[I 2024-11-22 05:51:14,410] Trial 37 finished with value: 167.65020655045578 and parameters: {'x': -1.910551373414437, 'y': -8, 'z': 'a'}. Best is trial 12 with value: 12.579350699291252.
[I 2024-11-22 05:51:14,410] Trial 38 finished with value: 49.71580512242629 and parameters: {'x': 3.703485536953842, 'y': -6, 'z': 'b'}. Best is trial 12 with value: 12.579350699291252.
[I 2024-11-22 05:51:14,410] Trial 39 finished with value: 129.9423924891495 and parameters: {'x': -2.223149227818391, 'y': -5, 'z': 'c'}. Best is trial 12 with value: 12.579350699291252.
[I 2024-11-22 05:51:14,411] Trial 40 finished with value: 172.90641280743063 and parameters: {'x': 8.538525212671718, 'y': 0, 'z': 'a'}. Best is trial 12 with value: 12.579350699291252.
[I 2024-11-22 05:51:14,411] Trial 41 finished with value: 159.09773422951992 and parameters: {'x': -7.622186971566618, 'y': 1, 'z': 'c'}. Best is trial 12 with value: 12.579350699291252.
[I 2024-11-22 05:51:14,411] Trial 42 finished with value: 136.02010032459634 and parameters: {'x': -0.14177561354598645, 'y': 6, 'z': 'a'}. Best is trial 12 with value: 12.579350699291252.
[I 2024-11-22 05:51:14,412] Trial 43 finished with value: 117.79260838529783 and parameters: {'x': -1.3388832605189407, 'y': -4, 'z': 'a'}. Best is trial 12 with value: 12.579350699291252.
[I 2024-11-22 05:51:14,412] Trial 44 finished with value: 265.31205173170605 and parameters: {'x': 9.182159426393447, 'y': 9, 'z': 'c'}. Best is trial 12 with value: 12.579350699291252.
[I 2024-11-22 05:51:14,412] Trial 45 finished with value: 171.83462890146836 and parameters: {'x': 8.236178051831345, 'y': 2, 'z': 'a'}. Best is trial 12 with value: 12.579350699291252.
[I 2024-11-22 05:51:14,413] Trial 46 finished with value: 182.9661969088125 and parameters: {'x': -4.35501973690275, 'y': 8, 'z': 'c'}. Best is trial 12 with value: 12.579350699291252.
[I 2024-11-22 05:51:14,413] Trial 47 finished with value: 168.7137483891025 and parameters: {'x': -7.260423430427629, 'y': -4, 'z': 'a'}. Best is trial 12 with value: 12.579350699291252.
[I 2024-11-22 05:51:14,413] Trial 48 finished with value: 4.175577228081009 and parameters: {'x': 0.4190193648043117, 'y': -2, 'z': 'b'}. Best is trial 48 with value: 4.175577228081009.
[I 2024-11-22 05:51:14,414] Trial 49 finished with value: 19.15138299729329 and parameters: {'x': -3.1861235062836606, 'y': -3, 'z': 'b'}. Best is trial 48 with value: 4.175577228081009.
[I 2024-11-22 05:51:14,414] Trial 50 finished with value: 167.69637402850287 and parameters: {'x': 7.981000816219911, 'y': 2, 'z': 'a'}. Best is trial 48 with value: 4.175577228081009.
[I 2024-11-22 05:51:14,414] Trial 51 finished with value: 1.704967534744017 and parameters: {'x': 0.8396234481861597, 'y': -1, 'z': 'b'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,415] Trial 52 finished with value: 210.73621428404954 and parameters: {'x': -9.733253016543316, 'y': 4, 'z': 'a'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,415] Trial 53 finished with value: 160.5589642222664 and parameters: {'x': -5.963133758542265, 'y': 5, 'z': 'a'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,415] Trial 54 finished with value: 52.14128351874976 and parameters: {'x': -4.017621624636865, 'y': 6, 'z': 'b'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,415] Trial 55 finished with value: 163.9699439169838 and parameters: {'x': 3.86910117688641, 'y': -7, 'z': 'a'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,416] Trial 56 finished with value: 275.13599117088313 and parameters: {'x': -9.70237038928545, 'y': -9, 'z': 'a'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,416] Trial 57 finished with value: 238.6836584172517 and parameters: {'x': 6.2196188321513475, 'y': -10, 'z': 'a'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,417] Trial 58 finished with value: 24.279594575337278 and parameters: {'x': -4.824893219060633, 'y': 1, 'z': 'b'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,417] Trial 59 finished with value: 27.787171905221697 and parameters: {'x': -1.6694825261804027, 'y': -5, 'z': 'b'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,417] Trial 60 finished with value: 68.2123546892867 and parameters: {'x': 2.0524021753269253, 'y': -8, 'z': 'b'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,417] Trial 61 finished with value: 164.24596395985364 and parameters: {'x': 0.495947537400518, 'y': 8, 'z': 'a'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,418] Trial 62 finished with value: 13.103554589817273 and parameters: {'x': -3.479016325028854, 'y': -1, 'z': 'b'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,418] Trial 63 finished with value: 148.14276926335532 and parameters: {'x': -3.4846476526838854, 'y': -6, 'z': 'a'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,418] Trial 64 finished with value: 232.03140792794954 and parameters: {'x': 8.248115416745183, 'y': -8, 'z': 'a'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,419] Trial 65 finished with value: 144.98712134629938 and parameters: {'x': 6.402118504549833, 'y': -2, 'z': 'a'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,419] Trial 66 finished with value: 105.6018262559994 and parameters: {'x': 2.366817748792542, 'y': 0, 'z': 'a'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,420] Trial 67 finished with value: 198.2279233274245 and parameters: {'x': -7.0162613497092945, 'y': -7, 'z': 'c'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,420] Trial 68 finished with value: 193.9230982183717 and parameters: {'x': 7.610722581882204, 'y': -6, 'z': 'a'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,420] Trial 69 finished with value: 186.156909340575 and parameters: {'x': -2.270882942948626, 'y': -9, 'z': 'c'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,421] Trial 70 finished with value: 215.6152773510085 and parameters: {'x': -8.161818262556972, 'y': -7, 'z': 'a'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,421] Trial 71 finished with value: 103.71264228793527 and parameters: {'x': -9.73204204100739, 'y': 3, 'z': 'b'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,421] Trial 72 finished with value: 201.57057823103992 and parameters: {'x': -1.2532271266773307, 'y': -10, 'z': 'c'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,422] Trial 73 finished with value: 233.61311259334946 and parameters: {'x': -5.797681656778808, 'y': -10, 'z': 'a'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,422] Trial 74 finished with value: 126.2396642602936 and parameters: {'x': 3.1999475402408706, 'y': 4, 'z': 'c'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,422] Trial 75 finished with value: 145.13965890257458 and parameters: {'x': 6.4140204943993275, 'y': 2, 'z': 'a'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,422] Trial 76 finished with value: 59.15168224285809 and parameters: {'x': -4.8116195031255415, 'y': 6, 'z': 'b'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,423] Trial 77 finished with value: 33.25190688666765 and parameters: {'x': -5.766446643008816, 'y': 0, 'z': 'b'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,423] Trial 78 finished with value: 117.22228446181713 and parameters: {'x': 4.149974031462984, 'y': -10, 'z': 'b'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,423] Trial 79 finished with value: 58.38976308332145 and parameters: {'x': -4.7317822311811275, 'y': -6, 'z': 'b'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,424] Trial 80 finished with value: 207.32666689628746 and parameters: {'x': -2.706781649170738, 'y': -10, 'z': 'a'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,424] Trial 81 finished with value: 55.84186987194411 and parameters: {'x': 7.472741790798349, 'y': 0, 'z': 'b'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,424] Trial 82 finished with value: 145.24419412065157 and parameters: {'x': -4.499354856048985, 'y': 5, 'z': 'c'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,425] Trial 83 finished with value: 180.28246521451294 and parameters: {'x': 4.035153679169227, 'y': 8, 'z': 'a'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,425] Trial 84 finished with value: 71.13331535419252 and parameters: {'x': 8.193492256308815, 'y': 2, 'z': 'b'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,425] Trial 85 finished with value: 181.74421321232995 and parameters: {'x': -0.8626779308235317, 'y': -9, 'z': 'a'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,426] Trial 86 finished with value: 117.88165765233919 and parameters: {'x': 2.980211008022618, 'y': -3, 'z': 'a'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,426] Trial 87 finished with value: 141.92549607393826 and parameters: {'x': 2.4342341863383368, 'y': -6, 'z': 'c'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,426] Trial 88 finished with value: 183.02476568558615 and parameters: {'x': 6.857460585784374, 'y': 6, 'z': 'a'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,427] Trial 89 finished with value: 64.30741355226655 and parameters: {'x': -0.554448872545116, 'y': 8, 'z': 'b'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,427] Trial 90 finished with value: 186.56239859161496 and parameters: {'x': 2.3584737843815358, 'y': 9, 'z': 'a'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,427] Trial 91 finished with value: 156.93223912365062 and parameters: {'x': 6.397830813928312, 'y': -4, 'z': 'c'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,428] Trial 92 finished with value: 70.72897259624318 and parameters: {'x': 2.5940263291345325, 'y': 8, 'z': 'b'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,428] Trial 93 finished with value: 204.70931021317904 and parameters: {'x': 9.783113523473958, 'y': -3, 'z': 'c'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,428] Trial 94 finished with value: 116.04089311425085 and parameters: {'x': -0.2022204595258703, 'y': -4, 'z': 'c'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,428] Trial 95 finished with value: 129.7010397231661 and parameters: {'x': 2.168188119874774, 'y': 5, 'z': 'a'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,429] Trial 96 finished with value: 149.6038781019435 and parameters: {'x': 0.7770959412733447, 'y': -7, 'z': 'a'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,429] Trial 97 finished with value: 175.76379181181852 and parameters: {'x': -7.124871354053946, 'y': 5, 'z': 'c'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,429] Trial 98 finished with value: 46.66412542136493 and parameters: {'x': 4.654473699717824, 'y': 5, 'z': 'b'}. Best is trial 51 with value: 1.704967534744017.
[I 2024-11-22 05:51:14,430] Trial 99 finished with value: 202.02841084566717 and parameters: {'x': 1.4242228918491584, 'y': -10, 'z': 'c'}. Best is trial 51 with value: 1.704967534744017.

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

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

Gallery generated by Sphinx-Gallery