Skip to content

Instantly share code, notes, and snippets.

@c-bata
Created July 17, 2024 09:53
Show Gist options
  • Save c-bata/6e6d829aa2062feda761a1d66fe308a5 to your computer and use it in GitHub Desktop.
Save c-bata/6e6d829aa2062feda761a1d66fe308a5 to your computer and use it in GitHub Desktop.
import numpy as np
from datetime import datetime
import optuna
import cProfile
import time
from optuna.visualization._rank import _get_rank_info
def sphere(trial: optuna.Trial) -> float:
X = np.asarray([trial.suggest_float(f"x{i}", -5, 5) for i in range(10)])
return np.sum(X ** 2)
study = optuna.create_study(sampler=optuna.samplers.RandomSampler(seed=1))
study.optimize(sphere, n_trials=10000)
profiler = cProfile.Profile()
profiler.runcall(_get_rank_info, study, None, None, "Objective Value")
profiler.dump_stats("./get_rank_info.stats")
@c-bata
Copy link
Author

c-bata commented Jul 17, 2024

$ git checkout master
$ git rev-parse HEAD
9b5c8635f3b1ef23c80a12cdafda4055490b72db
$ python cprofile_get_rank_info.py
$ gprof2dot -f pstats get_rank_info.stat | dot -Tpng -o get_rank_info.png

get_rank_info

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment