Recurrence figures for a patient; governance trains scenarios with external data; lifelines in the lock

This commit is contained in:
rockdrigo
2026-11-21 13:34:56 -06:00
parent a53179aa2e
commit 2c4bfa5691
6 changed files with 153 additions and 6 deletions
+7 -5
View File
@@ -17,7 +17,8 @@ from datetime import datetime, timezone
from pathlib import Path
TAIL_CHARS = 4000
# A domain whose scenarios train on a reference cohort and not on a dbt cohort build.
# A domain whose scenarios train on a reference cohort and not on a dbt cohort build; a scenario that says `external` in its
# `model.toml` does too, whatever its domain.
OWN_STEPS = {"tea": "Entrena con la cohorte de referencia de EEG (el clúster, o la carpeta de `TEA_REFERENCE_DIR`)."}
@@ -35,13 +36,13 @@ def catalog() -> list[dict]:
domain = spec.get("domain")
if domain is None:
continue
own = domain in OWN_STEPS
own = domain in OWN_STEPS or bool(spec.get("external"))
if not own and "scenario" not in spec:
continue
found.append({
"domain": domain, "scenario": spec.get("scenario", path.parent.name), "cohort": spec.get("cohort"),
"outcome": spec.get("outcome"), "description": " ".join(str(spec.get("description", OWN_STEPS.get(domain, ""))).split()),
"kind": "referencia" if own else "cohorte",
"kind": "referencia" if own else "cohorte", "external": own,
})
return found
@@ -52,7 +53,8 @@ def _base() -> Path:
def _command(domain: str, scenario: str) -> list[str]:
argv = [sys.executable, "-m", "models", "run", domain, scenario, "--environment", "prod", "--train", "--promote"]
if domain not in OWN_STEPS:
external = any(e["external"] for e in catalog() if (e["domain"], e["scenario"]) == (domain, scenario))
if not external:
argv += ["--export", "--source", "dbt", "--manifest", os.environ["DBT_MANIFEST"]]
elif domain == "tea" and os.environ.get("TEA_REFERENCE_DIR"):
# A reference cohort on this machine's disk, instead of the configured one in the cluster's storage.
@@ -100,7 +102,7 @@ def start(domain: str, scenario: str) -> dict:
"""Starts a job. `LookupError` for a scenario that cannot be trained, `RuntimeError` with no dbt manifest."""
if (domain, scenario) not in {(s["domain"], s["scenario"]) for s in catalog()}:
raise LookupError(f"no such model: {domain}/{scenario}")
if domain not in OWN_STEPS and not os.environ.get("DBT_MANIFEST"):
if not any(e["external"] for e in catalog() if (e["domain"], e["scenario"]) == (domain, scenario)) and not os.environ.get("DBT_MANIFEST"):
raise RuntimeError("No hay un manifest de dbt configurado.")
job_id = f"{datetime.now(timezone.utc):%Y%m%dT%H%M%S}-{uuid.uuid4().hex[:6]}"
folder = _base() / job_id