Merge parity/F1a

This commit is contained in:
2026-12-01 11:51:43 -06:00
3 changed files with 13 additions and 20 deletions
+4 -11
View File
@@ -9,8 +9,10 @@ import os
import zipfile import zipfile
from collections.abc import Callable from collections.abc import Callable
from datetime import date from datetime import date
from typing import Any
import dagster as dg import dagster as dg
from pydantic import TypeAdapter
from core.domains import Domain from core.domains import Domain
from models import execution, graph from models import execution, graph
@@ -67,21 +69,12 @@ def _jobs(domain: str):
raise ValueError(f"{domain} has no models") from e raise ValueError(f"{domain} has no models") from e
class TrainingSourceConfig(dg.Config):
kind: str = "site"
folder: str | None = None
line_hz: int = 50
def model(self) -> cluster.TrainingSource:
return cluster.TrainingSource(**self.model_dump())
class Training(dg.Config): class Training(dg.Config):
domain: str domain: str
models: list[str] = [] # default: every model of the domain models: list[str] = [] # default: every model of the domain
as_of: str | None = None # the date the data are taken up to (default: today) as_of: str | None = None # the date the data are taken up to (default: today)
execution: ExecutionConfig = ExecutionConfig() execution: ExecutionConfig = ExecutionConfig()
source: TrainingSourceConfig | None = None source: dict[str, Any] | None = None
@dg.op @dg.op
@@ -93,7 +86,7 @@ def train_models(context: dg.OpExecutionContext, config: Training) -> dict:
if config.source is not None: if config.source is not None:
if "source" not in inspect.signature(jobs.train).parameters: if "source" not in inspect.signature(jobs.train).parameters:
raise ValueError(f"{config.domain} models take no training source") raise ValueError(f"{config.domain} models take no training source")
options["source"] = config.source.model() options["source"] = TypeAdapter(cluster.TrainingSource).validate_python(config.source)
found = {} found = {}
with execution.running(context, config.execution.model()): with execution.running(context, config.execution.model()):
for name in config.models or jobs.JOBS.routine(): for name in config.models or jobs.JOBS.routine():
+1 -1
View File
@@ -114,7 +114,7 @@ def train(
if name == ASSOCIATION: if name == ASSOCIATION:
return train_association(as_of) return train_association(as_of)
day = as_of or date.today() day = as_of or date.today()
digest, measured, cohort, hz = _cohort(source or cluster.TrainingSource(), day) digest, measured, cohort, hz = _cohort(source or cluster.SiteTrainingSource(kind="site"), day)
table = cohort_reference.tables(measured)[name] table = cohort_reference.tables(measured)[name]
baseline = curves.train(table, name) baseline = curves.train(table, name)
valid = [m for m in measured if m["valid"] and m["error"] is None] valid = [m for m in measured if m["valid"] and m["error"] is None]
+8 -8
View File
@@ -9,7 +9,7 @@ from models.jobs import EmptyCohort
from models.tea import jobs from models.tea import jobs
from models.tea.eeg import reference from models.tea.eeg import reference
from persistance import eeg from persistance import eeg
from persistance.cluster import TrainingSource from persistance.cluster import FolderTrainingSource, SiteTrainingSource
@pytest.fixture @pytest.fixture
@@ -40,23 +40,23 @@ def test_bad_folders_fail_with_a_reason(folder):
cohort, ages = folder cohort, ages = folder
for name in ("..", ".", "nope"): for name in ("..", ".", "nope"):
with pytest.raises(ValueError) as exc: with pytest.raises(ValueError) as exc:
jobs._cohort(TrainingSource(kind="folder", folder=name), date(2026, 1, 1)) jobs._cohort(FolderTrainingSource(kind="folder", folder=name), date(2026, 1, 1))
assert str(exc.value) == f"no reference cohort {name!r}" assert str(exc.value) == f"no reference cohort {name!r}"
ages.write_text("path,age\n0.edf,12\n1.edf,48\nnight/2.edf,60\n") ages.write_text("path,age\n0.edf,12\n1.edf,48\nnight/2.edf,60\n")
with pytest.raises( with pytest.raises(
ValueError, match="folder 'hel' has no EDF with an age from 16 to 36 months" ValueError, match="folder 'hel' has no EDF with an age from 16 to 36 months"
): ):
jobs._cohort(TrainingSource(kind="folder", folder="hel"), date(2026, 1, 1)) jobs._cohort(FolderTrainingSource(kind="folder", folder="hel"), date(2026, 1, 1))
ages.unlink() ages.unlink()
with pytest.raises(ValueError, match=r"folder 'hel' has no edades\.csv"): with pytest.raises(ValueError, match=r"folder 'hel' has no edades\.csv"):
jobs._cohort(TrainingSource(kind="folder", folder="hel"), date(2026, 1, 1)) jobs._cohort(FolderTrainingSource(kind="folder", folder="hel"), date(2026, 1, 1))
with pytest.raises(ValidationError, match="folder"): with pytest.raises(ValidationError, match="folder"):
TrainingSource(kind="folder") FolderTrainingSource(kind="folder")
with pytest.raises(ValidationError, match="line_hz"): with pytest.raises(ValidationError, match="line_hz"):
TrainingSource(kind="folder", folder="hel", line_hz=55) FolderTrainingSource(kind="folder", folder="hel", line_hz=55)
def test_the_site_trains_on_children_without_the_diagnosis_by_the_cut_off(fresh_platform): def test_the_site_trains_on_children_without_the_diagnosis_by_the_cut_off(fresh_platform):
@@ -94,8 +94,8 @@ def test_the_site_trains_on_children_without_the_diagnosis_by_the_cut_off(fresh_
{"key": "a", "age_months": 20.0, "valid": True, "error": None, {"key": "a", "age_months": 20.0, "valid": True, "error": None,
"features": {"eeg-gradient": {"value": 1.0}}}, "features": {"eeg-gradient": {"value": 1.0}}},
] # fmt: skip ] # fmt: skip
digest, measured, cohort, hz = jobs._cohort(TrainingSource(), cut) digest, measured, cohort, hz = jobs._cohort(SiteTrainingSource(kind="site"), cut)
assert (cohort, hz, [m["key"] for m in measured]) == ("site", None, ["a"]) assert (cohort, hz, [m["key"] for m in measured]) == ("site", None, ["a"])
assert len(digest) == 64 assert len(digest) == 64
with pytest.raises(EmptyCohort, match="without the diagnosis by 2025-01-01"): with pytest.raises(EmptyCohort, match="without the diagnosis by 2025-01-01"):
jobs._cohort(TrainingSource(), date(2025, 1, 1)) jobs._cohort(SiteTrainingSource(kind="site"), date(2025, 1, 1))