-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix a bug in _create_new_trial
and refactor it
#5497
Fix a bug in _create_new_trial
and refactor it
#5497
Conversation
I will add unittest(s) if possible; I assume it is not difficult and will be done today. The unittest(s) will confirm that the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR, I left a comment!
_create_new_trial
_create_new_trial
Co-authored-by: Shuhei Watanabe <47781922+nabenabe0928@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
_create_new_trial
_create_new_trial
and refactor it
Motivation
I want to refactor
_create_new_trial
I want
_create_new_trial
to generate no empty trial_id when transaction processing fails.(note: I want to clarify by separating single issue in PR #5466 , which involves multiple issues and becomes complicated.)
Description of the changes
In the current implementation,
with _create_scoped_session
is outside andwhile
loop is inside, so if the transaction fails in_get_prepared_new_trial
, Optuna retries without rollback of the precedingfind_or_raise_by_id
. As a result, emptytrial_id
can be generated. (I confirmed the behaviour by a simple experiment that inserts a line raising an exception atrandom
in_get_prepared_new_trial
.)In the proposed implementation,
with _create_scoped_session
is inside the for loop, so a rollback occurs against every fail of transaction.Note
In the current inplementation, only
sqlalchemy_exc.OperationalError:
will be caught, and other exceptions are re-raised as is. I believe the proposed implementation does not change the behaviour.