optuna.storages.JournalRedisStorage

class optuna.storages.JournalRedisStorage(url, use_cluster=False, prefix='')[source]

Redis storage class for Journal log backend.

Parameters:
  • url (str) – URL of the redis storage, password and db are optional. (ie: redis://localhost:6379)

  • use_cluster (bool) – Flag whether you use the Redis cluster. If this is False, it is assumed that you use the standalone Redis server and ensured that a write operation is atomic. This provides the consistency of the preserved logs. If this is True, it is assumed that you use the Redis cluster and not ensured that a write operation is atomic. This means the preserved logs can be inconsistent due to network errors, and may cause errors.

  • prefix (str) – Prefix of the preserved key of logs. This is useful when multiple users work on one Redis server.

Note

Added in v3.1.0 as an experimental feature. The interface may change in newer versions without prior notice. See https://github.com/optuna/optuna/releases/tag/v3.1.0.

Methods

append_logs(logs)

Append logs to the backend.

load_snapshot()

Load snapshot from the backend.

read_logs(log_number_from)

Read logs with a log number greater than or equal to log_number_from.

save_snapshot(snapshot)

Save snapshot to the backend.

append_logs(logs)[source]

Append logs to the backend.

Parameters:

logs (List[Dict[str, Any]]) – A list that contains json-serializable logs.

Return type:

None

load_snapshot()[source]

Load snapshot from the backend.

Returns:

A serialized snapshot (bytes) if found, otherwise None.

Return type:

bytes | None

read_logs(log_number_from)[source]

Read logs with a log number greater than or equal to log_number_from.

If log_number_from is 0, read all the logs.

Parameters:

log_number_from (int) – A non-negative integer value indicating which logs to read.

Returns:

Logs with log number greater than or equal to log_number_from.

Return type:

List[Dict[str, Any]]

save_snapshot(snapshot)[source]

Save snapshot to the backend.

Parameters:

snapshot (bytes) – A serialized snapshot (bytes)

Return type:

None