Fix a bug that a gRPC server doesn't work with JournalStorage#6004
Merged
nabenabe0928 merged 3 commits intooptuna:masterfrom Mar 24, 2025
Merged
Conversation
Member
|
@c-bata @nabenabe0928 Could you review this PR? |
c-bata
approved these changes
Mar 13, 2025
Member
c-bata
left a comment
There was a problem hiding this comment.
LGTM! I confirmed that this PR allows the following code to work correctly.
$ python3 -c "import optuna; from optuna.storages import run_grpc_proxy_server; run_grpc_proxy_server(storage=optuna.storages.JournalStorage(optuna.storages.journal.JournalFileBackend('./tmp/journal.log')), host='localhost', port=13000)"
import optuna
def objective(trial):
x = trial.suggest_float("x", -10, 10)
return x ** 2
if __name__ == "__main__":
study = optuna.create_study(
study_name="distributed-example",
storage=optuna.storages.GrpcStorageProxy(host="localhost", port=13000),
load_if_exists=True,
)
study.optimize(objective, n_trials=100)| # We don't actually require that all storages to preserve the order of parameters, | ||
| # but all current implementations except for GrpcStorageProxy do, so we test this property. | ||
| if storage_mode == "grpc": | ||
| if storage_mode == "grpc_rdb" or storage_mode == "grpc_journal_file": |
Contributor
There was a problem hiding this comment.
Suggested change
| if storage_mode == "grpc_rdb" or storage_mode == "grpc_journal_file": | |
| if storage_mode in ("grpc_rdb", "grpc_journal_file"): |
tests/study_tests/test_study.py
Outdated
| @pytest.mark.parametrize("storage_mode", STORAGE_MODES) | ||
| def test_get_trials(storage_mode: str) -> None: | ||
| if storage_mode == "grpc": | ||
| if storage_mode == "grpc_rdb" or storage_mode == "grpc_journal_file": |
Contributor
There was a problem hiding this comment.
Suggested change
| if storage_mode == "grpc_rdb" or storage_mode == "grpc_journal_file": | |
| if storage_mode in ("grpc_rdb", "grpc_journal_file"): |
Contributor
nabenabe0928
left a comment
There was a problem hiding this comment.
Thank you for the PR!
I confirmed that the modification works as intended!
Please apply my comments and then I will approve this PR!
Contributor
Author
|
@nabenabe0928 |
nabenabe0928
approved these changes
Mar 24, 2025
Contributor
nabenabe0928
left a comment
There was a problem hiding this comment.
Thank you for the updates, LGTM!
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.
Motivation
Currently, the gRPC server fails to function properly when using JournalStorage.
Description of the changes
The
RepeatedScalarContainerclass is used to convey arrays for protobuf.However, an instance of
RepeatedScalarContainercannot be converted to JSON.To address this, I made the following change:
Additionally, to prevent issues like this in the future, I added
grpc_journal_fileto theSTORAGE_MODESfor pytest: