climate_ref.models.execution
#
Execution
#
Bases: CreatedUpdatedMixin, Base
Represents a single execution of a diagnostic
Each result is part of a group of executions that share similar input datasets.
An execution group might be run multiple times as new data becomes available,
each run will create a Execution.
Source code in packages/climate-ref/src/climate_ref/models/execution.py
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 252 253 254 255 256 257 258 259 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 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 | |
cpu_limit = mapped_column(Float, nullable=True)
class-attribute
instance-attribute
#
CPU cores available to the execution.
Read from the container cgroup quota at run time.
cpu_seconds = mapped_column(Float, nullable=True)
class-attribute
instance-attribute
#
CPU time consumed by the execution, in seconds.
Sums user and system time for the worker process and its children.
dataset_hash = mapped_column(index=True)
class-attribute
instance-attribute
#
Hash of the datasets used to calculate the diagnostic
This is used to verify if an existing diagnostic execution has been run with the same datasets.
datasets = relationship(secondary=execution_datasets)
class-attribute
instance-attribute
#
The datasets used in this execution
execution_group_id = mapped_column(ForeignKey('execution_group.id', name='fk_execution_id'), index=True)
class-attribute
instance-attribute
#
The execution group that this execution belongs to
memory_limit_bytes = mapped_column(BigInteger, nullable=True)
class-attribute
instance-attribute
#
Memory limit in force while the execution ran, in bytes.
Read from the container cgroup at run time.
A column rather than a context key because headroom is a comparison against
peak_memory_bytes that has to happen in SQL.
memory_source = mapped_column(nullable=True)
class-attribute
instance-attribute
#
Provenance of peak_memory_bytes.
One of cgroup, proc_tree, rusage or unavailable.
The sources measure different things and are not interchangeable.
output_fragment = mapped_column()
class-attribute
instance-attribute
#
Relative directory to store the output of the execution.
During execution this directory is relative to the temporary directory. If the diagnostic execution is successful, the executions will be moved to the final output directory and the temporary directory will be cleaned up. This directory may contain multiple input and output files.
path = mapped_column(nullable=True)
class-attribute
instance-attribute
#
Path to the output bundle
Relative to the diagnostic execution result output directory
peak_memory_bytes = mapped_column(BigInteger, nullable=True)
class-attribute
instance-attribute
#
Peak resident memory observed during the execution, in bytes.
Stored as a big integer because a plain integer overflows at 4 GiB on Postgres, and executions routinely peak well above that.
provider_version = mapped_column(nullable=True)
class-attribute
instance-attribute
#
Provider version recorded by the worker at run time.
Snapshot of the worker-installed provider.version when the execution ran.
Purely informational for audit; not used for validation or recomputation triggers.
Rows that predate the column stay NULL.
queue_seconds = mapped_column(Float, nullable=True)
class-attribute
instance-attribute
#
Time between submission and the start of the execution, in seconds.
Recorded by the submitting executor rather than the worker.
resource_context = mapped_column(nullable=True)
class-attribute
instance-attribute
#
Supporting detail for the resource measurements.
Host, CPU count, sampler settings and any cross-checks the worker made.
Both sampled peaks are kept here, under cgroup_peak_bytes and proc_tree_peak_bytes,
whichever of them peak_memory_bytes reports,
so which one to trust stays a read-time decision.
A large gap between the two says the cgroup was shared.
Purely informational, so nothing here is a query predicate.
resources_exclusive = mapped_column(nullable=True)
class-attribute
instance-attribute
#
Whether this execution had the worker's cgroup to itself.
Declared by the executor, which is the only party that knows its own concurrency. A cgroup reading covers the whole container, so it is meaningless when a container runs several executions at once. Non-exclusive measurements are excluded from aggregation by default.
retracted = mapped_column(default=False)
class-attribute
instance-attribute
#
Whether the diagnostic execution result has been retracted or not
This may happen if a dataset has been retracted, or if the diagnostic execution was incorrect. Rather than delete the values, they are marked as retracted. These data may still be visible in the UI, but should be marked as retracted.
successful = mapped_column(nullable=True, index=True)
class-attribute
instance-attribute
#
Was the run successful
wall_seconds = mapped_column(Float, nullable=True)
class-attribute
instance-attribute
#
Wall clock time taken by the execution, in seconds.
Measured by the worker as a monotonic delta around the diagnostic run.
apply_resource_usage(usage, *, queue_seconds=None)
#
Copy a worker's resource measurements onto this row.
Every value is coerced before any of them is assigned, so a value a column cannot store raises here rather than at flush, where the offending execution is no longer identifiable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
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. |
None
|
Source code in packages/climate-ref/src/climate_ref/models/execution.py
mark_failed()
#
mark_successful(path)
#
Mark the diagnostic execution as successful
Source code in packages/climate-ref/src/climate_ref/models/execution.py
register_datasets(db, execution_dataset)
#
Register the datasets used in the diagnostic calculation with the execution
Source code in packages/climate-ref/src/climate_ref/models/execution.py
ExecutionGroup
#
Bases: CreatedUpdatedMixin, Base
Represents a group of executions with a shared set of input datasets.
When solving, the ExecutionGroups are derived from the available datasets,
the defined diagnostics and their data requirements. From the information in the
group an execution can be triggered, which is an actual run of a diagnostic calculation
with a specific set of input datasets.
When the ExecutionGroup is created, it is marked dirty, meaning there are no
current executions available. When an Execution was run successfully for a
ExecutionGroup, the dirty mark is removed. After ingesting new data and
solving again and if new versions of the input datasets are available, the
ExecutionGroup will be marked dirty again.
The diagnostic_id and key form a unique identifier for ExecutionGroups.
Source code in packages/climate-ref/src/climate_ref/models/execution.py
25 26 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 | |
diagnostic_id = mapped_column(ForeignKey('diagnostic.id'), index=True)
class-attribute
instance-attribute
#
The diagnostic that this execution group belongs to
diagnostic_version = mapped_column(default=1, server_default='1')
class-attribute
instance-attribute
#
Diagnostic version that produced this group.
Read from the live Diagnostic.version class attribute at solve time.
Combined with diagnostic_id and key to form the unique identifier,
so v1 and v2 groups for the same key coexist as separate rows.
dirty = mapped_column(default=False)
class-attribute
instance-attribute
#
Whether the execution group should be rerun
An execution group is dirty if the diagnostic or any of the input datasets has been updated since the last execution.
key = mapped_column(index=True)
class-attribute
instance-attribute
#
Key for the datasets in this Execution group.
selectors = mapped_column(default=dict)
class-attribute
instance-attribute
#
Collection of selectors that define the group
These selectors are the unique key, value pairs that were selected during the initial groupby operation. These are also used to define the dataset key.
should_run(dataset_hash, rerun_failed=False, stale_cutoff=None)
#
Check if the diagnostic execution group needs to be executed.
The dirty flag is the primary signal for whether an execution group needs to be rerun.
It is set when the group is created or when new data is available,
and cleared when an execution completes (whether successful or not).
Manual intervention (flag-dirty, fail-running) can set it back to True.
The execution group should be run if:
- no executions have been performed ever
- the dataset hash is different from the last run
- the execution group is marked as dirty
rerun_failed=Trueis passed and the last execution failed
The execution group should NOT be run if:
- an execution with the same dataset hash is already in progress
- the last execution failed and the group is not dirty
(use
rerun_failed=Trueorflag-dirtyto retry)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_hash
|
str
|
Hash of the candidate datasets for this run. |
required |
rerun_failed
|
bool
|
Re-run the group even if the last execution failed and the group is not dirty. |
False
|
stale_cutoff
|
datetime | None
|
When provided,
an in-progress execution created before this timestamp is treated as already failed.
A real solve reaps such abandoned executions (via |
None
|
Source code in packages/climate-ref/src/climate_ref/models/execution.py
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 | |
ExecutionOutput
#
Bases: DimensionMixin, CreatedUpdatedMixin, Base
An output generated as part of an execution.
This output may be a plot, data file or HTML file. These outputs are defined in the CMEC output bundle.
Outputs can be tagged with dimensions from the controlled vocabulary to enable filtering and organization.
Source code in packages/climate-ref/src/climate_ref/models/execution.py
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 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 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 | |
description = mapped_column(nullable=True)
class-attribute
instance-attribute
#
Long description describing the plot
filename = mapped_column(nullable=True)
class-attribute
instance-attribute
#
Path to the output
Relative to the diagnostic execution result output directory
long_name = mapped_column(nullable=True)
class-attribute
instance-attribute
#
Human readable name describing the plot
output_type = mapped_column(index=True)
class-attribute
instance-attribute
#
Type of the output
This will determine how the output is displayed
short_name = mapped_column(nullable=True)
class-attribute
instance-attribute
#
Short key of the output
This is unique for a given result and output type
build(*, execution_id, output_type, dimensions, filename=None, short_name=None, long_name=None, description=None)
classmethod
#
Build an ExecutionOutput from dimensions and metadata
This is a helper method that validates the dimensions supplied.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
execution_id
|
int
|
Execution that created the output |
required |
output_type
|
ResultOutputType
|
Type of the output |
required |
dimensions
|
dict[str, str]
|
Dimensions that describe the output |
required |
filename
|
str | None
|
Path to the output |
None
|
short_name
|
str | None
|
Short key of the output |
None
|
long_name
|
str | None
|
Human readable name |
None
|
description
|
str | None
|
Long description |
None
|
Raises:
| Type | Description |
|---|---|
KeyError
|
If an unknown dimension was supplied. Dimensions must exist in the controlled vocabulary. |
Returns:
| Type | Description |
|---|---|
Newly created ExecutionOutput
|
|
Source code in packages/climate-ref/src/climate_ref/models/execution.py
ResultOutputType
#
Bases: Enum
Types of supported outputs
These map to the categories of output in the CMEC output bundle
Source code in packages/climate-ref/src/climate_ref/models/execution.py
get_execution_group_and_latest(session, among_executions=None)
#
Query to get the most recent result for each execution group
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
The database session to use for the query. |
required |
among_executions
|
Sequence[Any] | None
|
Optional predicates on |
None
|
Returns:
| Type | Description |
|---|---|
Query to get the most recent result for each execution group.
|
The result is a tuple of the execution group and the most recent result, which can be None. |
Source code in packages/climate-ref/src/climate_ref/models/execution.py
get_execution_group_and_latest_filtered(session, diagnostic_filters=None, provider_filters=None, facet_filters=None, dirty=None, successful=None, latest_successful=None, include_superseded=False)
#
Query execution groups with filtering capabilities.
By default, returns only execution groups whose diagnostic_version matches
the parent diagnostic's promoted_version so consumers see exactly one
version's worth of results.
Pass include_superseded=True to bypass the version filter and see the full history.
Success can be filtered in two different ways: successful and latest_successful.
successful=True keeps a group only if its newest run happened to succeed,
whereas latest_successful=True changes which run is chosen as newest.
The two compose but answer different questions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
Database session |
required |
diagnostic_filters
|
list[str] | None
|
List of diagnostic slug substrings (OR logic, case-insensitive) |
None
|
provider_filters
|
list[str] | None
|
List of provider slug substrings (OR logic, case-insensitive) |
None
|
facet_filters
|
dict[str, list[str]] | None
|
Dictionary mapping facet keys to lists of allowed values. Different keys are ANDed; multiple values for the same key are ORed. |
None
|
dirty
|
bool | None
|
If True, only return dirty execution groups. If False, only return clean execution groups. If None, do not filter by dirty status. |
None
|
successful
|
bool | None
|
Post-rank filter on the winning execution -- asks "is the latest execution successful?". If True, only return execution groups whose latest execution was successful. If False, only return execution groups whose latest execution was unsuccessful or has no executions. If None, do not filter by execution success. |
None
|
latest_successful
|
bool | None
|
Pre-rank population filter -- asks "what is the latest successful execution?". If True, rank only over successful executions, so the returned execution is each group's latest successful run (if any). If False, rank only over unsuccessful / in-progress executions. If None (default), rank over all executions. |
None
|
include_superseded
|
bool
|
If True, include execution groups for diagnostic versions older than the
currently promoted version.
If False (default), join |
False
|
Returns:
| Type | Description |
|---|---|
Query returning tuples of (ExecutionGroup, latest Execution or None)
|
|
Notes
- Diagnostic and provider filters use substring matching (case-insensitive)
- Multiple values within same filter type use OR logic
- Different filter types use AND logic
- Facet filters can either be key=value (searches all dataset types) or dataset_type.key=value (searches specific dataset type)
- This helper is the only sanctioned path for new callers that should respect the promoted-version filter.
The one acknowledged exception is the
cli/executions.py::statsaggregation, which inlines.join(Diagnostic).filter(ExecutionGroup.diagnostic_version == Diagnostic.promoted_version)because it returns aggregate rows rather than a list of tuples and so cannot reuse this helper. Operational queries that must remain version-agnostic (e.g.mark_failed_runningin the same module) intentionally do not use this helper at all.
Source code in packages/climate-ref/src/climate_ref/models/execution.py
705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 | |