TEA EEG: training and analysis choose the cluster, EEG ids are text, run progress snapshots; tea library pointer

This commit is contained in:
ulises
2026-11-23 09:29:26 -06:00
parent f9d97f4d12
commit 2a04ee8c8e
9 changed files with 564 additions and 56 deletions
+24 -14
View File
@@ -19,6 +19,7 @@ from dataclasses import dataclass
from pathlib import Path
import pandas as pd
from tea.pipeline.run_monitor import active_monitor, monitor_from_env
from models.io.lineage import (
COHORT_BUILD_TAG,
@@ -78,7 +79,7 @@ def list_reference(s: Settings) -> list[tuple[str, float]]:
def listing(s: Settings, cluster: str = "auto") -> Listing:
from tea.pipeline.dask_runner import run as run_batch
(found,) = run_batch(list_reference, [(s,)], cluster=cluster)
(found,) = run_batch(list_reference, [(s,)], cluster=cluster, track_progress=False)
return Listing.of(s.reference.name, found)
@@ -146,9 +147,14 @@ def train_scenario(scenario: str, studies: list[ReferenceStudy], found: Listing,
biomarker, phase = s.scenarios[scenario]
data = table(studies, biomarker, phase)
module = type(pipeline(s).module(biomarker))(baseline=s.baseline)
monitor = active_monitor()
if monitor is not None:
monitor.phase("ajustando")
module.train(data)
sha, state = _module_state(module)
name = registered_name(DOMAIN, scenario)
if monitor is not None:
monitor.phase("registrando")
# Created here first so it lives under MLFLOW_ARTIFACT_ROOT; `log_biomarker` alone would put it in ./mlruns.
experiment_id(MlflowClient(), name)
mv = log_biomarker(module, plan=plan(s), registered_name=name, run_name=scenario, n_reference=len(data),
@@ -210,19 +216,23 @@ def train_all(s: Settings, environment: str, *, cluster: str = "auto", found: Li
"""Every scenario's version, by scenario: (version, whether it's new). A scenario already trained on the same
listing, plan, module version and baseline keeps its version; the reference cohort is measured only if some
scenario needs it."""
found = found or listing(s, cluster)
out, pending = {}, []
for scenario in s.scenarios:
existing = find_trained(scenario, expected_tags(scenario, found, s, environment))
if existing is not None:
out[scenario] = (str(existing.version), False)
else:
pending.append(scenario)
if pending:
studies = studies if studies is not None else measure(found, s, cluster)
for scenario in pending:
out[scenario] = (train_scenario(scenario, studies, found, s, environment), True)
return out
with monitor_from_env() as monitor:
found = found or listing(s, cluster)
out, pending = {}, []
for scenario in s.scenarios:
existing = find_trained(scenario, expected_tags(scenario, found, s, environment))
if existing is not None:
out[scenario] = (str(existing.version), False)
else:
pending.append(scenario)
if pending:
if studies is None:
monitor.total(len(found.studies))
monitor.phase("midiendo")
studies = measure(found, s, cluster)
for scenario in pending:
out[scenario] = (train_scenario(scenario, studies, found, s, environment), True)
return out
def latest(scenario: str, environment: str):