Skip to content

Closure Mode Ablation - #8

Merged
lee-leonardo merged 3 commits into
rishabshah:keepfrom
lee-leonardo:task/closure_mode_investigation
Nov 28, 2026
Merged

lee-leonardo merged 3 commits into
rishabshah:keepfrom
lee-leonardo:task/closure_mode_investigation

Conversation

@lee-leonardo

@lee-leonardo lee-leonardo commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

This investigates whether KEEP's existing path_source="closure" option changes the information available after ontology traversal: does it reconnect concepts that filtered direct relationships leave disconnected, recover failed ancestor mappings, or change the retained targets and paths supplied to later processing?

The contribution is a reproducible audit and explanatory notebook around the existing PyHealth readers and roll-up processor. It adds no production behavior or default changes. On one identified Athena bundle, closure improves connectivity and mapping coverage; whether those changes improve embeddings or downstream prediction remains unmeasured.

Start with the notebook, which separates executable synthetic examples from recorded full-release findings.

What is being compared?

Here, “closure” means a specific separation-one ancestry overlay, not every transitive ancestor relationship:

  • U: the uncut subtree of valid standard SNOMED Condition concepts under Disease, OMOP concept 4274025.
  • D: filtered direct Is a edges whose endpoints are in U, oriented parent → child.
  • P: unique CONCEPT_ANCESTOR pairs whose minimum separation is exactly one, with both endpoints in U.
  • Direct traversal follows D; closure traversal follows D ∪ P. Existing direct-edge provenance wins where the sets overlap.
Setting Held fixed in each direct/closure comparison
Root depths Athena minimum root separations, authoritative in both modes
Target eligibility Depth ≤ 5, Disease root excluded
Traversal universe Uncut subtree; deep sources and intermediate nodes remain available
Orphan rescue Disabled; longer rescue shortcuts are a separate intervention
Target policies Paired comparisons for both first_retained and all_retained
Failures Diagnostic on_unmapped="empty" preserves typed failures for counting; the production default remains "error"
Population Every concept in the same U, once per mode and policy

The distinction between graph layers matters: the factory's base KnowledgeGraph remains direct in both modes. The processor's traversal index receives the overlay, and projected sample graphs may include those additional successful paths. The audit does not edit the Athena export. An embedding trainer consuming only the unchanged base graph would not automatically receive the overlay.

What the audit measures

The helper independently extracts the direct and separation-one edge sets through public reader tables, checks factory provenance and target eligibility, then maps every subtree concept in bounded deterministic batches. It records:

  • Graph structure: edge-set overlap, closure-only edges, nodes without an incoming parent, and nodes unreachable from Disease along selected edges.
  • Mappings: identical targets, changed nonempty target sets, recovered no_target failures, lost mappings, and residual failures. Eligible identity mappings and excluded-root failures are counted separately from deep-source outcomes.
  • Traceability: release metadata, input/source hashes, processor fingerprints, ordered mapping digests, local difference/failure tables, and small decoded path witnesses.
  • Resources: reference extraction, factory and mapping timings, plus lifetime process peak RSS. These are resource observations rather than a controlled performance benchmark.

Synthetic check

The invented fixture has 12 subtree concepts, six eligible targets and five deep sources. Direct traversal has nine edges; closure adds two.

One new edge recovers a previously unmapped deep source. Another adds a branch-local first_retained target even though all_retained already reaches that target through another path. A separate filtered-intermediate example remains unmapped because repairing it would require a longer ancestry shortcut.

For either policy, deep failures fall from 2/5 to 1/5. Across all 12 concepts, failures fall from three to two, including the expected excluded root. These are hand-specified correctness examples, not estimates of clinical prevalence or a simulated full Athena release.

Recorded Athena results

The full-subtree audit was run on 2026-11-25 against OMOP Standardized Vocabularies v5.0 29-AUG-26. The supplied bundle identifies SNOMED International 2026-02-01, US 2026-03-01, and UK 2026-04-08. The notebook records table hashes and environment details. These observations cover this bundle's Disease subtree, not every Athena vocabulary or release.

Graph quantity Direct Closure
Subtree concepts 92,676 92,676
Eligible targets 69,445 69,445
Deep sources, depth > 5 23,230 23,230
Traversal edges 206,783 207,117
Non-root nodes without an incoming parent 36 11
Nodes unreachable from Disease along selected edges 190 133

The 334 additional edges are 0.162% of the direct edge count. Their importance cannot be inferred from that fraction alone.

Mapping outcome first_retained all_retained
Deep denominator 23,230 23,230
Direct / closure deep no_target 33 / 7 33 / 7
Recovered deep mappings 26 26
Changed nonempty target sets 26 39
Any changed target set, including recoveries 52 65
Lost mappings 0 0
All-subtree failures, including the excluded root 34 / 8 34 / 8

Both policies recover 26 of 33 deep failures (78.8%). The concept-level deep mapping failure rate falls from 0.142% to 0.030%, an absolute decrease of 0.112 percentage points. This is a full Athena-bundle observation, distinct from the synthetic check above. It measures mapping reachability, not semantic accuracy or patient-level coverage.

Seven deep failures remain. A separate diagnostic scan found eligible ancestors at separations three to five for all seven, but no selected traversal path reaches them. This shows the limits of a separation-one overlay; it does not establish that an orphan-rescue algorithm would repair every residual case.

Interpretation and limits

Closure can change coverage, represented targets and topology. Identical target sets can still hide different successful paths and therefore different projected graph inputs. The current census measures mapping outcomes across U, with selected graph witnesses; it does not yet enumerate all projected-graph changes or measure diagnosis-weighted exposure, co-occurrence changes, trained embeddings or predictive benefit.

More connectivity does not establish better representations. Next steps documented in the notebook include independent synthetic graph references, paired projected-graph comparisons, cutoff sensitivity, sample-level exposure and a separately scoped learning experiment. These are proposed extensions, not completed results. Neither target policy is certified against the original authors' artifact here.

Changes / additions

File Purpose
examples/keep_closure_mode_audit.py Synthetic input generator, matched direct/closure audit, provenance checks and local evidence export
examples/keep_closure_mode_audit.ipynb Motivation, executable examples, recorded release findings, learning implications and methodological extensions
tests/core/test_keep_closure_mode_audit.py Literal graph/mapping expectations, provenance and projected paths, failure classification, duplicate/order invariance, target preservation, and rejection of self-edges/cycles

This is separate from the ontology-loading optimization in #7. The recorded measurements used production baseline 33c2cb6, before that optimization, and should not be attributed to its performance changes. The audit can inform the choice of traversal configuration for the depth experiment in #9; it does not require changing that PR's reference before the branches merge.

Run it

From the PyHealth repository root:

# Synthetic data only; no credentials or vocabulary download needed.
python -m examples.keep_closure_mode_audit \
  --output-dir .artifacts/keep-closure-synthetic

# Focused regression tests.
python -m pytest tests/core/test_keep_closure_mode_audit.py -q

# Optional full-subtree census on an explicitly supplied Athena export.
python -m examples.keep_closure_mode_audit \
  --athena-dir /path/to/authorized/athena-export \
  --output-dir .artifacts/keep-closure-athena \
  --max-depth 5 --batch-size 512

The helper writes summary.json, per-policy difference/failure TSVs and path witnesses locally. Real input requires --athena-dir; there is no automatic dataset discovery or download. Keep licensed input and release-specific row exports local.

Validation record

  • The implementation's recorded focused and existing OMOP/roll-up checks passed 140 tests and eight subtests. The synthetic notebook ran in a fresh kernel; committed outputs are cleared.
  • Two full-release runs with batch sizes 512 and 137 reproduced non-resource summaries, processor fingerprints, ordered mapping digests and byte-identical difference/failure tables. Timing, memory, dirty-state text and batch size were excluded from that comparison.
  • The recorded main run used 0.447 s for public-reader extraction, approximately 1.03–1.04 s for direct factory builds and 1.11–1.12 s for closure builds. Lifetime process peak RSS was approximately 2.07 GiB across all phases. Concurrent validation and full ancestor materialization make these resource context, not a reliable relative-speed claim; full projected-graph costs were not measured.
  • These are the recorded implementation results, not a claim that the full Athena experiment was rerun for this description update.

AI assistance

OpenAI Codex assisted with the audit implementation, synthetic tests, notebook explanations, analysis and this description. The contributor directed the investigation's questions and scope. The numerical results above come from the recorded audit runs; AI-assisted interpretation does not establish clinical benefit or independent confirmation of the original KEEP implementation.

@lee-leonardo
lee-leonardo merged commit 4947f92 into rishabshah:keep Nov 28, 2026
lee-leonardo added a commit that referenced this pull request Nov 28, 2026
…ge (#8)

Add a reusable audit helper, synthetic semantic checks and a notebook comparing
direct Is a traversal with a minimum-separation-one ancestry overlay at fixed
root depths, eligibility and target policy. Record input identity, exact edge
deltas, structural gaps, typed mapping failures and local path witnesses.

On the identified Athena bundle, the overlay adds 334 edges, reduces nodes
unreachable from Disease from 190 to 133 and recovers 26 of 33 deep mapping
failures under both target policies. Seven deep failures remain. The eligible
target vocabulary is unchanged; additional nonempty target sets also change.

The base KnowledgeGraph remains direct; the traversal overlay can change
successful sample paths. Connectivity and coverage improve on this bundle,
but embedding quality and downstream learning effects remain inconclusive.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant