Skip to content

Remove CmaEsAttrKeys and _attr_keys for Simplification#6068

Merged
HideakiImamura merged 2 commits intooptuna:masterfrom
sawa3030:remove-cmaesattrkeys
May 7, 2025
Merged

Remove CmaEsAttrKeys and _attr_keys for Simplification#6068
HideakiImamura merged 2 commits intooptuna:masterfrom
sawa3030:remove-cmaesattrkeys

Conversation

@sawa3030
Copy link
Copy Markdown
Collaborator

@sawa3030 sawa3030 commented May 2, 2025

Motivation

  • The callable functions in CmaEsAttrKeys were removed in #6025.
  • This cleanup further simplifies the CMA-ES implementation.
  • ref: #6025 (comment)

Description of the Changes

  • Removed the CmaEsAttrKeys class.
  • Removed the _attr_keys method and replaced its usage with inline logic where necessary.

@nabenabe0928
Copy link
Copy Markdown
Contributor

@HideakiImamura @c-bata Could you review this PR?

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

@c-bata c-bata left a comment

Choose a reason for hiding this comment

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

LGTM with a nit.

params = optimizer.ask()

generation_attr_key = self._attr_keys.generation
generation_attr_key = self._attr_prefix + "generation"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: It might be better to introduce the following two property methods to avoid inconsistencies in the key definitions.

@property
def _attr_key_generation(self) -> str:
    return self._attr_prefix + "generation"

@property
def _attr_key_optimizer(self, index: int) -> str:
    return f"{self._attr_prefix}optimizer:{index}"

key: value
for key, value in trial.system_attrs.items()
if key.startswith(self._attr_keys.optimizer)
if key.startswith(self._attr_key_optimizer)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Due to this implementation, the index is not passed as an argument to _attr_key_optimizer.

Copy link
Copy Markdown
Member

@c-bata c-bata May 2, 2025

Choose a reason for hiding this comment

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

I think we don't need to use self._attr_key_optimizer here. Instead, you can simply hardcode "cma:optimizer" in this line. Let me explain the background.

In older versions of Optuna, the CMA-ES optimizer was stored as a single system_attr without being split. However, this approach caused issues when using MySQL as the storage backend, so it was revised in the following PR to store the optimizer across multiple system_attrs:
#1833

To keep the backward compatibility, PR #1833 introduced these lines. But since more than four years have passed, it's likely that very few users are still affected by this logic, and we could even consider removing it (though it would be better to do so in a separate PR).

@sawa3030
Copy link
Copy Markdown
Collaborator Author

sawa3030 commented May 2, 2025

Thank you for the review. I made the update accordingly!

@codecov
Copy link
Copy Markdown

codecov bot commented May 2, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.40%. Comparing base (7272fb7) to head (632ab66).
⚠️ Report is 650 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6068      +/-   ##
==========================================
- Coverage   88.43%   88.40%   -0.03%     
==========================================
  Files         206      207       +1     
  Lines       13910    13973      +63     
==========================================
+ Hits        12301    12353      +52     
- Misses       1609     1620      +11     

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

Copy link
Copy Markdown
Member

@HideakiImamura HideakiImamura left a comment

Choose a reason for hiding this comment

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

Thanks for the follow-up! LGTM!

@HideakiImamura HideakiImamura merged commit 356bd1e into optuna:master May 7, 2025
16 checks passed
@nabenabe0928 nabenabe0928 added this to the v4.4.0 milestone May 16, 2025
@sawa3030 sawa3030 deleted the remove-cmaesattrkeys branch November 14, 2025 07:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code-fix Change that does not change the behavior, such as code refactoring.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants