diff --git a/README.md b/README.md index 4b46b24..0323f5b 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/RELEASING.md b/RELEASING.md index d43ed28..7547112 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -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. @@ -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 @@ -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" ``` @@ -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" ``` @@ -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**. diff --git a/docs/core-package.md b/docs/core-package.md index 1034c77..9d4d271 100644 --- a/docs/core-package.md +++ b/docs/core-package.md @@ -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. diff --git a/pyproject.toml b/pyproject.toml index 1504a59..d1a6b52 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/src/meds_algorithm/CONTRACT.md b/src/meds_algorithm/CONTRACT.md index e6b85d2..0eb1733 100644 --- a/src/meds_algorithm/CONTRACT.md +++ b/src/meds_algorithm/CONTRACT.md @@ -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 diff --git a/src/meds_algorithm/TESTING.md b/src/meds_algorithm/TESTING.md index 1bcc492..28b17be 100644 --- a/src/meds_algorithm/TESTING.md +++ b/src/meds_algorithm/TESTING.md @@ -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. | diff --git a/src/meds_algorithm/conformance/temporal.py b/src/meds_algorithm/conformance/temporal.py index be8d21d..1b73737 100644 --- a/src/meds_algorithm/conformance/temporal.py +++ b/src/meds_algorithm/conformance/temporal.py @@ -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], ...] = ( @@ -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 @@ -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", ) diff --git a/tests/test_temporal.py b/tests/test_temporal.py index 5d742c9..71f68b9 100644 --- a/tests/test_temporal.py +++ b/tests/test_temporal.py @@ -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, @@ -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) diff --git a/uv.lock b/uv.lock index 8be283b..3178e06 100644 --- a/uv.lock +++ b/uv.lock @@ -438,7 +438,7 @@ wheels = [ [[package]] name = "meds-algorithm" -version = "0.4.0a5" +version = "0.4.0a6" source = { editable = "." } dependencies = [ { name = "pyyaml" }, @@ -1138,7 +1138,7 @@ resolution-markers = [ "python_full_version < '3.12'", ] dependencies = [ - { name = "numpy", version = "2.4.6", source = { registry = "https://pypi.org/simple" } }, + { name = "numpy", version = "2.4.6", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.12'" }, ] sdist = { url = "https://files.pythonhosted.org/packages/7a/97/5a3609c4f8d58b039179648e62dd220f89864f56f7357f5d4f45c29eb2cc/scipy-1.17.1.tar.gz", hash = "sha256:95d8e012d8cb8816c226aef832200b1d45109ed4464303e997c5b13122b297c0", size = 30573822, upload-time = "2026-02-23T00:26:24.851Z" } wheels = [ @@ -1212,7 +1212,7 @@ resolution-markers = [ "python_full_version >= '3.12'", ] dependencies = [ - { name = "numpy", version = "2.5.4", source = { registry = "https://pypi.org/simple" } }, + { name = "numpy", version = "2.5.4", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.12'" }, ] sdist = { url = "https://files.pythonhosted.org/packages/7e/74/66de6258867beb2ef08f35f9f2ac017a52cacd5081714d239ff1a442d458/scipy-1.18.1.tar.gz", hash = "sha256:52c4b7422442aba924d03ad4019852b08a92e64ea187b933135687bfe2747307", size = 30781235, upload-time = "2026-08-21T23:28:50.599Z" } wheels = [