API Reference¶
optuna_db.db_instance¶
get_optuna_db()
¶
Returns a global OptunaDatabase instance, initializing it if necessary.
If the database instance does not exist, it will be created using credentials stored in Docker secrets. If initialization fails, an exception is raised.
Returns:
| Type | Description |
|---|---|
OptunaDatabase
|
The global OptunaDatabase instance. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the database initialization fails. |
Source code in src/docktuna/optuna_db/db_instance.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
options: show_source: true
optuna_db.optuna_db.OptunaDatabase¶
Handles database interactions for Optuna studies, including secure retrieval of credentials from Docker secrets and connection management.
Source code in src/docktuna/optuna_db/optuna_db.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | |
db_name
property
¶
Retrieves the database name from secrets.
hostname
property
¶
Retrieves the database hostname from secrets.
num_existing_studies
property
¶
Returns the number of existing studies in the database.
Returns:
| Type | Description |
|---|---|
int
|
The total number of studies. |
storage
property
¶
Creates an Optuna RDBStorage instance for persistent study storage.
Returns:
| Type | Description |
|---|---|
RDBStorage
|
The Optuna storage backend. |
study_summaries
property
¶
Retrieves summaries of all studies stored in the database.
Returns:
| Type | Description |
|---|---|
list[StudySummary]
|
A list of study summaries. |
username
property
¶
Retrieves the database username from secrets.
__init__(username, db_password_secret, db_name, hostname)
¶
Initializes an OptunaDatabase instance with database connection details.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
username
|
str
|
Database username. |
required |
db_password_secret
|
str
|
Secret name for the database password. |
required |
db_name
|
str
|
Name of the database. |
required |
hostname
|
str
|
Database host. |
required |
Source code in src/docktuna/optuna_db/optuna_db.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
get_all_studies()
¶
Retrieves all studies stored in the database.
Returns:
| Type | Description |
|---|---|
list[Study]
|
A list of all Optuna studies. |
Source code in src/docktuna/optuna_db/optuna_db.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
get_best_params(study_name)
¶
Retrieves the best hyperparameters from a completed study.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
study_name
|
str
|
The name of the study. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, any]
|
The best hyperparameters, or an empty dictionary if no trials exist. |
Source code in src/docktuna/optuna_db/optuna_db.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
get_last_update_time(study)
staticmethod
¶
Retrieves the last update time of a given study.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
study
|
Study
|
The study object. |
required |
Returns:
| Type | Description |
|---|---|
datetime
|
The timestamp of the most recent trial completion, |
datetime
|
or a default old date if no trials exist. |
Source code in src/docktuna/optuna_db/optuna_db.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | |
get_latest_study()
¶
Retrieves the most recently updated study.
Returns:
| Type | Description |
|---|---|
Study
|
The study with the most recent completed trial, |
Study
|
or None if no studies exist. |
Source code in src/docktuna/optuna_db/optuna_db.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 | |
get_study(study_name)
¶
Retrieves or creates an Optuna study.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
study_name
|
str
|
The name of the study. |
required |
Returns:
| Type | Description |
|---|---|
Study
|
The retrieved or newly created study. |
Source code in src/docktuna/optuna_db/optuna_db.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |
get_study_summary(study_name)
¶
Retrieves the summary of a specific study.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
study_name
|
str
|
The name of the study. |
required |
Returns:
| Type | Description |
|---|---|
StudySummary
|
The summary of the study. |
Raises:
| Type | Description |
|---|---|
StopIteration
|
If the study is not found. |
Source code in src/docktuna/optuna_db/optuna_db.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
is_in_db(study_name)
¶
Checks if a study exists in the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
study_name
|
str
|
The name of the study. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the study exists, False otherwise. |
Source code in src/docktuna/optuna_db/optuna_db.py
125 126 127 128 129 130 131 132 133 134 135 136 137 | |
options: show_source: true