3853cc552265602cf697fc349348036c74809ff2
models
Lo que rodea a los modelos de riesgo de CaCu, CaMa y TEA: registro de
versiones en MLflow con requisitos de promoción, registro de predicciones y
los trabajos de OCR de reportes. Las cohortes con que se entrena son los
armados del kit de indicadores (cohorte_armado, en la base de cada
dominio). Lee y escribe por los mismos repositorios de Persistance que usa
WebApi.
| Módulo | Qué hace |
|---|---|
__main__.py |
La línea de comandos: python -m models <comando>. Cada área agrega ahí sus subcomandos. |
io/contracts.py |
The shapes of the data: a cohort build's file (COHORT_SCHEMA), a cohort's rules (ExclusionRule, CohortQueries, BuiltCohort), an estimate's output (ESTIMATE_COLUMNS) and the risk contract (Risk, Provenance, RiskEstimator, which still takes the wide frame). |
io/storage.py |
Where data lives and how it's read and written: cohort and estimate Parquet files (read_cohort, write_once, read_metadata), dbt's manifest (read_queries), and Persistance repositories (resolve_repository, ReadOnlyRepository, ML-04). |
io/lineage.py |
What each output came from, in one vocabulary: registered names, tag keys, the hashes of code, files, tables and models (code_version, model_sha), and matches, the one rule for "already done". |
io/tracking.py |
TrainingRun: an MLflow run, with its cohort link (ML-03), artifacts (ML-01), environment (ML-02), git commit and log_model with its modelo_sha. In PROD, only models whose class lives in a module. inspect_onnx_metadata checks an ONNX checkpoint before it's logged. |
io/registry.py |
registry: versiones en MLflow (<dominio>-<escenario>), su linaje (armado y atrición), revisiones de promoción (ML-02, ML-03, MLD-01, MLD-01b, MLD-03) y el alias produccion. Registers a finished run as a version (register_run) and sets its description. PredictionService stores each single prediction with the version in production (MLD-4/5, EL-04b). |
steps/ |
Funciones puras que comparten todos los modelos: sin E/S, se prueban solas. |
pipelines/reading.py |
Los nodos de Hamilton con que lee todo DAG de un modelo: cohort_build, members, known_until y timeline (la línea de tiempo de los miembros, cortada en datos_as_of del armado y en known_until: su conocida_hasta o, si no tiene, el momento de la lectura). Los repositorios entran como insumos. |
steps/cohort.py, steps/cohort_file.py |
The plain functions the cohort pipelines list: the chain's steps, and from a population and the timeline to the file's table, its hash and its lineage. |
pipelines/cohort_build.py |
Builds a cohort: all patients → index date → A1 → … → An → study population. Lists the steps, gives each rule its own nodes and runs them. python -m models cohorts build cacu cohorte_vigilancia --manifest target/manifest.json [--graph] shows the attrition or the Mermaid diagram; it stores nothing. |
pipelines/export_cohort.py |
Exports a build to its Parquet file. python -m models cohorts export cacu cohorte_vigilancia [--build N] writes the kit's build once; --source dbt --manifest target/manifest.json builds it from dbt's rules into dbt/<n>.parquet and writes only when its rows change. The timeline comes from dbt's view <domain>_linea_de_tiempo. |
cacu/cin2_logistic/ |
El modelo de prueba de CaCu, sin significado clínico: sus pasos (model.py, nodos de Hamilton), su driver (train.py) y sus ajustes (model.toml). Solo lee el archivo Parquet del armado. Se entrena con `python -m models train cacu cin2_logistic [--armado N] [--environment dev |
cacu/, cama/, tea/ |
Un paquete por dominio, con sus escenarios y sus cuadernos (notebooks/, fuera del paquete instalado). |
ocr.py |
Los trabajos de OCR (OCR_JOBS): resultados de VPH, grado CIN y grado histológico desde los PDF guardados (VAR-01..09). |
testing.py |
Ayudas para las pruebas de otro código: CacuStandIn, un estimador determinista sin MLflow para correr la cadena de riesgos sin un modelo entrenado. No es un modelo clínico. |
MLflow se configura con sus propias variables (MLFLOW_TRACKING_URI).
MLFLOW_ARTIFACT_ROOT, si existe, es la carpeta donde los experimentos nuevos
guardan sus artefactos.
uv run pytest -q
Description
Languages
Python
100%