Skip to content

Instantly share code, notes, and snippets.

@crcrpar
Created December 20, 2020 07:15
Show Gist options
  • Save crcrpar/f22011c12b03608d424e2f7bf34cd671 to your computer and use it in GitHub Desktop.
Save crcrpar/f22011c12b03608d424e2f7bf34cd671 to your computer and use it in GitHub Desktop.
optuna ❯ python optuna_create_trial.py
Optuna version: 2.3.0
[I 2020-12-20 16:15:44,324] A new study created in memory with name: no-name-e5c3d5a2-c5b0-43a6-91d0-d20150726e9d
optuna_create_trial.py:12: ExperimentalWarning: create_trial is experimental (supported from v2.0.0). The interface can change in the future.
trial: optuna.trial.FrozenTrial = optuna.trial.create_trial(value=-80, params={"x": -5})
Traceback (most recent call last):
File "optuna_create_trial.py", line 20, in <module>
main()
File "optuna_create_trial.py", line 12, in main
trial: optuna.trial.FrozenTrial = optuna.trial.create_trial(value=-80, params={"x": -5})
File "/home/masaki/ghq/github.com/optuna/optuna-1/optuna/_experimental.py", line 68, in new_func
return func(*args, **kwargs) # type: ignore
File "/home/masaki/ghq/github.com/optuna/optuna-1/optuna/trial/_frozen.py", line 538, in create_trial
trial._validate()
File "/home/masaki/ghq/github.com/optuna/optuna-1/optuna/trial/_frozen.py", line 321, in _validate
set(self.params.keys()), set(self.distributions.keys())
ValueError: Inconsistent parameters {'x'} and distributions set().
import optuna
def objective(trial: optuna.trial.Trial) -> float:
x = trial.suggest_float("x", low=-2.0, high=2.0)
return x**3 + 3 * x**2 + 6 * x
def main():
study = optuna.create_study()
trial: optuna.trial.FrozenTrial = optuna.trial.create_trial(value=-80, params={"x": -5})
study.add_trial(trial)
study.optimize(objective, n_trials=10)
if __name__ == "__main__":
print(f"Optuna version: {optuna.__version__}")
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment