registry⚓︎
Explicit registry of selectable assimilation schemes.
PIPT historically resolved a scheme by string surgery on the config::
getattr(import_module('pipt.update_schemes.' + daalg[0]),
f'{daalg[1]}_{analysis}')
That failed badly: a typo in daalg surfaced as a bare
ModuleNotFoundError or AttributeError naming a symbol the user never
wrote, there was no way to ask what the valid combinations are, and any tool
wanting to list the available schemes had to guess at module contents.
A later refactor replaced the string surgery with an explicit table, but built
it from eighteen hand-written classes -- one per (scheme, analysis)
combination -- because the analysis flavour used to be baked into the class
through mixin composition. It no longer is: every algorithm class declares its
own COMPATIBLE_ANALYSES (flavour name -> analysis class) and takes
analysis as a constructor argument that picks from it (see
AnalysisBindingMixin for how). The per-combination classes had become pure
duplication -- esmda_approx was nothing but class esmda_approx(ESMDA):
FLAVOUR = "approx" -- so this module now derives the regular combinations
from two small tables instead of storing eighteen classes:
ALGORITHMS
One entry per algorithm, e.g. "esmda" -> ESMDA.
SPECIAL_SCHEMES
Combinations backed by a real, distinct implementation rather than a
registered analysis flavour -- esmda_hybrid (multilevel ES-MDA) is
an algorithm in its own right that happens to share the esmda name,
not an alias.
Extending the registry
Schemes living outside this repository can register themselves without editing this file::
from pipt.update_schemes.registry import register_scheme
register_scheme("myscheme", "approx", MyScheme)
available_schemes()
⚓︎
Return the registered (scheme, analysis) combinations, sorted.
get_scheme(scheme, analysis)
⚓︎
Look up the constructor for a (scheme, analysis) combination.
Returns:
| Type | Description |
|---|---|
callable
|
Either the class directly (for a :data: |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the combination is not registered. The message distinguishes an unknown scheme from a known scheme with an unsupported analysis flavour, and lists the valid options in both cases. |
register_scheme(scheme, analysis, cls, *, overwrite=False)
⚓︎
Add a scheme to the registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scheme
|
str
|
Scheme name, as it appears in the config's |
required |
analysis
|
str
|
Analysis flavour, as it appears in the config's |
required |
cls
|
type
|
Class implementing the combination. |
required |
overwrite
|
bool
|
Allow replacing an existing entry. Defaults to |
False
|