Faster parent population trials lookup in NSGA-II sampler - #238
Merged
Conversation
c-bata
force-pushed
the
c-bata/nsgaii-fast-trial-number-lookup
branch
from
September 1, 2026 08:32
c75fbea to
708db2a
Compare
Co-authored-by: Hemmi Shinichi <shemmi@preferred.jp>
c-bata
force-pushed
the
c-bata/nsgaii-fast-trial-number-lookup
branch
from
September 1, 2026 09:58
708db2a to
14a7d15
Compare
Member
Author
|
I also executed the following benchmark to confirm that this PR does not change the behavior. import time
import rustuna
n_trials = 10000
def run_optimize():
def objective(trial: rustuna.Trial) -> tuple[float, float]:
x = trial.suggest_float("x", -15, 30)
y = trial.suggest_float("y", -15, 30)
v0 = 4 * x**2 + 4 * y**2
v1 = (x - 5) ** 2 + (y - 5) ** 2
trial.set_constraints({"c0": 1000 - v0})
return v0, v1
directions = ["minimize", "minimize"]
sampler = rustuna.samplers.NSGAIISampler(seed=1)
study = rustuna.create_study(sampler=sampler, directions=directions)
study.optimize(objective, n_trials=n_trials)
return study
def main():
for _ in range(3):
start = time.time()
study = run_optimize()
elapsed_rustuna = time.time() - start
assert len(study.get_trials(states=[rustuna.trial.TrialState.COMPLETE])) == n_trials
print(f"Rustuna\telapsed={elapsed_rustuna:.3f}\tbest_trials[0].values={study.best_trials[0].values}")
if __name__ == "__main__":
main()
This PR: |
c-bata
marked this pull request as ready for review
September 1, 2026 10:04
Member
Author
|
@Alnusjaponica Could you review this PR? |
Alnusjaponica
requested review from
Alnusjaponica
and
a lite review from Copilot
and removed request for
Copilot
September 2, 2026 07:04
Alnusjaponica
left a comment
Contributor
There was a problem hiding this comment.
Apologies for the delayed reply. I've added a few comments about the behavioral changes. Please take a look, and let me know if anything is unclear.
c-bata
force-pushed
the
c-bata/nsgaii-fast-trial-number-lookup
branch
from
September 2, 2026 09:16
21b5e96 to
64349c7
Compare
c-bata
force-pushed
the
c-bata/nsgaii-fast-trial-number-lookup
branch
from
September 2, 2026 09:17
64349c7 to
4ec59db
Compare
Member
Author
|
@Alnusjaponica I applied your suggestions. PTAL. |
Alnusjaponica
approved these changes
Sep 2, 2026
Alnusjaponica
left a comment
Contributor
There was a problem hiding this comment.
LGTM. Thanks for the update.
Comment on lines
+450
to
+452
| && matches!( | ||
| trial.state_values, | ||
| TrialStateValues::Complete(_) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up #179 and #222.
get_cached_trial.trial_id -> trial numbermap by scanning all trials on every sample.Motivation
NSGA-II parent populations are persisted as trial IDs. On main, restoring a parent population rebuilds a
trial_id -> trial numbermap by scanning all completed trials for everysample_jointcall. This makes the cost grow with the total number of trials, even though the parent population contains onlypopulation_sizetrials.Benchmark
I took the same benchmark with #237 (comment). Here are the benchmark results (n_trials=10000, n_params=40):
mainbranch