Repository navigation
Normalize trial timestamps to UTC in RDBStorage and JournalStorage - #6776
Merged
Merged
Conversation
c-bata
marked this pull request as draft
July 28, 2026 11:49
Member
Author
Member
Author
|
Since verifying UTC normalization requires inspecting backend-specific persisted data directly, such as querying the RDB with raw SQL or inspecting the Journal log file, I manually verified the behavior using the steps below. All commands below were run in the RDBStorage (SQLite3)Scriptimport os
import optuna
branch_name = "master"
base_dir = os.path.dirname(__file__)
storage = optuna.storages.get_storage(f"sqlite:///{base_dir}/{branch_name}.sqlite3")
study = optuna.create_study(storage=storage)
study.optimize(lambda t: t.suggest_float("x", -10, 10), n_trials=5)
print(f"{study.trials[0].datetime_start=}")
print(f"{study.trials[0].datetime_start.tzinfo=}")
print(f"{study.trials[0].datetime_complete=}")
print(f"{study.trials[0].datetime_complete.tzinfo=}")BeforeWith this PRJournalStorage (JournalFileBackend)Scriptimport os
import optuna
from optuna.storages.journal import JournalStorage
from optuna.storages.journal import JournalFileBackend
branch_name = "master"
base_dir = os.path.dirname(__file__)
storage = JournalStorage(JournalFileBackend(f"{base_dir}/{branch_name}.journal"))
study = optuna.create_study(storage=storage)
study.optimize(lambda t: t.suggest_float("x", -10, 10), n_trials=5)
print(f"{study.trials[0].datetime_start=}")
print(f"{study.trials[0].datetime_start.tzinfo=}")
print(f"{study.trials[0].datetime_complete=}")
print(f"{study.trials[0].datetime_complete.tzinfo=}")BeforeWith this PR |
1 task done
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
Refs #6755
RDBStorage and JournalStorage currently create trial timestamps using timezone-naive datetime.now().
As a result, the persisted values represent the local wall-clock time of the process writing to the storage.
This makes datetime_start and datetime_complete dependent on the writer's local timezone. In particular, when using the gRPC storage proxy, changing the timezone of the proxy process changes the timestamps written to the database, even if the workers and database remain unchanged.
This PR normalizes newly stored trial timestamps to UTC while preserving the existing public representation of trial datetimes.
Description of the changes
The datetime representations after this change are:
The representations used by RDBStorage and JournalStorage intentionally differ.
2026-07-28T10:00:00.000000+00:00.The public
FrozenTrialrepresentation remains timezone-naive local time for backward compatibility.Changing it to a timezone-aware datetime would break existing code that compares or subtracts it from a timezone-naive
datetime.now(), including existing Optuna functionality such asplot_timeline().