optuna.trial.create_trial(*, state: Optional[optuna.trial._state.TrialState] = None, value: Optional[float] = None, params: Optional[Dict[str, Any]] = None, distributions: Optional[Dict[str, optuna.distributions.BaseDistribution]] = None, user_attrs: Optional[Dict[str, Any]] = None, system_attrs: Optional[Dict[str, Any]] = None, intermediate_values: Optional[Dict[int, float]] = None) → optuna.trial._frozen.FrozenTrial[source]

Create a new FrozenTrial.


import optuna
from optuna.distributions import CategoricalDistribution
from optuna.distributions import UniformDistribution

trial = optuna.trial.create_trial(
    params={"x": 1.0, "y": 0},
        "x": UniformDistribution(0, 10),
        "y": CategoricalDistribution([-1, 0, 1]),

assert isinstance(trial, optuna.trial.FrozenTrial)
assert trial.value == 5.0
assert trial.params == {"x": 1.0, "y": 0}

See also

See add_trial() for how this function can be used to create a study from existing trials.


Please note that this is a low-level API. In general, trials that are passed to objective functions are created inside optimize().

  • state – Trial state.

  • value – Trial objective value. Must be specified if state is TrialState.COMPLETE.

  • params – Dictionary with suggested parameters of the trial.

  • distributions – Dictionary with parameter distributions of the trial.

  • user_attrs – Dictionary with user attributes.

  • system_attrs – Dictionary with system attributes. Should not have to be used for most users.

  • intermediate_values – Dictionary with intermediate objective values of the trial.


Created trial.


Added in v2.0.0 as an experimental feature. The interface may change in newer versions without prior notice. See https://github.com/optuna/optuna/releases/tag/v2.0.0.