climate_ref.solver
#
Solver to determine which diagnostics need to be calculated
This module provides a solver to determine which diagnostics need to be calculated.
DiagnosticExecution
#
Class to hold information about the execution of a diagnostic
This is a temporary class used by the solver to hold information about an execution that might be required.
Source code in packages/climate-ref/src/climate_ref/solver.py
dataset_key
property
#
Key used to uniquely identify the execution group
This key is unique to an execution group and uses unique set of metadata (selectors) that defines the group. This key is combines the selectors from each source dataset type into a single key and should be stable if new datasets are added or removed.
selectors
property
#
Collection of selectors used to identify the datasets
These are the key, value pairs that were selected during the initial group-by, for each data requirement.
build_execution_definition(output_root)
#
Build the execution definition for the current diagnostic execution
Source code in packages/climate-ref/src/climate_ref/solver.py
ExecutionSolver
#
A solver to determine which executions need to be calculated.
Source code in packages/climate-ref/src/climate_ref/solver.py
build_from_db(config, db)
staticmethod
#
Initialise the solver using information from the database
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db
|
Database
|
Database instance |
required |
Returns:
| Type | Description |
|---|---|
ExecutionSolver
|
A new ExecutionSolver instance |
Source code in packages/climate-ref/src/climate_ref/solver.py
solve(filters=None)
#
Solve which executions need to be calculated for a dataset
The solving scheme is iterative, for each iteration we find all diagnostics that can be solved and calculate them. After each iteration we check if there are any more diagnostics to solve.
Yields:
| Type | Description |
|---|---|
DiagnosticExecution
|
A class containing the information related to the execution of a diagnostic |
Source code in packages/climate-ref/src/climate_ref/solver.py
SolveFilterOptions
#
Options to filter the diagnostics that are solved
Source code in packages/climate-ref/src/climate_ref/solver.py
extract_covered_datasets(data_catalog, requirement)
#
Determine the different diagnostic executions that should be performed with the current data catalog
Source code in packages/climate-ref/src/climate_ref/solver.py
matches_filter(diagnostic, filters)
#
Check if a diagnostic matches the provided filters
Each filter is optional and a diagnostic will match if it satisfies all the provided filters. i.e. the filters are ANDed together.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
diagnostic
|
Diagnostic
|
Diagnostic to check against the filters |
required |
filters
|
SolveFilterOptions | None
|
Collection of filters to apply to the diagnostic If no filters are provided, the diagnostic is considered to match |
required |
Returns:
| Type | Description |
|---|---|
True if the diagnostic matches the filters, False otherwise
|
|
Source code in packages/climate-ref/src/climate_ref/solver.py
solve_executions(data_catalog, diagnostic, provider)
#
Calculate the diagnostic executions that need to be performed for a given diagnostic
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_catalog
|
dict[SourceDatasetType, DataFrame]
|
Data catalogs for each source dataset type |
required |
diagnostic
|
Diagnostic
|
Diagnostic of interest |
required |
provider
|
DiagnosticProvider
|
Provider of the diagnostic |
required |
Returns:
| Type | Description |
|---|---|
Generator[DiagnosticExecution, None, None]
|
A generator that yields the diagnostic executions that need to be performed |
Source code in packages/climate-ref/src/climate_ref/solver.py
solve_required_executions(db, dry_run=False, execute=True, solver=None, config=None, timeout=60, one_per_provider=False, one_per_diagnostic=False, filters=None)
#
Solve for executions that require recalculation
This may trigger a number of additional calculations depending on what data has been ingested since the last solve.
Raises:
| Type | Description |
|---|---|
TimeoutError
|
If the execution isn't completed within the specified timeout |
Source code in packages/climate-ref/src/climate_ref/solver.py
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 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 | |