API

dask_optuna.DaskStorage([storage])

Dask-compatible Storage class

class dask_optuna.DaskStorage(storage=None, name: str = None, client: distributed.client.Client = None)

Dask-compatible Storage class

Parameters
  • storage – Optuna storage class or url to use for underlying Optuna storage to wrap (e.g. None for in-memory storage, sqlite:///example.db for SQLite storage). Defaults to None.

  • name – Unique identifier for the Dask storage class. If not provided, a random name will be generated.

  • client – Dask Client to connect to. If not provided, will attempt to find an existing Client.

create_new_study(study_name: Optional[str] = None) → int

Create a new study from a name.

If no name is specified, the storage class generates a name. The returned study ID is unique among all current and deleted studies.

Parameters

study_name – Name of the new study to create.

Returns

ID of the created study.

Raises

optuna.exceptions.DuplicatedStudyError – If a study with the same study_name already exists.

create_new_trial(study_id: int, template_trial: Optional[optuna.trial._frozen.FrozenTrial] = None) → int

Create and add a new trial to a study.

The returned trial ID is unique among all current and deleted trials.

Parameters
  • study_id – ID of the study.

  • template_trial – Template FronzenTrial with default user-attributes, system-attributes, intermediate-values, and a state.

Returns

ID of the created trial.

Raises

KeyError – If no study with the matching study_id exists.

delete_study(study_id: int) → None

Delete a study.

Parameters

study_id – ID of the study.

Raises

KeyError – If no study with the matching study_id exists.

get_all_study_summaries() → List[optuna._study_summary.StudySummary]

Read a list of StudySummary objects.

Returns

A list of StudySummary objects.

get_all_trials(study_id: int, deepcopy: bool = True) → List[optuna.trial._frozen.FrozenTrial]

Read all trials in a study.

Parameters
  • study_id – ID of the study.

  • deepcopy – Whether to copy the list of trials before returning. Set to True if you intend to update the list or elements of the list.

Returns

List of trials in the study.

Raises

KeyError – If no study with the matching study_id exists.

get_n_trials(study_id: int, state: Optional[optuna.trial._state.TrialState] = None) → int

Count the number of trials in a study.

Parameters
  • study_id – ID of the study.

  • stateTrialState to filter trials.

Returns

Number of trials in the study.

Raises

KeyError – If no study with the matching study_id exists.

get_study_direction(study_id: int) → optuna._study_direction.StudyDirection

Read whether a study maximizes or minimizes an objective.

Parameters

study_id – ID of a study.

Returns

Optimization direction of the study.

Raises

KeyError – If no study with the matching study_id exists.

get_study_id_from_name(study_name: str) → int

Read the ID of a study.

Parameters

study_name – Name of the study.

Returns

ID of the study.

Raises

KeyError – If no study with the matching study_name exists.

get_study_id_from_trial_id(trial_id: int) → int

Read the ID of a study to which a trial belongs.

Parameters

trial_id – ID of the trial.

Returns

ID of the study.

Raises

KeyError – If no trial with the matching trial_id exists.

get_study_name_from_id(study_id: int) → str

Read the study name of a study.

Parameters

study_id – ID of the study.

Returns

Name of the study.

Raises

KeyError – If no study with the matching study_id exists.

get_study_system_attrs(study_id: int) → Dict[str, Any]

Read the optuna-internal attributes of a study.

Parameters

study_id – ID of the study.

Returns

Dictionary with the optuna-internal attributes of the study.

Raises

KeyError – If no study with the matching study_id exists.

get_study_user_attrs(study_id: int) → Dict[str, Any]

Read the user-defined attributes of a study.

Parameters

study_id – ID of the study.

Returns

Dictionary with the user attributes of the study.

Raises

KeyError – If no study with the matching study_id exists.

get_trial(trial_id: int) → optuna.trial._frozen.FrozenTrial

Read a trial.

Parameters

trial_id – ID of the trial.

Returns

Trial with a matching trial ID.

Raises

KeyError – If no trial with the matching trial_id exists.

get_trial_number_from_id(trial_id: int) → int

Read the trial number of a trial.

Note

The trial number is only unique within a study, and is sequential.

Parameters

trial_id – ID of the trial.

Returns

Number of the trial.

Raises

KeyError – If no trial with the matching trial_id exists.

get_trial_param(trial_id: int, param_name: str) → float

Read the parameter of a trial.

Parameters
  • trial_id – ID of the trial.

  • param_name – Name of the parameter.

Returns

Internal representation of the parameter.

Raises

KeyError – If no trial with the matching trial_id exists. If no such parameter exists.

read_trials_from_remote_storage(study_id: int) → None

Make an internal cache of trials up-to-date.

Parameters

study_id – ID of the study.

Raises

KeyError – If no study with the matching study_id exists.

set_study_direction(study_id: int, direction: optuna._study_direction.StudyDirection) → None

Register an optimization problem direction to a study.

Parameters
Raises
  • KeyError – If no study with the matching study_id exists.

  • ValueError – If the direction is already set and the passed direction is the opposite direction or NOT_SET.

set_study_system_attr(study_id: int, key: str, value: Any) → None

Register an optuna-internal attribute to a study.

This method overwrites any existing attribute.

Parameters
  • study_id – ID of the study.

  • key – Attribute key.

  • value – Attribute value. It should be JSON serializable.

Raises

KeyError – If no study with the matching study_id exists.

set_study_user_attr(study_id: int, key: str, value: Any) → None

Register a user-defined attribute to a study.

This method overwrites any existing attribute.

Parameters
  • study_id – ID of the study.

  • key – Attribute key.

  • value – Attribute value. It should be JSON serializable.

Raises

KeyError – If no study with the matching study_id exists.

set_trial_intermediate_value(trial_id: int, step: int, intermediate_value: float) → None

Report an intermediate value of an objective function.

This method overwrites any existing intermediate value associated with the given step.

Parameters
  • trial_id – ID of the trial.

  • step – Step of the trial (e.g., the epoch when training a neural network).

  • intermediate_value – Intermediate value corresponding to the step.

Raises
  • KeyError – If no trial with the matching trial_id exists.

  • RuntimeError – If the trial is already finished.

set_trial_param(trial_id: int, param_name: str, param_value_internal: float, distribution: optuna.distributions.BaseDistribution) → None

Set a parameter to a trial.

Parameters
  • trial_id – ID of the trial.

  • param_name – Name of the parameter.

  • param_value_internal – Internal representation of the parameter value.

  • distribution – Sampled distribution of the parameter.

Raises
  • KeyError – If no trial with the matching trial_id exists.

  • RuntimeError – If the trial is already finished.

set_trial_state(trial_id: int, state: optuna.trial._state.TrialState) → bool

Update the state of a trial.

Parameters
  • trial_id – ID of the trial.

  • state – New state of the trial.

Returns

True if the state is successfully updated. False if the state is kept the same. The latter happens when this method tries to update the state of RUNNING trial to RUNNING.

Raises
  • KeyError – If no trial with the matching trial_id exists.

  • RuntimeError – If the trial is already finished.

set_trial_system_attr(trial_id: int, key: str, value: Any) → None

Set an optuna-internal attribute to a trial.

This method overwrites any existing attribute.

Parameters
  • trial_id – ID of the trial.

  • key – Attribute key.

  • value – Attribute value. It should be JSON serializable.

Raises
  • KeyError – If no trial with the matching trial_id exists.

  • RuntimeError – If the trial is already finished.

set_trial_user_attr(trial_id: int, key: str, value: Any) → None

Set a user-defined attribute to a trial.

This method overwrites any existing attribute.

Parameters
  • trial_id – ID of the trial.

  • key – Attribute key.

  • value – Attribute value. It should be JSON serializable.

Raises
  • KeyError – If no trial with the matching trial_id exists.

  • RuntimeError – If the trial is already finished.

set_trial_value(trial_id: int, value: float) → None

Set a return value of an objective function.

This method overwrites any existing trial value.

Parameters
  • trial_id – ID of the trial.

  • value – Value of the objective function.

Raises
  • KeyError – If no trial with the matching trial_id exists.

  • RuntimeError – If the trial is already finished.