optuna.trial.FixedTrial

class optuna.trial.FixedTrial(params, number=0)[source]

A trial class which suggests a fixed value for each parameter.

This object has the same methods as Trial, and it suggests pre-defined parameter values. The parameter values can be determined at the construction of the FixedTrial object. In contrast to Trial, FixedTrial does not depend on Study, and it is useful for deploying optimization results.

Example

Evaluate an objective function with parameter values given by a user.

import optuna


def objective(trial):
    x = trial.suggest_float("x", -100, 100)
    y = trial.suggest_categorical("y", [-1, 0, 1])
    return x**2 + y


assert objective(optuna.trial.FixedTrial({"x": 1, "y": 0})) == 1

Note

Please refer to Trial for details of methods and properties.

Parameters:
  • params (dict[str, Any]) – A dictionary containing all parameters.

  • number (int) – A trial number. Defaults to 0.

Methods

report(value, step)

set_system_attr(key, value)

set_user_attr(key, value)

should_prune()

suggest_categorical()

suggest_discrete_uniform(name, low, high, q)

suggest_float(name, low, high, *[, step, log])

suggest_int(name, low, high, *[, step, log])

suggest_loguniform(name, low, high)

suggest_uniform(name, low, high)

Attributes

datetime_start

distributions

number

params

system_attrs

user_attrs

set_system_attr(key, value)[source]

Warning

Deprecated in v3.1.0. This feature will be removed in the future. The removal of this feature is currently scheduled for v5.0.0, but this schedule is subject to change. See https://github.com/optuna/optuna/releases/tag/v3.1.0.

Parameters:
Return type:

None

suggest_discrete_uniform(name, low, high, q)[source]

Warning

Deprecated in v3.0.0. This feature will be removed in the future. The removal of this feature is currently scheduled for v6.0.0, but this schedule is subject to change. See https://github.com/optuna/optuna/releases/tag/v3.0.0.

Use suggest_float(…, step=…) instead.

Parameters:
Return type:

float

suggest_loguniform(name, low, high)[source]

Warning

Deprecated in v3.0.0. This feature will be removed in the future. The removal of this feature is currently scheduled for v6.0.0, but this schedule is subject to change. See https://github.com/optuna/optuna/releases/tag/v3.0.0.

Use suggest_float(…, log=True) instead.

Parameters:
Return type:

float

suggest_uniform(name, low, high)[source]

Warning

Deprecated in v3.0.0. This feature will be removed in the future. The removal of this feature is currently scheduled for v6.0.0, but this schedule is subject to change. See https://github.com/optuna/optuna/releases/tag/v3.0.0.

Use suggest_float instead.

Parameters:
Return type:

float