Cycle: estimate with every scenario in production, one batch per model

The scenarios come from the registry instead of a fixed list, and a cohort can carry several estimators.
This commit is contained in:
2026-11-22 20:34:38 -06:00
parent e0967d0175
commit 2fe4101982
4 changed files with 59 additions and 67 deletions
+11 -38
View File
@@ -1,5 +1,5 @@
"""Live estimators for `Context.estimators`: the cycle's `estimate` step scores each cohort with the model version
its domain has in production.
"""Live estimators for `Context.estimators`: the cycle's `estimate` step scores each cohort with every model version
of its domain in production, one batch per model.
`estimate` hands an estimator the cohort build's wide frame (`estimar(columnas, filas)`, `procedencia()`,
`desenlace`): one column per the cohort's own variables. A registered model's predictors are a different, larger
@@ -11,7 +11,6 @@ unused by design.
from dataclasses import dataclass
from importlib import import_module
from typing import Any
@dataclass(frozen=True)
@@ -61,45 +60,19 @@ class ScenarioEstimator:
return self._provenance
class Cin2LogisticEstimator(ScenarioEstimator):
"""Scores CaCu's surveillance cohort with the `cacu-cin2_logistic` version in production (or `version`)."""
def __init__(self, domain: str = "cacu", version: str | None = None):
super().__init__(domain, "cin2_logistic", version)
self.desenlace = "cin2_mas"
# The scenarios the cycle estimates with, per domain other than CaCu: each one that has a version in production
# scores the cohort it names.
LIVE_SCENARIOS = {"cama": ("survival",)}
def _scenario_estimators(domain: str) -> dict[str, Any]:
def live_estimators(domain: str) -> dict[str, list[ScenarioEstimator]]:
"""The estimators of a domain's cohorts, by cohort url: one per scenario with a version in production in the
registry, so promoting or retiring a version is what adds or drops it. A registered name with no scenario
definition in `models` is skipped. Empty where none is in production, the same as no estimator being
configured: `estimate` then does nothing."""
from models.dags.training import Scenario
from models.io.registry import registry
found = {}
for name in LIVE_SCENARIOS.get(domain, ()):
scenario = Scenario.load(domain, name)
found: dict[str, list[ScenarioEstimator]] = {}
for name in registry.in_production(domain):
try:
registry.resolve(domain, name)
scenario = Scenario.load(domain, name)
except LookupError:
continue
found[scenario.cohort] = ScenarioEstimator(domain, name)
found.setdefault(scenario.cohort, []).append(ScenarioEstimator(domain, name))
return found
def live_estimators(domain: str) -> dict[str, Any]:
"""The estimators of a domain's cohorts whose model has a version in production, by cohort url. Empty where
none is in production yet, the same as no estimator being configured: `estimate` then does nothing."""
if domain != "cacu":
return _scenario_estimators(domain)
from models.dags.training import Scenario
from models.io.registry import registry
scenario = Scenario.load(domain, "cin2_logistic")
try:
registry.resolve(domain, scenario.scenario)
except LookupError:
return {}
return {scenario.cohort: Cin2LogisticEstimator(domain)}