climate_ref.executor.result_handling
#
Execute diagnostics in different environments
We support running diagnostics in different environments, such as locally,
in a separate process, or in a container.
These environments are represented by climate_ref.executor.Executor classes.
The simplest executor is the LocalExecutor, which runs the diagnostic in the same process.
This is useful for local testing and debugging.
ExecutionFuture
#
A container linking a submitted future to its execution metadata.
Source code in packages/climate-ref/src/climate_ref/executor/result_handling.py
definition
instance-attribute
#
The execution definition associated with this future.
execution_id = None
class-attribute
instance-attribute
#
The ID of the execution associated with this future, or None if not yet assigned.
future
instance-attribute
#
The future representing the asynchronous execution of this task.
This future has a base-class of concurrent.futures.Future,
but the concrete class of the instance will depend on the executor.
queue_seconds
property
#
Time spent waiting between submission and the start of execution, in seconds.
None when the start of execution could not be established.
started_at = None
class-attribute
instance-attribute
#
Wall-clock time (time.time()) at which a worker was first observed running this future,
or None while it is still queued.
The per-task timeout is budgeted against this rather than submitted_at
so that time spent waiting in the pool queue is not counted as execution time.
submitted_at = 0.0
class-attribute
instance-attribute
#
Wall-clock time (time.time()) at which this future was submitted to the executor.
infer_started_at(result, observed_at)
#
Place started_at using the worker's own wall time, if a poll never observed the start.
A task submitted and finished between two polls is never seen running, which would leave the queue latency unrecorded for every short execution. The worker measured how long it ran, so subtracting that from the moment completion was observed puts the start within one poll interval of the truth.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
ExecutionResult
|
The finished result, whose |
required |
observed_at
|
float
|
Wall-clock time ( |
required |
Source code in packages/climate-ref/src/climate_ref/executor/result_handling.py
fail_future(database, config, future, *, detail)
#
Mark the execution behind an abandoned future as failed-retryable.
Source code in packages/climate-ref/src/climate_ref/executor/result_handling.py
fail_outstanding(database, config, results, progress, *, detail)
#
Mark every execution an executor is giving up on as failed-retryable and drop it from results.
Source code in packages/climate-ref/src/climate_ref/executor/result_handling.py
handle_execution_result(config, database, execution, result, *, update_dirty=True, queue_seconds=None, detail=None)
#
Handle the result of a diagnostic execution
This will update the diagnostic execution result with the output of the diagnostic execution. The output will be copied from the scratch directory to the executions directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
The configuration to use |
required |
database
|
Database
|
The active database session to use |
required |
execution
|
Execution
|
The diagnostic execution result DB object to update |
required |
result
|
ExecutionResult
|
The result of the diagnostic execution, either successful or failed |
required |
update_dirty
|
bool
|
Whether to update the execution group's dirty flag. Set to False for reingest which should not alter pending-work state. |
True
|
queue_seconds
|
float | None
|
Submit-to-start latency observed by the submitting executor, or None when it is unknown. |
None
|
detail
|
str | None
|
Why the executor failed the execution, if it did. A failed execution has this appended to its results log. |
None
|
Source code in packages/climate-ref/src/climate_ref/executor/result_handling.py
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 | |
ingest_execution_result(database, execution, result, cv, *, output_base_path)
#
Ingest a successful execution result into the database.
Registers output entries and ingests scalar and series metric values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
database
|
Database
|
The active database session to use |
required |
execution
|
Execution
|
The execution record to associate results with |
required |
result
|
ExecutionResult
|
The successful execution result |
required |
cv
|
CV
|
The controlled vocabulary to validate metrics against |
required |
output_base_path
|
Path
|
Primary base directory for resolving output filenames |
required |
Notes
Callers are responsible for:
- File copying (scratch -> results)
- Transaction boundaries
- Marking the execution as successful (
execution.mark_successful()) - Setting the dirty flag on the execution group
Source code in packages/climate-ref/src/climate_ref/executor/result_handling.py
ingest_scalar_values(database, result, execution, cv)
#
Load, validate, and bulk-insert scalar metric values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
database
|
Database
|
The active database session to use |
required |
result
|
ExecutionResult
|
The execution result containing the metric bundle filename |
required |
execution
|
Execution
|
The execution record to associate values with |
required |
cv
|
CV
|
The controlled vocabulary to validate against |
required |
Notes
Callers are responsible for transaction boundaries; this function does not open a nested transaction or catch exceptions.
Source code in packages/climate-ref/src/climate_ref/executor/result_handling.py
ingest_series_values(database, result, execution, cv)
#
Load, validate, and bulk-insert series metric values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
database
|
Database
|
The active database session to use |
required |
result
|
ExecutionResult
|
The execution result containing the series filename |
required |
execution
|
Execution
|
The execution record to associate values with |
required |
cv
|
CV
|
The controlled vocabulary to validate against |
required |
Notes
Callers are responsible for transaction boundaries; this function does not open a nested transaction or catch exceptions.
Source code in packages/climate-ref/src/climate_ref/executor/result_handling.py
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 | |
mark_execution_failed(database, config, definition, execution_id, *, retryable, detail=None)
#
Persist a failed result for an outstanding execution.
Used when an executor abandons a future (per-task timeout, overall timeout,
worker crash) so the corresponding Execution row never stays stuck in
successful=None state.
detail is written to the execution's results log.
Source code in packages/climate-ref/src/climate_ref/executor/result_handling.py
process_result(config, database, result, execution, *, queue_seconds=None, detail=None)
#
Process the result of a diagnostic execution, persisting outcome to the DB.
queue_seconds is supplied by the submitting executor,
because only the parent knows when the task was submitted.
detail says why a failed execution failed and is written to its results log.
Source code in packages/climate-ref/src/climate_ref/executor/result_handling.py
record_failure(config, execution, reason, detail)
#
Mark the execution failed and append why to its results log, which is otherwise silent.
Source code in packages/climate-ref/src/climate_ref/executor/result_handling.py
record_lost_execution(config, execution, detail)
#
Fail an execution whose worker died before it returned a result
The partial log is copied from scratch first, so the results log shows how far it got. The group's dirty flag is left alone.
Source code in packages/climate-ref/src/climate_ref/executor/result_handling.py
record_resource_usage(execution, usage, queue_seconds)
#
Annotate an execution with its resource measurements, swallowing any failure.
These numbers are diagnostic metadata rather than scientific output, so losing a measurement is always preferable to losing a result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
execution
|
Execution
|
The execution record to annotate |
required |
usage
|
ResourceUsage | None
|
The measurements taken by the worker, or None when nothing was measured |
required |
queue_seconds
|
float | None
|
Submit-to-start latency observed by the submitting executor, or None when it is unknown |
required |
Source code in packages/climate-ref/src/climate_ref/executor/result_handling.py
register_execution_outputs(database, execution, outputs, output_type, *, base_path)
#
Register output entries in the database.
Each entry in outputs is resolved relative to base_path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
database
|
Database
|
The active database session to use |
required |
execution
|
Execution
|
The execution record to associate outputs with |
required |
outputs
|
dict[str, OutputDict] | None
|
Mapping of short name to |
required |
output_type
|
ResultOutputType
|
The type of output being registered |
required |
base_path
|
Path
|
Base directory for resolving relative filenames |
required |
Notes
Callers are responsible for transaction boundaries.