-
-
Notifications
You must be signed in to change notification settings - Fork 88
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
Introduce skip
flag for preferential optimization
#581
Conversation
skiped_numbers = get_skiped_trials(study_id, storage) | ||
return [ | ||
copy.deepcopy(t) | ||
for t in ready_trials | ||
if t.number not in worse_numbers and t.number not in skiped_numbers | ||
] |
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.
skiped_numbers = get_skiped_trials(study_id, storage) | |
return [ | |
copy.deepcopy(t) | |
for t in ready_trials | |
if t.number not in worse_numbers and t.number not in skiped_numbers | |
] | |
skipped_numbers = get_skipped_trials(study_id, storage) | |
return [ | |
copy.deepcopy(t) | |
for t in ready_trials | |
if t.number not in worse_numbers and t.number not in skipped_numbers | |
] |
Typo.
def get_skiped_trials( | ||
study_id: int, | ||
storage: BaseStorage, | ||
) -> list[int]: | ||
"""Get trial numbers that have skip flag.""" | ||
skiped_trials: list[int] = [] | ||
summary = get_study_summary(storage, study_id) | ||
system_attrs = getattr(summary, "system_attrs", {}) | ||
for k, v in system_attrs.items(): | ||
if not k.startswith(_SYSTEM_ATTR_PREFIX_SKIP_TRIAL): | ||
continue | ||
skiped_trials.append(int(k.split(":")[-1])) | ||
return skiped_trials |
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.
def get_skiped_trials( | |
study_id: int, | |
storage: BaseStorage, | |
) -> list[int]: | |
"""Get trial numbers that have skip flag.""" | |
skiped_trials: list[int] = [] | |
summary = get_study_summary(storage, study_id) | |
system_attrs = getattr(summary, "system_attrs", {}) | |
for k, v in system_attrs.items(): | |
if not k.startswith(_SYSTEM_ATTR_PREFIX_SKIP_TRIAL): | |
continue | |
skiped_trials.append(int(k.split(":")[-1])) | |
return skiped_trials | |
def get_skipped_trials( | |
study_id: int, | |
storage: BaseStorage, | |
) -> list[int]: | |
"""Get trial numbers that have skip flag.""" | |
skipped_trials: list[int] = [] | |
summary = get_study_summary(storage, study_id) | |
system_attrs = getattr(summary, "system_attrs", {}) | |
for k, v in system_attrs.items(): | |
if not k.startswith(_SYSTEM_ATTR_PREFIX_SKIP_TRIAL): | |
continue | |
skipped_trials.append(int(k.split(":")[-1])) | |
return skipped_trials |
Typo.
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.
@moririn2528 Thank you for your pull request!
Looks almost good to me. I left some suggestions though.
for t in ready_trials: | ||
if t.number in worse_numbers: | ||
continue | ||
skipped_key = _SYSTEM_ATTR_PREFIX_SKIP_TRIAL + str(t._trial_id) | ||
if skipped_key in study_system_attrs: | ||
continue | ||
best_trials.append(copy.deepcopy(t)) |
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.
I've just noticed that we do not need to declare ready_trials.
for t in ready_trials: | |
if t.number in worse_numbers: | |
continue | |
skipped_key = _SYSTEM_ATTR_PREFIX_SKIP_TRIAL + str(t._trial_id) | |
if skipped_key in study_system_attrs: | |
continue | |
best_trials.append(copy.deepcopy(t)) | |
for t in storage.get_all_trials(study_id, deepcopy=False, states=(TrialState.COMPLETE, TrialState.RUNNING)): | |
if not t.system_attrs.get(_SYSTEM_ATTR_COMPARISON_READY, False): | |
continue | |
if t.number in worse_numbers: | |
continue | |
skipped_key = _SYSTEM_ATTR_PREFIX_SKIP_TRIAL + str(t._trial_id) | |
if skipped_key in study_system_attrs: | |
continue | |
best_trials.append(copy.deepcopy(t)) |
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.
Also perhaps, it might be clearer to define def is_skipped_trial(trial_id: int) -> bool
in optuna_dashboard/preferential/_system_attrs.py
.
optuna_dashboard/_app.py
Outdated
summary = get_study_summary(storage, study_id) | ||
if summary is None: | ||
response.status = 404 # Not found | ||
return {"reason": f"study_id={study_id} is not found"} | ||
system_attrs = getattr(summary, "system_attrs", {}) |
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.
Here, you can simply call get_study_system_attrs()
storage api.
https://github.com/optuna/optuna/blob/ddfcafd796eb7f933438510fdc3c844864933fe9/optuna/storages/_base.py#L205
summary = get_study_summary(storage, study_id) | |
if summary is None: | |
response.status = 404 # Not found | |
return {"reason": f"study_id={study_id} is not found"} | |
system_attrs = getattr(summary, "system_attrs", {}) | |
try: | |
system_attrs = storage.get_study_system_attrs(study_id) | |
except KeyError: | |
response.status = 404 # Not found | |
return {"reason": f"study_id={study_id} is not found"} |
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 after passing CI!
skip
flag for preferential optimization
Contributor License Agreement
This repository (
optuna-dashboard
) and Goptuna share common code.This pull request may therefore be ported to Goptuna.
Make sure that you understand the consequences concerning licenses and check the box below if you accept the term before creating this pull request.
Reference Issues/PRs
What does this implement/fix? Explain your changes.