jobs
Tools for setting up the JobDB.
TODO: Add some quick tools for inspecting the jobdb here.
fail(job, errcode, msg, logger)
Mark and job as failed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job
|
Job
|
The job to fail. |
required |
errcode
|
ErrCode
|
The error code that thi job failed with. |
required |
msg
|
str
|
The detailed error message. |
required |
logger
|
LoggerLike
|
The logger to log the error to. |
required |
Source code in lat_beams/utils/jobs.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
make_jobdb(comm, data_dir, append='')
Create or load a JobDB at {data_dir}/jobdb{append}.db.
If a jobdb without append exists its entries will be merged
into the append jobdb based on the last update.
Note that this can create some confusion because it may reference
jobs that were run in the main jobdb, to address this jobs with jclass
stack_maps and fit_stacks are not copied, but use with caution
if you are running jobs of jclass source_map or fit_map.
If you are running one of those some manual reconfiguring may be needed.
This should be used to test new methods or create custom one-off stacks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
comm
|
Optional[Comm]
|
The communicator if we are running with MPI or None if not. If provided then rank 0 will load the database first so that it may create it if it doesn't exist. |
required |
data_dir
|
str
|
The directory to load the db from. |
required |
append
|
str
|
String appended to db name. See docstring for details. |
''
|
Returns:
| Name | Type | Description |
|---|---|---|
jobdb |
JobManager
|
The loaded database. For better MPI support this has a timeout of 10 and uses NullPool. |
Source code in lat_beams/utils/jobs.py
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 252 253 254 255 256 257 258 259 | |
setup_jobs(comm, data_dir, jclass, get_jobdict, get_jobit, get_jobstr, get_tags, source_list, overwrite, retry_failed, job_memory, job_memory_buffer, replot, logger, append='')
Discover, create, and select jobs for execution across MPI ranks.
Existing jobs are loaded from the job database and matched against a
collection of candidate jobs generated by get_jobit. Missing jobs are
created, eligible jobs are reopened when requested, and a consolidated
list of jobs to process is returned.
Jobs may be filtered by lock status, source tag, recent visit time, and job state. Database writes are serialized across MPI ranks to avoid contention.
Jobs are created and database updates are committed serially across MPI ranks to avoid database locking contention.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
comm
|
Optional[Comm]
|
MPI communicator used to prevent deadlock between processes. |
required |
data_dir
|
str
|
Directory containing the job database. |
required |
jclass
|
str
|
Job class name passed to |
required |
get_jobdict
|
Callable[[JobManager], dict[str, Job]]
|
Function that returns a mapping from job identifier strings to existing jobs in the database. |
required |
get_jobit
|
Callable[[JobManager], Iterable[Any]]
|
Function that returns an iterable of candidate job descriptions. |
required |
get_jobstr
|
Callable[[Any], Optional[str]]
|
Function that converts a candidate job description into its unique
job identifier string. Returning |
required |
get_tags
|
Callable[[Any], dict[str, str]]
|
Function that generates the tag dictionary used when creating a new job from a candidate job description. |
required |
source_list
|
Sequence[str]
|
Allowed values of the |
required |
overwrite
|
bool
|
If |
required |
retry_failed
|
bool
|
If |
required |
job_memory
|
Optional[float]
|
Number of hours for which recently visited jobs should be skipped.
If |
required |
job_memory_buffer
|
float
|
Minimum age, in minutes, before the visit-time filter is applied. |
required |
replot
|
bool
|
If |
required |
logger
|
LoggerLike
|
Logger to log to. |
required |
append
|
str
|
String appended to db name.
See |
''
|
Returns:
| Name | Type | Description |
|---|---|---|
jdb |
JobManager
|
Job database manager instance. |
jobs |
list[Job]
|
Complete list of jobs selected for processing across all MPI ranks. |
Source code in lat_beams/utils/jobs.py
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 339 340 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 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 | |
update_jobs_retry(jdb, jobs, max_retries, logger)
Update jobs in the job database, retrying on database lock errors.
The update is retried up to max_retries times when the database
reports that it is locked. A one-second delay is inserted between
retries. Other operational errors are propagated immediately.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
jdb
|
JobManager
|
Job database manager used to update the jobs. |
required |
jobs
|
Sequence[Job]
|
Jobs to update in the database. |
required |
max_retries
|
int
|
Maximum number of attempts to make when updating the jobs. |
required |
logger
|
LoggerLike
|
Logger used to report failures and successful updates. |
required |
Raises:
| Type | Description |
|---|---|
OperationalError
|
If an operational database error occurs that is not caused by the database being locked. |
Source code in lat_beams/utils/jobs.py
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 | |