Skip to content

Improve time complexity of IntersectionSearchSpace#5982

Merged
c-bata merged 1 commit intooptuna:masterfrom
GittyHarsha:master
Feb 19, 2025
Merged

Improve time complexity of IntersectionSearchSpace#5982
c-bata merged 1 commit intooptuna:masterfrom
GittyHarsha:master

Conversation

@GittyHarsha
Copy link
Copy Markdown
Contributor

Motivation

Fix #5949

Description of the changes

Removed this line

trials_of_interest = [trial for trial in trials if trial.state in states_of_interest]

Added filtering logic inside the for-loop so that the loop breaks to avoid putting filter checks on the trials with trial.number less than cached_trial_number

@not522
Copy link
Copy Markdown
Member

not522 commented Feb 17, 2025

Thank you for your PR!
This is just a comment unrelated to this PR, but updating your branch (GittyHarsha:master) will update the PR, so there's no need to close the previous PR #5981! (but let's keep working on it here!)

@c-bata
Copy link
Copy Markdown
Member

c-bata commented Feb 17, 2025

@sawa3030 @not522 Could you review this PR?

@GittyHarsha
Copy link
Copy Markdown
Contributor Author

Thanks. I'll keep that in mind.

@c-bata c-bata added the code-fix Change that does not change the behavior, such as code refactoring. label Feb 17, 2025
Copy link
Copy Markdown
Member

@not522 not522 left a comment

Choose a reason for hiding this comment

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

LGTM! I confirmed that this PR will speed up the following code.

import optuna

def objective(trial):
    return sum(trial.suggest_float(f"x{i}", 0, 1) ** 2 for i in range(10))

study = optuna.create_study(sampler=optuna.samplers.CmaEsSampler(seed=42))
study.optimize(objective, n_trials=10000)

master

real	1m15.972s
user	1m14.434s
sys	0m1.037s

PR

real	1m8.455s
user	1m7.028s
sys	0m1.076s

@sawa3030
Copy link
Copy Markdown
Collaborator

LGTM! I tested this in my local environment and confirmed that the PR will speed up the code @not522 provided above.

master
real 3m39.997s
user 3m39.561s
sys 0m2.473s

PR
real 3m23.284s
user 3m19.046s
sys 0m5.473s

@c-bata
Copy link
Copy Markdown
Member

c-bata commented Feb 19, 2025

Let me merge this PR since this PR got two approvals. @GittyHarsha Thank you for your contribution!

@c-bata c-bata added this to the v4.3.0 milestone Feb 19, 2025
@c-bata c-bata merged commit b5f8b03 into optuna:master Feb 19, 2025
14 checks passed
@not522 not522 changed the title Improve time complexity of IntersectionSearchSpace #5949 Improve time complexity of IntersectionSearchSpace Feb 20, 2025
@not522 not522 added enhancement Change that does not break compatibility and not affect public interfaces, but improves performance. and removed code-fix Change that does not change the behavior, such as code refactoring. labels Mar 5, 2025
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.

IntersectionSearchSpace is slow

4 participants