`get_all_study_summaries` ignores constraints when selecting `best_trial`
Author: AayushMainali-GithubCreated Aug 25, 2026Updated Aug 25, 2026
Expected behavior
StudySummary.best_trial should match Study.best_trial for constrained studies. Only feasible trials (all constraint values <= 0) should be considered.
If every complete trial is infeasible, best_trial should be None. Study.best_trial already raises ValueError in that case.
Environment
- Optuna version: 5.0.0.dev
- Python version: 3.14.7
- OS: Linux-6.1.177-224.371.amzn2023.x86_64-x86_64-with-glibc2.34
Error messages, stack traces, or logs
study.best_trial: {'x': 5.0} value=5.0 constraints={'c': 0.0}
summary.best_trial: {'x': -10.0} value=-10.0 constraints={'c': 15.0}Steps to reproduce
- Run the following:
import optuna
def objective(trial):
x = trial.suggest_float("x", -10, 10)
trial.set_constraint("c", 5 - x) # feasible iff x >= 5
return x
study = optuna.create_study(direction="minimize")
study.enqueue_trial({"x": -10.0}) # infeasible, better objective
study.enqueue_trial({"x": 5.0}) # feasible
study.optimize(objective, n_trials=2)
print("study.best_trial:", study.best_trial.params, study.best_trial.value, study.best_trial.constraints)
summary = optuna.get_all_study_summaries(study._storage)[0]
print("summary.best_trial:", summary.best_trial.params, summary.best_trial.value, summary.best_trial.constraints)Study.best_trialis the feasible trial (x=5.0).StudySummary.best_trialis the infeasible trial (x=-10.0).
Additional context (optional)
get_all_study_summaries picks best_trial with min/max over complete trials and does not filter infeasible trials. Reproduced with InMemoryStorage, sqlite, and JournalStorage.
Source: optuna/optuna