Skip to content

Fix _pop_waiting_trial_id for finished trial#6012

Merged
y0z merged 3 commits intooptuna:masterfrom
not522:fix-pop-waiting-trial-id
Mar 31, 2025
Merged

Fix _pop_waiting_trial_id for finished trial#6012
y0z merged 3 commits intooptuna:masterfrom
not522:fix-pop-waiting-trial-id

Conversation

@not522
Copy link
Copy Markdown
Member

@not522 not522 commented Mar 14, 2025

Motivation

If _pop_waiting_trial_id tries to change the state for a finished trial, it unexpectedly raises UpdateFinishedTrialError. This PR changes the implementation to catch the exception.

Description of the changes

  • Adding a try-except statement for the buggy case.
  • Adding a test.

@not522 not522 force-pushed the fix-pop-waiting-trial-id branch from ceabdc9 to a44f74b Compare March 14, 2025 07:45
@not522 not522 force-pushed the fix-pop-waiting-trial-id branch from ff08402 to 7822f24 Compare March 18, 2025 05:48
@not522 not522 added the bug Issue/PR about behavior that is broken. Not for typos/examples/CI/test but for Optuna itself. label Mar 18, 2025
@not522 not522 marked this pull request as ready for review March 18, 2025 05:50
@not522
Copy link
Copy Markdown
Member Author

not522 commented Mar 18, 2025

I've added a test and this PR is now review ready.

@c-bata
Copy link
Copy Markdown
Member

c-bata commented Mar 18, 2025

@sawa3030 @nabenabe0928 @gen740 Could you review this PR?

# The trial is already running.
continue
except exceptions.UpdateFinishedTrialError:
# The trial is already finished.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you elaborate the note here a bit more?

assert len(trial_id_set) == num_enqueued


def test_pop_waiting_trial_id_race_condition() -> None:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Confirmed that this test fails with the latest master, but it passes with the modification in this PR.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Confirmation complete on my end!

Copy link
Copy Markdown
Contributor

@nabenabe0928 nabenabe0928 left a comment

Choose a reason for hiding this comment

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

Almost LGTM!
I left a minor comment, so PTAL!

@sawa3030
Copy link
Copy Markdown
Collaborator

sawa3030 commented Mar 20, 2025

Other than the issue @nabenabe0928 pointed out above, this looks good to me.

@not522 not522 force-pushed the fix-pop-waiting-trial-id branch from d8677dc to 09af760 Compare March 21, 2025 04:48
@not522
Copy link
Copy Markdown
Member Author

not522 commented Mar 21, 2025

Thank you for your reviews. I've updated the comment. PTAL.

Copy link
Copy Markdown
Contributor

@nabenabe0928 nabenabe0928 left a comment

Choose a reason for hiding this comment

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

The change looks good to me:)

@nabenabe0928 nabenabe0928 removed their assignment Mar 21, 2025
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.44%. Comparing base (3ba42a7) to head (09af760).
Report is 595 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6012      +/-   ##
==========================================
- Coverage   88.46%   88.44%   -0.03%     
==========================================
  Files         206      206              
  Lines       13857    13876      +19     
==========================================
+ Hits        12259    12272      +13     
- Misses       1598     1604       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@c-bata c-bata assigned y0z and unassigned gen740 Mar 21, 2025
@c-bata
Copy link
Copy Markdown
Member

c-bata commented Mar 21, 2025

@y0z 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

@y0z y0z left a comment

Choose a reason for hiding this comment

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

LGTM

@y0z y0z added this to the v4.3.0 milestone Mar 31, 2025
@y0z y0z removed their assignment Mar 31, 2025
@y0z y0z merged commit 543a65a into optuna:master Mar 31, 2025
16 checks passed
@not522 not522 deleted the fix-pop-waiting-trial-id branch March 31, 2025 07:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Issue/PR about behavior that is broken. Not for typos/examples/CI/test but for Optuna itself.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants