Skip to content

Commit

Permalink
Start updating Optuna example (#182)
Browse files Browse the repository at this point in the history
* Start updating Optuna example

* Add Optuna to test matrix

* Remove duplicate
  • Loading branch information
Lothiraldan authored Sep 10, 2024
1 parent e5b368e commit f29680e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
# coding: utf-8
from comet_ml import Experiment, login
from comet_ml import login

import optuna
from optuna_integration.comet import CometCallback

# Login to Comet if needed
login()

study = optuna.create_study()
comet = CometCallback(
study, project_name="comet-example-optuna-hello-world", metric_names=["score"]
)


@comet.track_in_comet()
def objective(trial):
x = trial.suggest_float("x", -10, 10)
objective = (x - 2) ** 2

experiment = Experiment(project_name="comet-example-optuna-hello-world")

experiment.log_optimization(
optimization_id=trial.study.study_name,
metric_name="objective",
metric_value=objective,
parameters={"x": x},
objective="minimize",
)

return objective


study = optuna.create_study()
study.optimize(objective, n_trials=20)
study.optimize(objective, n_trials=20, callbacks=[comet])

best_params = study.best_params
found_x = best_params["x"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
comet_ml>=3.33.10
optuna
optuna>=4.0.0
optuna-integration>=4.0.0

0 comments on commit f29680e

Please sign in to comment.