Skip to content

Remove find_or_raise_by_id in _set_trial_value_without_commit#6266

Merged
c-bata merged 2 commits intooptuna:masterfrom
not522:fix-set-trial-value
Sep 10, 2025
Merged

Remove find_or_raise_by_id in _set_trial_value_without_commit#6266
c-bata merged 2 commits intooptuna:masterfrom
not522:fix-set-trial-value

Conversation

@not522
Copy link
Copy Markdown
Member

@not522 not522 commented Sep 1, 2025

Motivation

RDBStorage uses find_or_raise_by_id to retrieve a TrialModel in _set_trial_value_without_commit, but it can be directly obtained from callers.

Description of the changes

By passing the trial model as an argument, this PR removes the need for find_or_raise_by_id in _set_trial_value_without_commit.

Benchmark

import optuna

def objective(trial: optuna.Trial) -> float:
    x = trial.suggest_float("x", -100, 100)
    y = trial.suggest_int("y", -100, 100)
    return x**2 + y**2

sampler = optuna.samplers.TPESampler(seed=42, multivariate=True, constant_liar=True)
study = optuna.create_study(sampler=sampler, storage="sqlite:///tmp.db")
study.optimize(objective, n_trials=1000)
master PR
12.307s 12.206s

@not522 not522 added the enhancement Change that does not break compatibility and not affect public interfaces, but improves performance. label Sep 1, 2025
@nabenabe0928
Copy link
Copy Markdown
Contributor

@sawa3030 @c-bata
Could you review this PR?

Copy link
Copy Markdown
Collaborator

@sawa3030 sawa3030 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Copy Markdown
Member

@c-bata c-bata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. LGTM!

@c-bata c-bata added this to the v4.6.0 milestone Sep 10, 2025
@c-bata c-bata merged commit 4422318 into optuna:master Sep 10, 2025
13 of 14 checks passed
@not522 not522 deleted the fix-set-trial-value branch September 10, 2025 05:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Change that does not break compatibility and not affect public interfaces, but improves performance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants