optuna.storages.GrpcStorageProxy
- class optuna.storages.GrpcStorageProxy(*, host='localhost', port=13000)[source]
run_grpc_proxy_server()
用の gRPC クライアント。使用例
GrpcStorageProxy
をrun_grpc_proxy_server()
と組み合わせて使用する簡単な例です。import optuna from optuna.storages import GrpcStorageProxy storage = GrpcStorageProxy(host="localhost", port=13000) study = optuna.create_study(storage=storage)
サーバー側のコードについては、
run_grpc_proxy_server()
の例を参照してください。Warning
現在、SQLite3 データベースと組み合わせた gRPC ストレージプロキシは、キャッシュが無効化されないため、
optuna.delete_study()
を呼び出すと予期しない動作を引き起こす可能性があります。Note
バージョン 4.2.0 で実験的機能として追加されました。インターフェースは予告なく変更される可能性があります。 詳細は https://github.com/optuna/optuna/releases/tag/v4.2.0 を参照してください。
メソッド
check_trial_is_updatable
(trial_id, trial_state)Check whether a trial state is updatable.
close
()Close the gRPC channel.
create_new_study
(directions[, study_name])Create a new study from a name.
create_new_trial
(study_id[, template_trial])Create and add a new trial to a study.
delete_study
(study_id)Delete a study.
Read a list of
FrozenStudy
objects.get_all_trials
(study_id[, deepcopy, states])Read all trials in a study.
get_best_trial
(study_id)Return the trial with the best value in a study.
get_n_trials
(study_id[, state])Count the number of trials in a study.
get_study_directions
(study_id)Read whether a study maximizes or minimizes an objective.
get_study_id_from_name
(study_name)Read the ID of a study.
get_study_name_from_id
(study_id)Read the study name of a study.
get_study_system_attrs
(study_id)Read the optuna-internal attributes of a study.
get_study_user_attrs
(study_id)Read the user-defined attributes of a study.
get_trial
(trial_id)Read a trial.
Read the trial ID of a trial.
get_trial_number_from_id
(trial_id)Read the trial number of a trial.
get_trial_param
(trial_id, param_name)Read the parameter of a trial.
get_trial_params
(trial_id)Read the parameter dictionary of a trial.
get_trial_system_attrs
(trial_id)Read the optuna-internal attributes of a trial.
get_trial_user_attrs
(trial_id)Read the user-defined attributes of a trial.
Clean up all connections to a database.
set_study_system_attr
(study_id, key, value)Register an optuna-internal attribute to a study.
set_study_user_attr
(study_id, key, value)Register a user-defined attribute to a study.
set_trial_intermediate_value
(trial_id, step, ...)Report an intermediate value of an objective function.
set_trial_param
(trial_id, param_name, ...)Set a parameter to a trial.
set_trial_state_values
(trial_id, state[, values])Update the state and values of a trial.
set_trial_system_attr
(trial_id, key, value)Set an optuna-internal attribute to a trial.
set_trial_user_attr
(trial_id, key, value)Set a user-defined attribute to a trial.
wait_server_ready
([timeout])Wait until the gRPC server is ready.
- check_trial_is_updatable(trial_id, trial_state)
トライアルの状態が更新可能かどうかを確認します。
- Parameters:
trial_id (int) – トライアルの ID エラーメッセージの表示にのみ使用されます。
trial_state (TrialState) – チェックするトライアルの状態
- Raises:
UpdateFinishedTrialError – トライアルが既に終了している場合
- Return type:
None
- create_new_study(directions, study_name=None)[source]
名前から新しいスタディを作成します。
名前を指定しない場合、ストレージクラスが名前を生成します。 返されるスタディ ID は、現在および削除済みのすべてのスタディの中で一意です。
- Parameters:
directions (Sequence[StudyDirection]) – 要素が
MAXIMIZE
またはMINIMIZE
のいずれかである方向のシーケンスstudy_name (str | None) – 作成する新しいスタディの名前
- Returns:
作成されたスタディの ID
- Raises:
optuna.exceptions.DuplicatedStudyError – 同じ
study_name
のスタディが既に存在する場合- Return type:
- create_new_trial(study_id, template_trial=None)[source]
スタディに新しいトライアルを作成して追加します。
返されるトライアル ID は、現在および削除済みのすべてのトライアルの中で一意です。
- Parameters:
study_id (int) – スタディの ID
template_trial (FrozenTrial | None) – デフォルトのユーザー属性、システム属性、中間値、および状態を持つテンプレート
FrozenTrial
- Returns:
作成されたトライアルの ID
- Raises:
KeyError – 一致する
study_id
を持つスタディが存在しない場合- Return type:
- get_all_studies()[source]
FrozenStudy
オブジェクトのリストを読み込みます。- Returns:
study_id
でソートされたFrozenStudy
オブジェクトのリスト- Return type:
list[FrozenStudy]
- get_all_trials(study_id, deepcopy=True, states=None)[source]
スタディ内のすべてのトライアルを読み込みます。
- Parameters:
- Returns:
trial_id
でソートされたスタディ内のトライアルのリスト- Raises:
KeyError – 一致する
study_id
を持つスタディが存在しない場合- Return type:
- get_best_trial(study_id)
スタディ内で最も良い値を持つトライアルを返します。
このメソッドは単一目的最適化の場合のみ有効です。
- Parameters:
study_id (int) – スタディの ID
- Returns:
スタディ内のすべての終了したトライアルの中で最良の目的値を持つトライアル
- Raises:
KeyError – 一致する
study_id
を持つスタディが存在しない場合RuntimeError – スタディに複数の方向がある場合
ValueError – トライアルが完了していない場合
- Return type:
- get_n_trials(study_id, state=None)
スタディ内のトライアル数をカウントします。
- Parameters:
study_id (int) – スタディの ID
state (tuple[TrialState, ...] | TrialState | None) – フィルタリングするトライアルの状態。
None
の場合、すべての状態を含めます
- Returns:
スタディ内のトライアル数
- Raises:
KeyError – 一致する
study_id
を持つスタディが存在しない場合- Return type:
- get_study_directions(study_id)[source]
スタディが目的値を最大化または最小化するかを読み取ります。
- get_trial(trial_id)[source]
トライアルを読み込みます。
- get_trial_number_from_id(trial_id)
トライアル番号を読み込みます。
Note
トライアル番号はスタディ内で一意であり、連番です。
- get_trial_param(trial_id, param_name)
トライアルのパラメータを読み込みます。
- Parameters:
- Returns:
パラメータの内部表現
- Raises:
KeyError – 一致する
trial_id
を持つトライアルが存在しない場合- Return type:
パラメータが存在しない場合
- get_trial_params(trial_id)
トライアルのパラメータ辞書を読み込みます。
- get_trial_system_attrs(trial_id)
トライアルの optuna 内部属性を読み込みます。
- get_trial_user_attrs(trial_id)
トライアルのユーザー定義属性を読み込みます。
- remove_session()
データベースへのすべての接続をクリーンアップします。
- Return type:
None
- set_trial_intermediate_value(trial_id, step, intermediate_value)[source]
目的関数の中間値を報告します。
このメソッドは、指定されたステップに関連付けられた既存の中間値を上書きします。
- Parameters:
- Raises:
KeyError – 一致する
trial_id
を持つトライアルが存在しない場合UpdateFinishedTrialError – トライアルが既に終了している場合
- Return type:
None
- set_trial_param(trial_id, param_name, param_value_internal, distribution)[source]
トライアルにパラメータを設定します。
- Parameters:
- Raises:
KeyError – 一致する
trial_id
を持つトライアルが存在しない場合UpdateFinishedTrialError – トライアルが既に終了している場合
- Return type:
None
- set_trial_state_values(trial_id, state, values=None)[source]
トライアルの状態と値を更新します。
目的関数の戻り値を values 引数に設定します。 values 引数が
None
でない場合、このメソッドは既存のトライアル値を上書きします。- Parameters:
trial_id (int) – トライアルの ID
state (TrialState) – トライアルの新しい状態
- Returns:
状態が正常に更新された場合は
True
、 状態が変更されなかった場合はFalse
。 後者は、このメソッドがRUNNING
状態のトライアルをRUNNING
状態に更新しようとした場合に発生します。- Raises:
KeyError – 一致する
trial_id
を持つトライアルが存在しない場合UpdateFinishedTrialError – トライアルが既に終了している場合
- Return type:
- set_trial_system_attr(trial_id, key, value)[source]
トライアルに optuna 内部属性を設定します。
このメソッドは既存の属性を上書きします。
- Parameters:
- Raises:
KeyError – 一致する
trial_id
を持つトライアルが存在しない場合UpdateFinishedTrialError – トライアルが既に終了している場合
- Return type:
None
- set_trial_user_attr(trial_id, key, value)[source]
トライアルにユーザー定義属性を設定します。
このメソッドは既存の属性を上書きします。
- Parameters:
- Raises:
KeyError – 一致する
trial_id
を持つトライアルが存在しない場合UpdateFinishedTrialError – トライアルが既に終了している場合
- Return type:
None