drop cohort builder plumbing; use kit cohorte_armado builds for MLflow lineage
This commit is contained in:
+25
-17
@@ -11,6 +11,8 @@ def _wire(monkeypatch, tmp_path, domain: str, base_module: str, base_class: str)
|
||||
engine = getattr(persistance_db, f"get_{domain}_engine")
|
||||
engine.cache_clear()
|
||||
importlib.import_module(f"core.{domain}.models")
|
||||
if domain != "governance":
|
||||
importlib.import_module(f"core.{domain}.indicadores.models")
|
||||
base = getattr(importlib.import_module(base_module), base_class)
|
||||
base.metadata.create_all(engine())
|
||||
return engine
|
||||
@@ -32,13 +34,7 @@ def cacu_db(tmp_path, monkeypatch):
|
||||
|
||||
@pytest.fixture
|
||||
def mlflow_tracking(tmp_path, monkeypatch):
|
||||
"""A local, SQLite-backed MLflow tracking URI — no server, no network,
|
||||
isolated per test (MLflow's own default local backend; the older plain
|
||||
file store is deprecated as of MLflow 3). Also `chdir`s into `tmp_path`:
|
||||
an experiment with no explicit `artifact_location` falls back to
|
||||
`./mlruns` relative to the CWD, and production never sets one either
|
||||
(the real MLflow server picks it, e.g. S3) — so this is purely test
|
||||
isolation, not something `models.training` should set itself."""
|
||||
"""A SQLite-backed MLflow per test; `chdir` keeps the default `./mlruns` in `tmp_path`."""
|
||||
import mlflow
|
||||
|
||||
uri = f"sqlite:///{tmp_path / 'mlflow.db'}"
|
||||
@@ -49,24 +45,16 @@ def mlflow_tracking(tmp_path, monkeypatch):
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def production_ready(governance_db, mlflow_tracking):
|
||||
def production_ready(governance_db, cacu_db, mlflow_tracking):
|
||||
"""Factory: registers a PROD version that passes every promotion check,
|
||||
returns (domain, scenario, version)."""
|
||||
from core.governance.enums import ArtifactKind, Environment
|
||||
from core.governance.models import CohortVersion
|
||||
from models.registry import registry
|
||||
from persistance.governance import cohort_version_repository
|
||||
|
||||
def make(tag: str, *, domain: str = "cacu", scenario: str = "tamizaje", metrics: dict | None = None):
|
||||
cohort = cohort_version_repository.create(
|
||||
CohortVersion(
|
||||
domain=domain, scenario=scenario, criteria_version="v1", version_hash=f"hash-{tag}",
|
||||
source_table=f"{domain}.episodioclinico", n_source=10, n_included=8,
|
||||
)
|
||||
)
|
||||
version = registry.register(
|
||||
domain=domain, scenario=scenario, environment=Environment.PROD,
|
||||
cohort_version_id=cohort.cohort_version_id, metrics=metrics or {"auc": 0.8},
|
||||
cohorte_armado_id=armado(f"huella-{tag}"), metrics=metrics or {"auc": 0.8},
|
||||
technical_validation_report_uri="docs/tecnica.pdf", clinical_validation_report_uri="docs/clinica.pdf",
|
||||
interpretability_report_uri="docs/interpretabilidad.html",
|
||||
)
|
||||
@@ -83,3 +71,23 @@ def tiny_onnx() -> bytes:
|
||||
x = onnx.helper.make_tensor_value_info("x", onnx.TensorProto.FLOAT, [1])
|
||||
y = onnx.helper.make_tensor_value_info("y", onnx.TensorProto.FLOAT, [1])
|
||||
return onnx.helper.make_model(onnx.helper.make_graph([node], "tiny", [x], [y]), producer_name="pytest").SerializeToString()
|
||||
|
||||
|
||||
def armado(huella: str) -> int:
|
||||
"""A CaCu cohort build with two attrition steps; returns its `armado_id`."""
|
||||
from datetime import date, datetime, timezone
|
||||
|
||||
from core.cacu.indicadores.models import CohorteArmado, CohorteExclusion
|
||||
from persistance.db import get_cacu_session
|
||||
|
||||
with get_cacu_session() as session:
|
||||
fila = CohorteArmado(
|
||||
url="cacu/cohorte_vigilancia", version="1.0", definicion_sha="d", reglas_sha="r", parametros="{}",
|
||||
datos_as_of=date(2025, 12, 31), huella=huella, marco_sha="m", n_miembros=8,
|
||||
armado_en=datetime(2026, 1, 1, tzinfo=timezone.utc))
|
||||
session.add(fila)
|
||||
session.flush()
|
||||
session.add_all([CohorteExclusion(armado_id=fila.armado_id, orden=1, paso="candidatas", n=10),
|
||||
CohorteExclusion(armado_id=fila.armado_id, orden=2, paso="sin evento previo", n=8)])
|
||||
session.commit()
|
||||
return fila.armado_id
|
||||
|
||||
Reference in New Issue
Block a user