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.
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.
handle_execution_result(config, database, execution, result, *, update_dirty=True)
#
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
|
Source code in packages/climate-ref/src/climate_ref/executor/result_handling.py
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 455 456 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 | |
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
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 260 261 262 263 264 265 266 267 268 269 270 271 272 | |
mark_execution_failed(database, config, definition, execution_id, *, retryable)
#
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.
Source code in packages/climate-ref/src/climate_ref/executor/result_handling.py
process_result(config, database, result, execution)
#
Process the result of a diagnostic execution, persisting outcome to the DB.
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.