db
Tools for working with the LUTE parameter and configuration database.
The current implementation relies on a sqlite backend database. In the future this may change - therefore relatively few high-level API function calls are intended to be public. These abstract away the details of the database interface and work exclusively on LUTE objects.
Functions:
Name | Description |
---|---|
record_analysis_db |
DescribedAnalysis) -> None: Writes the configuration to the backend database. |
read_latest_db_entry |
str, task_name: str, param: str) -> Any: Retrieve the most recent entry from a database for a specific Task. |
Raises:
Type | Description |
---|---|
DatabaseError
|
Generic exception raised for LUTE database errors. |
DatabaseError
Bases: Exception
General LUTE database error.
Source code in lute/io/db.py
38 39 40 41 |
|
_cfg_to_exec_entry_cols(cfg)
Converts AnalysisConfig to be entered into a exec_cfg table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entries
|
Dict[str, Any]
|
Converted {name:value} dictionary. |
required |
columns
|
Dict[str, str]
|
Converted {name:type} dictionary. |
required |
Source code in lute/io/db.py
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 |
|
_check_type(value)
Return SQL type for a value.
Source code in lute/io/db.py
155 156 157 158 159 160 161 162 163 164 |
|
_dict_to_flatdicts(d, curr_key='')
Flattens a dictionary delimiting parameters with a '.'.
Works recursively. Also returns the type of each flattened value. Tuples/lists are handled flattened as well, using an indexing scheme. E.g. a["b"] in the nested dictionaries below: { "a": { "b": (1, 2), }, # ... } will be addressed as: a.b[0] and a.b[1] for the values of 1 and 2, respectively.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
d
|
Dict[str, Any]
|
Dictionary to flatten. |
required |
curr_key
|
str
|
Current flattened key. |
''
|
Returns:
Name | Type | Description |
---|---|---|
flattened_params |
Dict[str, Any]
|
Dictionary of flatkey:value pairs. |
flattened_types |
Dict[str, str]
|
Dictionary of flatkey:type(value) pairs. Types are one of TEXT, INTEGER, REAL. |
Source code in lute/io/db.py
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 252 253 254 255 256 257 |
|
_list_to_flatlists(l_entry, curr_key='')
Flatten lists for database storage.
Indexes entries in the list using "[idx]" notation. Nested lists are handled with multiple indices [x][y][...]. This function is called recursively to handle nesting.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
l_entry
|
List[Any]
|
Dictionary to flatten. |
required |
curr_key
|
str
|
Current flattened key. Base key for indexing. |
''
|
Returns:
Name | Type | Description |
---|---|---|
flattened_params |
List[Tuple[str, Any]]
|
List of (indexed_key, value) pairs. |
flattened_types |
List[Tuple[str, str]]
|
List of (indexed_key, type) pairs. Types are one of TEXT, INTEGER, REAL |
Source code in lute/io/db.py
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 |
|
_params_to_entry_cols(params)
Adapts a TaskParameters object to be entered into a table.
Extracts the appropriate names and types from a TaskParameters object. Compound types (e.g. dicts) are recursively extracted and are given names where subparameters are delimited by ".". E.g. a parameter such as: my_param = { "a": 1, "b": 0.1, } will be converted into the following entries: ("my_param.a", "INTEGER"), ("my_param.b", "REAL").
The lute_config
analysis header is separated out and returned as a separate
set of entries and columns. This particular field of the TaskParameters
object contains shared configuration between Task
s which is stored in a
separated table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params
|
TaskParameters
|
The TaskParameters object to convert to columns. |
required |
Returns:
Name | Type | Description |
---|---|---|
entries |
Dict[str, Any]
|
Converted {name:value} dictionary for Task specific parameters. |
columns |
Dict[str, str]
|
Converted {name:type} dictionary for Task specific parameters. |
gen_entries |
Dict[str, Any]
|
General configuration entry dictionary. |
gen_columns |
Dict[str, str]
|
General configuration type information dictionary. |
Source code in lute/io/db.py
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 |
|
_result_to_entry_cols(result)
Adapts the required fields from a TaskResult to be entered into a table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entries
|
Dict[str, Any]
|
Converted {name:value} dictionary. |
required |
columns
|
Dict[str, str]
|
Converted {name:type} dictionary. |
required |
Source code in lute/io/db.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
|
read_latest_db_entry(db_dir, task_name, param, valid_only=True, for_run=os.getenv('RUN'))
Read most recent value entered into the database for a Task parameter.
(Will be updated for schema compliance as well as Task name.)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
db_dir
|
str
|
Database location. |
required |
task_name
|
str
|
The name of the Task to check the database for. |
required |
param
|
str
|
The parameter name for the Task that we want to retrieve. |
required |
valid_only
|
bool
|
Whether to consider only valid results or not. E.g. An input file may be useful even if the Task result is invalid (Failed). Default = True. |
True
|
for_run
|
Optional[str | int]
|
Only consider latest entries from the specific experiment run provided. |
getenv('RUN')
|
Returns:
Name | Type | Description |
---|---|---|
val |
Any
|
The most recently entered value for |
Source code in lute/io/db.py
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 |
|
record_analysis_db(cfg)
Write an DescribedAnalysis object to the database.
The DescribedAnalysis object is maintained by the Executor and contains all
information necessary to fully describe a single Task
execution. The
contained fields are split across multiple tables within the database as
some of the information can be shared across multiple Tasks. Refer to
docs/design/database.md
for more information on the database specification.
Source code in lute/io/db.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
|