Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,18 @@ training. Keep each algorithm's data-access and cluster approval rules in its ow

## Changes

### Unreleased

### 0.4.0a6 (2026-11-24)

- Add temporal-leakage conformance (`conformance/temporal.py`): `test_end_to_end` reruns the lifecycle with every
evaluated subject's events after its latest prediction time rewritten and requires predictions identical up to floating-point rounding (relative 1e-12);
the new inherited `test_null_world_predictions_are_at_chance` runs non-zero-shot profiles on a null world whose
future is independent of its past. `run_e2e` adapters must honour a perturbed `external_meds_dir` and accept the
`null_world` dataset. The suite grows from 38 to 44 collected tests.
- The future-blind rerun compares probabilities to a relative tolerance of 1e-12 (`FUTURE_BLIND_RTOL`) instead of
bit for bit: a leak-free polars score moved by one unit in the last place on a GitHub runner, while the smallest
measured leak moves a probability by about 1e-7.
- Stop the owned process group when the caller is terminated.
- Add an explicit raw-data access guard to the implementation prompt.
- Consolidate the template guides, implementation prompt and interactive builder on Read the Docs;
use Read the Docs as the only documentation host.
- Configure Read the Docs hosting with the existing MkDocs theme and docs dependency group; update
Expand Down
16 changes: 8 additions & 8 deletions RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ and [publishing action](https://docs.pypi.org/trusted-publishers/using-a-publish

## 2. Release the shared package first

Current candidate: **0.4.0a5**. Run the following in Bash/WSL with Git, GitHub CLI and uv installed.
Current candidate: **0.4.0a6**. Run the following in Bash/WSL with Git, GitHub CLI and uv installed.
Use the reviewed `main` commit, and wait for its CI checks before tagging. Do not move or reuse a
published release tag/version; increment `project.version` for a replacement.

Expand All @@ -53,11 +53,11 @@ uv run ruff format --check .
uv run pytest -q
uv build
uvx --from 'twine>=6' twine check --strict dist/*
git tag v0.4.0a5
git push origin v0.4.0a5
git tag v0.4.0a6
git push origin v0.4.0a6

gh workflow run publish.yml --repo McDermottHealthAI/meds-algorithm \
--ref v0.4.0a5 -f index=testpypi
--ref v0.4.0a6 -f index=testpypi
gh run list --repo McDermottHealthAI/meds-algorithm --workflow publish.yml --limit 5
# Select the run created above and watch it:
gh run watch RUN_ID --repo McDermottHealthAI/meds-algorithm --exit-status
Expand All @@ -76,7 +76,7 @@ check_env=$(mktemp -d)
uv venv "$check_env"
uv pip install --python "$check_env/bin/python" 'pyyaml>=6'
uv pip install --python "$check_env/bin/python" --no-deps \
--index-url https://test.pypi.org/simple/ 'meds-algorithm==0.4.0a5'
--index-url https://test.pypi.org/simple/ 'meds-algorithm==0.4.0a6'
"$check_env/bin/python" -I tests/wheel_smoke.py
uv pip check --python "$check_env/bin/python"
```
Expand All @@ -85,11 +85,11 @@ After the test release is verified, publish the same tag to PyPI and approve its

```bash
gh workflow run publish.yml --repo McDermottHealthAI/meds-algorithm \
--ref v0.4.0a5 -f index=pypi
--ref v0.4.0a6 -f index=pypi
# Find and watch the new run as above. After it succeeds:
pypi_env=$(mktemp -d)
uv venv "$pypi_env"
uv pip install --python "$pypi_env/bin/python" 'meds-algorithm==0.4.0a5'
uv pip install --python "$pypi_env/bin/python" 'meds-algorithm==0.4.0a6'
"$pypi_env/bin/python" -I tests/wheel_smoke.py
uv pip check --python "$pypi_env/bin/python"
```
Expand All @@ -99,7 +99,7 @@ See the official [TestPyPI guide](https://packaging.python.org/en/latest/guides/

## 3. Cut over and release the template

Only after `meds-algorithm==0.4.0a5` installs from PyPI, follow the
Only after `meds-algorithm==0.4.0a6` installs from PyPI, follow the
[template release guide](https://github.com/McDermottHealthAI/MEDS_algorithm_template/blob/main/RELEASING.md).
It switches the development and generated dependencies from the Git pin to the released package,
updates the lockfile/docs, and publishes the generator at **0.4.0a2** with tag **v0.4.0a2**.
Expand Down
4 changes: 2 additions & 2 deletions docs/core-package.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Shared core package

The core lives in its own [repository](https://github.com/McDermottHealthAI/meds-algorithm), pinned by the template to PyPI version `0.4.0a5`.
See its [layout and usage](https://github.com/McDermottHealthAI/meds-algorithm/blob/v0.4.0a5/README.md) for its artifact, runtime, task, evaluation, integration and conformance APIs.
The core lives in its own [repository](https://github.com/McDermottHealthAI/meds-algorithm), pinned by the template to PyPI version `0.4.0a6`.
See its [layout and usage](https://github.com/McDermottHealthAI/meds-algorithm/blob/v0.4.0a6/README.md) for its artifact, runtime, task, evaluation, integration and conformance APIs.
The [specification](reference/spec.md) and [architecture and UML](reference/architecture.md) are
rendered directly from this core checkout, the same sources included in its distributions.
The `latest` documentation follows core `main`; generated algorithms use their pinned installed release.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "meds-algorithm"
version = "0.4.0a5"
version = "0.4.0a6"
description = "Shared MEDS algorithm contracts and conformance boundaries."
readme = "README.md"
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion src/meds_algorithm/CONTRACT.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ dry-run, and its real end-to-end chain. The rendered `tests/test_end_to_end.py`
dataset in which every evaluated subject's events after its latest indexed prediction time are deleted
and replaced by plain events copied from the same shard at log-uniform offsets, many within seconds of
`T` (`conformance.temporal.perturb_future`). Histories at every indexed time, including the row order
of ties, are unchanged, so probabilities MUST be bit-identical by key. Any path from the future to a
of ties, are unchanged, so probabilities MUST be identical by key up to floating-point rounding (relative 1e-12). Any path from the future to a
prediction fails this check, even one the fitted model barely uses; no statistical threshold is
involved.
- **Temporal cutoff (null world):** for non-zero-shot profiles, the full lifecycle runs on
Expand Down
2 changes: 1 addition & 1 deletion src/meds_algorithm/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ in the generated `tests/e2e.py` and the shared `E2EResult`/`MEDSDevRun` types.
|---|---|---|
| `test_profile_implementations_match_contract` | Compares each registered profile's commands with the core lifecycle. | Detect incorrect registration or dispatch wiring. |
| `test_algorithm_configuration_roundtrips` | Saves and reloads each supplied concrete configuration. | Preserve settings across independent processes, including required constructor fields. |
| `test_end_to_end` | Runs each implemented profile and checks artifacts, manifests, coverage, fresh label-blind reruns, a fresh rerun with every evaluated subject's events after its latest prediction time rewritten (predictions must be bit-identical), split canaries and zero-shot task binding. | Detect broken persistence, label leakage, information from after the prediction time and transductive fitting through the real lifecycle. |
| `test_end_to_end` | Runs each implemented profile and checks artifacts, manifests, coverage, fresh label-blind reruns, a fresh rerun with every evaluated subject's events after its latest prediction time rewritten (predictions must be identical up to floating-point rounding, relative 1e-12), split canaries and zero-shot task binding. | Detect broken persistence, label leakage, information from after the prediction time and transductive fitting through the real lifecycle. |
| `test_null_world_predictions_are_at_chance` | Runs each completed non-zero-shot profile on a null world (homogeneous Poisson events; the label, any event in `(T, T + ln 2 / rate]`, is independent of the history) and applies a one-sided Mann-Whitney test, one key per held-out subject, at `alpha = 1e-3`. | End-to-end smoke alarm for temporal leaks that training learned to exploit, such as a forward time gap to the next real event. `run_e2e` must accept the `null_world` dataset with its test settings. |
| `test_completed_algorithm_has_a_completed_report` | Validates report evidence for every completed profile. | Prevent incomplete profiles from masking unsupported completion claims. |
| `test_algorithm_yaml_is_a_meds_dev_descriptor` | Checks each profile descriptor's required structure. | Catch packaging errors before integration. |
Expand Down
17 changes: 12 additions & 5 deletions src/meds_algorithm/conformance/temporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
from pathlib import Path

US_PER_HOUR = 3_600_000_000
# Future-blind comparison: a few units in the last place (see assert_future_blind_pipeline).
FUTURE_BLIND_RTOL, FUTURE_BLIND_ATOL = 1e-12, 1e-15
NULL_WORLD_DATASET = "null_world"
# (code, share of events, numeric mean, numeric sd); a None mean gives an event without a value.
NULL_WORLD_CODES: tuple[tuple[str, float, float | None, float | None], ...] = (
Expand Down Expand Up @@ -297,13 +299,18 @@ def assert_same_predictions(original, other, *, message: str, rtol: float = 1e-6
)


def assert_future_blind_pipeline(result, *, profile, run_e2e, tmp_path, tolerance: float = 0.0) -> None:
def assert_future_blind_pipeline(
result, *, profile, run_e2e, tmp_path, tolerance: float = FUTURE_BLIND_RTOL
) -> None:
"""Rerun every stage with each evaluated subject's future rewritten; predictions must not move.

Training data, seeds and the inputs at every indexed time are identical in both runs, so a deterministic
pipeline reproduces its predictions bit for bit; the default ``tolerance`` is therefore zero. A small
leak through a briefly trained conformance model can move a probability by only ~1e-7, which a float
tolerance would hide. Pass a relative ``tolerance`` only for a pipeline that is not bitwise reproducible.
pipeline reproduces its predictions up to floating-point rounding. The rewritten future changes how rows
are laid out in memory, and vectorized float kernels (polars, BLAS) can then round a result differently in
the last bit on some CPUs: a leak-free polars score moved by 5.6e-17 on a GitHub runner. The default
relative ``tolerance`` (1e-12, a few units in the last place) absorbs that and still catches a small
leak through a briefly trained conformance model, which moves a probability by about 1e-7. Pass a larger
relative ``tolerance`` only for a pipeline that is not reproducible to that precision.
"""
from meds_algorithm import ALGORITHM_PROFILES

Expand Down Expand Up @@ -337,7 +344,7 @@ def assert_future_blind_pipeline(result, *, profile, run_e2e, tmp_path, toleranc
read_predictions(result.artifacts[steps[-1]], require_truth=False),
read_predictions(prediction, require_truth=False),
rtol=tolerance,
atol=0.0,
atol=FUTURE_BLIND_ATOL,
message="Predictions changed when only events after every indexed prediction time were rewritten; "
"information from after the prediction time reaches the prediction",
)
15 changes: 15 additions & 0 deletions tests/test_temporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
read_index,
)
from meds_algorithm.conformance.temporal import (
FUTURE_BLIND_ATOL,
FUTURE_BLIND_RTOL,
NULL_WORLD_DATASET,
assert_chance_level,
assert_future_blind_pipeline,
assert_same_predictions,
build_null_world_dataset,
null_auroc_test,
perturb_future,
Expand Down Expand Up @@ -207,3 +210,15 @@ def test_perturbation_keeps_tie_order_and_never_copies_objects(tmp_path):
future = after.slice(4) # the old future (X) is gone; 8 new plain rows after T replace it
assert future.height == 8 and (future["time"] > t0 + timedelta(hours=2)).all()
assert set(future["code"]) <= {"Z//LAST", "A//FIRST", "M//MIDDLE", "X"}


def test_future_blind_tolerance_absorbs_rounding_but_not_leaks():
"""A leak-free polars score moved by one unit in the last place on a CI runner; a leak moves far more."""
keys = {"subject_id": [1, 2], "prediction_time": [0, 0]}
original = pl.DataFrame({**keys, "predicted_boolean_probability": [0.5, 1e-3]})
rounded = pl.DataFrame({**keys, "predicted_boolean_probability": [math.nextafter(0.5, 1), 1e-3]})
leaked = pl.DataFrame({**keys, "predicted_boolean_probability": [0.5 + 1e-9, 1e-3]})
check = {"rtol": FUTURE_BLIND_RTOL, "atol": FUTURE_BLIND_ATOL, "message": "moved"}
assert_same_predictions(original, rounded, **check)
with pytest.raises(AssertionError, match="1 of 2 keys moved"):
assert_same_predictions(original, leaked, **check)
6 changes: 3 additions & 3 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading