Governance: each version stores the drawing of its dataflow as files of its own

Training stores the scenario's Hamilton graph as `diagramas/pipeline.dot` and, when Graphviz's `dot` is installed,
`diagramas/pipeline.svg`, listed next to the version's other files. Without the `graphviz` package there is no
drawing and training goes on.
This commit is contained in:
2026-11-22 07:38:07 -06:00
parent e8c264e571
commit d090bb0f9f
4 changed files with 55 additions and 2 deletions
+2 -1
View File
@@ -216,7 +216,8 @@ def test_training_registers_a_version_and_estimating_dates_each_risk_by_the_mode
assert wrote and resolved.version == version
files = [f["path"] for f in registry.artifacts("cacu", "survival", version)]
assert {"analisis/curvas.json", "analisis/subgrupos.json", "reportes/subgrupos.html"} <= set(files)
assert {"analisis/curvas.json", "analisis/subgrupos.json", "reportes/subgrupos.html", "diagramas/pipeline.dot",
"diagramas/pipeline.svg"} <= set(files)
risks = pq.read_table(output).to_pandas()
assert set(risks["horizonte_anios"]) == {1.0, 3.0, 5.0} and set(risks["pac_id"]) == set(range(1, N + 1))
frame = read_cohort(cohort_file)
+25
View File
@@ -139,6 +139,21 @@ def test_training_registers_a_version_from_the_fitted_model_and_the_metrics(scen
assert training.find_trained(scenario, CohortFile(cohort_file)) == version
def test_training_stores_the_drawing_of_its_dataflow_as_files_of_the_version(scenario, cohort_file, mlflow_tracking):
"""Pins down: the version lists `diagramas/pipeline.dot` and, with Graphviz's `dot`, `diagramas/pipeline.svg`, one
file each (no archive), and the drawing names the scenario's nodes. Fails if training stops drawing its graph or
stores it as anything but separate files."""
pytest.importorskip("graphviz")
version = training.train(scenario, CohortFile(cohort_file))
files = {f["path"] for f in registry.artifacts("cacu", "fake_scenario", version)}
name, dot = registry.artifact("cacu", "fake_scenario", version, "diagramas/pipeline.dot")
assert name == "pipeline.dot" and b"fitted_model" in dot and b"metrics" in dot
assert "diagramas/pipeline.svg" in files or not training.pipeline_drawing(
training.dataflow(*scenario.modules, config=scenario.config))[1]
assert not any(path.endswith(".zip") for path in files)
def test_the_registered_model_runs_without_this_repository(scenario, cohort_file, mlflow_tracking,
predict_without_repository):
"""Pins down: the model's own package is pickled by value, so a Python that can't import `models`, Hamilton or the
@@ -196,3 +211,13 @@ def test_the_registered_model_needs_only_its_listed_requirements(scenario, cohor
assert f"scikit-learn=={installed('scikit-learn')}" in lines and f"numpy=={installed('numpy')}" in lines
assert not [line for line in lines if line.startswith("-e") or "/" in line]
def test_without_graphviz_training_has_no_drawing_and_still_registers():
"""Pins down: when Hamilton can't draw (no `graphviz` package, it gives None instead of raising), the drawing
is skipped rather than stopping the training. Fails if `pipeline_drawing` reads a missing graph."""
from types import SimpleNamespace
from models.dags.training import pipeline_drawing
assert pipeline_drawing(SimpleNamespace(display_all_functions=lambda *a, **k: None)) is None