Repository navigation
Add ARMR medication recommendation model (IJCAI 2025) - #1371
Conversation
ARMR (Wu et al., "ARMR: Adaptively Responsive Network for Medication Recommendation", IJCAI 2025) for the MIMIC-III/IV drug-recommendation tasks: piecewise temporal learning (recent visits through a feedforward network, distant ones through a pure-PyTorch Mamba block), the adaptively responsive module over reused and new drugs with time-decayed past use, and the joint direct/similarity recommendation with the BCE plus multi-label margin loss. Reimplemented from the paper's equations; the authors' code (no license) was only used to check open details. Optional co-occurrence and DDI graph embeddings follow the authors' code. Adds tests, a docs page and a Colab notebook comparing ARMR with GAMENet, SafeDrug and RETAIN on synthetic MIMIC-III and, with credentials, on MIMIC-III v1.4. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BdtuVKBLhWpYbhTQbaZaTt
|
/review |
Test CoverageTotal: 76.91% (23512 / 30571 lines)
|
There was a problem hiding this comment.
Previous review
AI Review
suggestion: need change
decision: need change
Thank you for contributing ARMR. It adds a new medication-recommendation model with piecewise temporal learning, an adaptively responsive module and a joint loss. It also adds docs, tests and a comparison notebook. The test file is clear, and coverage of armr.py is 96.3%, above the 80% bar. Whole-repository coverage is 75.7%, above the 60% bar.
To get this merged:
- The learned time decay (Eq. 9) has no effect on the output. In
_responsive_drugs,used(which containsdecay_scaleanddecay_rate) is a scalar per drug. It only multiplies that drug's embedding vector, and the model then scores drugs withF.cosine_similarity. Cosine similarity ignores a per-vector scale. For a drug the patient has taken,unusedis 0, sousedis only a rescaling. As a resultdecay_scaleanddecay_rateget essentially no gradient. Please feed the decay into something cosine similarity can see, for example by adding it to the per-feature attention logits or using it as a per-drug bias on the score. Alternatively, document that it is inert and drop it. Please also add a test that checks the decay parameters receive a non-zero gradient. - Duplicated helpers.
_ddi_adjand_hist_vocab_mapclosely mirror the existing GAMENet helpers (generate_ddi_adjand_build_drug_hist_vocab_map).SelectiveSSMreimplements the Mamba block already inehrmamba.py. Please reuse the existing code, or state in the PR why a separate version is needed (for example, no dependency onmamba_ssm). - Possible leakage in the co-occurrence graph.
_ehr_adjbuilds the graph from every sample in the dataset you pass in. The notebook passes the full dataset to every model, so test-patient labels shape the graph. Please build the graph from the training split only, or pass the training split to the model. The Part 1 comparison depends on this. - The reused/new test doesn't test the model code.
test_drug_history_splits_reused_and_new_drugsrecomputes the split with its own formula. It should call_responsive_drugs, or a factored-out helper, so it would catch problem 1.
Optional suggestions:
- Install the notebook from the upstream repo rather than a personal fork branch.
- Don't state the "about an hour" runtime for Part 2 until you have run it.
- The constructor writes to the shared
ddi_adj.npycache. You have already flagged this race, so a follow-up fix is fine.
Reviewed commit 7090d8c
- Eq. 9's decayed past use multiplied each drug's whole embedding, which the cosine similarity of Eq. 17-18 ignores, so decay_scale/decay_rate had no effect. Eq. 11 now uses the past-use indicator, and the decayed use is added to each drug's score as a recency term. Documented as a choice where the paper is open. - Move the DDI graph and drugs_hist -> label index map into pyhealth.models.utils (ddi_adjacency, history_to_label_index); GAMENet and ARMR both call them instead of keeping copies. - Document why SelectiveSSM is separate from ehrmamba.MambaBlock (input- dependent dt, B, C vs. a fixed per-channel SSM). - Document that the co-occurrence graph comes from the dataset passed in, so callers should pass the training split. - Tests call _split_reused_new and _responsive_drugs directly, check the recency term orders by lag, check the decay parameters get a gradient, and cover the two shared helpers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BdtuVKBLhWpYbhTQbaZaTt
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BdtuVKBLhWpYbhTQbaZaTt
- Models are built from the training split, so the drug co-occurrence graphs no longer see validation/test labels. - Colab installs from the upstream PR ref instead of a fork branch. - The DDI matrix comes from pyhealth.models.utils.ddi_adjacency. - Drop the unmeasured Part 2 runtime; describe the decay change. - Part 1 re-run with the updated model. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BdtuVKBLhWpYbhTQbaZaTt
|
Thanks for the review. Changes are in ecd70c7, 27012ac and 6bf16ad. Time decay had no effect (fixed). Agreed: the decayed use only rescaled each drug's embedding, and the cosine similarity ignores that. Eq. 11 now uses the past-use indicator to choose between the reused and new attention, and the decayed use (Eq. 9) is added to each drug's score in Eq. 19 as a recency term. The class docstring lists this as a choice where the paper is open. New tests check that Duplicated helpers (fixed for the two named; SSM kept with a reason). The DDI graph and the drugs_hist-to-label index map are now Co-occurrence graph leakage (fixed in the notebook, documented in the model). The notebook now builds every model from the training split ( Reused/new test (fixed). The split is factored into Optional points. The Colab cell now installs from the upstream PR ref ( Local results: the test_armr, test_gamenet, test_safedrug, test_micron and test_molerec tests pass, and |
|
/review |
There was a problem hiding this comment.
Previous review
AI Review
suggestion: need change
decision: need change
Thank you for contributing ARMR. It adds a pure-PyTorch implementation of the IJCAI 2025 model, with a selective-SSM block, piecewise temporal learning and the adaptively responsive module. It also comes with docs, a notebook and tests. The code is well documented, and the choices where the paper is open are stated clearly. The shared ddi_adjacency and history_to_label_index helpers are additive, and the GAMENet refactor looks behaviour-preserving.
Coverage meets the bar. armr.py is at 97.1%, gamenet.py at 89.7%, utils.py at 89.4% and __init__.py at 100%. The whole repository is at 75.7%, above the 60% guideline.
To get this merged:
- The new
ddi_adjacencyhelper inpyhealth/models/utils.pyduplicates DDI-matrix construction that is still inlined in SafeDrug (safedrug.py~L436), MoleRec (molerec.py~L678) and MICRON (micron.py~L353). Please either switch those models to the shared helper, so there is one implementation, or explain why they should keep their own. Check that the resulting matrices are identical.
Optional suggestions:
- ARMR's constructor writes to the shared
ddi_adj.npycache. You already flag the race this causes as a separate fix, so this is fine for now. Check whether ARMR needs to write that file at all, since it keepsddi_adj_normas a buffer. _visit_lengthscounts visits that have at least one code. If an empty visit sits in the middle of a sequence, the count will be too low. The shipped tasks filter such visits, but a short comment or a check would help.- When the PR merges, update the notebook's install cell, which currently points at the PR ref, and the Colab badge.
- The real MIMIC-III run is still pending. You state this clearly, so it is not blocking. Sharing the Part 2 results when you have them would be valuable.
Reviewed commit 6bf16ad
…sit lengths - SafeDrug, MICRON and MoleRec's generate_ddi_adj now call pyhealth.models.utils.ddi_adjacency. Checked first that each model's old matrix is identical (np.array_equal) to the helper's on the mimic3demo test data and synthetic MIMIC-III (full and training split). Their ddi_adj.npy writes are unchanged. - ARMR writes ddi_adj.npy with or without use_graph, since the "ddi" metric reads it during evaluation. - ARMR's _visit_lengths takes the position of the last non-empty visit, so an empty visit in the middle no longer shortens the sequence; test added. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BdtuVKBLhWpYbhTQbaZaTt
|
Follow-up to the re-review, in 9aba5ef. One DDI implementation (done). SafeDrug, MICRON and MoleRec's ARMR's ddi_adj.npy (kept, now always written). The Visit lengths (fixed). An empty visit is encoded as all padding, so counting non-empty visits undercounted a patient with an empty visit in the middle. That shifted the "last visit" and dropped drug history. The install cell and badge stay as they are until merge. The ARMR, GAMENet, SafeDrug, MICRON and MoleRec test modules pass when run one at a time, and |
|
/review |
There was a problem hiding this comment.
Previous review
AI Review
suggestion: need change
decision: need change
Thank you for this contribution. ARMR is a well-documented addition for the drug-recommendation tasks. It comes with a pure-PyTorch selective SSM, a notebook, and a shared ddi_adjacency / history_to_label_index helper that removes duplicated code across GAMENet, SafeDrug, MICRON and MoleRec. The model file has 97.6% coverage and the tests look thoughtful. You are close.
To get this merged:
- Label leakage in the default configuration. With
use_graph=True(the default),_ehr_adjbuilds the drug co-occurrence graph from every sample of the dataset passed in. Many PyHealth examples pass the full dataset to models, so test labels can end up in a GCN input and inflate metrics without any warning. The docstring warns about this, but the default does not guard against it. Please make this safe, for example by building the graph only from an explicit training split argument, by warning when the dataset looks unsplit, or by defaultinguse_graphtoFalse. - Coverage of modified files.
molerec.py(62.6%) andsafedrug.py(68.5%) are below the 80% per-file guideline. Most of the uncovered code is not code you changed. Please add a small test, or point to an existing one, that exercises the refactoredgenerate_ddi_adjin those two models. That would show the refactor is behaviour-preserving and bring the touched code under test. Overall repository coverage (75.7%) meets the 60% bar.
Optional suggestions:
- The
* self.label_sizefactor in_responsive_drugshas no effect, because the cosine similarity is scale-invariant. Consider removing it. - Every ARMR construction writes the shared
ddi_adj.npycache, which is the race you already flagged. A follow-up fix would help. - The notebook installs from
refs/pull/1371/head. Remember to switch that to a release ormasterafter merging. The description's Colab link also points to a fork. - The refactor of four existing models is behaviour-preserving as far as I can tell. Consider whether it belongs in a separate PR to keep this one focused.
Reviewed commit 9aba5ef
- ARMR takes graph_dataset, the samples its drug co-occurrence graph is built from. With use_graph=True and no graph_dataset it falls back to dataset and warns that the training split should be passed. The notebook passes the training split explicitly. - Drop the constant label_size factor on the weighted drug embeddings: they only feed the cosine similarity, which ignores a positive scale. - Tests: the warning, the graph built only from graph_dataset, and SafeDrug's and MoleRec's generate_ddi_adj matching ddi_adjacency. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BdtuVKBLhWpYbhTQbaZaTt
|
Follow-up to the third review, in 787c221. Label leakage with Coverage of the refactored DDI code (added).
Not changed, as explained before. The SafeDrug, MICRON and MoleRec refactor was what the previous review asked for. The shared The test_armr (14), test_safedrug (7) and test_molerec (8) modules pass when run one at a time, and |
|
/review |
|
Merged master (now including #1373) into this branch. CI's contribution-rules check was comparing against the new master and flagging untouched lines in |
|
/review |
There was a problem hiding this comment.
Previous review
AI Review
suggestion: need change
decision: need change
Thank you for this contribution. ARMR is a well-documented addition. It comes with a pure-PyTorch selective SSM, a docs page, a notebook, and a refactor that moves the shared ATC-3 DDI and history-index helpers into pyhealth/models/utils.py. The change looks self-contained, so I don't see a reason for a maintainer to be pulled in.
To get this merged:
- Eq. 11 attention normalization (
armr.py,_responsive_drugs). Bothtorch.softmax(..., dim=1)calls normalize over all M drugs. The description and notebook say a drug is weighted by attention over the reused drugs if the patient took it before, and over the new drugs otherwise. Please do one of two things:- Make the normalization match that description, for example by masking the softmax to the reused or new drugs.
- If softmax over all drugs is intended, say so explicitly in the docstring and notebook, and add a test that pins the behavior.
- Duplicated co-occurrence graph code.
ARMR._ehr_adjreimplementsGAMENet.generate_ehr_adj. Please share one implementation, as you already did forddi_adjacencyandhistory_to_label_index, rather than adding a second copy.
Optional suggestions:
- The notebook's Colab badge points to
master, which doesn't have ARMR until the PR is merged. Point it at the PR branch for now, or change it after merging. - Add a test for the attention normalization, since none of the current tests check it.
- Part 2 of the notebook (real MIMIC-III) hasn't been run yet. It would be good to add those results once you have credentials.
Coverage:
- The whole repository is at 76.17%, above the 60% bar.
armr.pyis at 97.7%.utils.py(89.4%),gamenet.py(89.7%),safedrug.py(85.5%) andmicron.py(83.3%) are also above the 80% bar.molerec.pyis at 65.9%, which is below the bar. The shortfall is mostly in existing code. Your added DDI test covers the lines you changed.
Reviewed commit 22723b9
- Eq. 11: the reused-drug attention is a softmax over the drugs the patient took before and the new-drug attention over the drugs never taken (masked softmax; an empty set gives zeros, no NaNs). The paper does not give the axis; the authors' code restricts each branch to its set. Test pins the normalization. - Move the co-occurrence graph into pyhealth.models.utils (ehr_cooccurrence_adjacency, for code lists or multi-hot tensors). ARMR and GAMENet call it. GAMENet still passes only unprocessed samples, so its matrix is unchanged (np.array_equal on mimic3demo and synthetic MIMIC-III, for processed samples and for raw code lists). - Notebook: Colab badge points at the PR branch; Part 1 re-run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BdtuVKBLhWpYbhTQbaZaTt
|
Follow-up to the review of 22723b9, in 3f4689f. Eq. 11 normalization (fixed). The paper defines Co-occurrence graph duplicated GAMENet (fixed). The graph is now built in one place, GAMENet's old loop skipped processed (tensor) labels. PyHealth 2.x samples are processed, so GAMENet's co-occurrence graph is in practice all zeros. To keep GAMENet's behaviour unchanged in this PR, it still passes only unprocessed samples to the helper. I compared GAMENet's matrix before and after the change with Optional. The Colab badge now points to the PR branch until merge. The ARMR, GAMENet, SafeDrug, MICRON and MoleRec test modules pass when run one at a time, and |
|
/review |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BdtuVKBLhWpYbhTQbaZaTt
- Notebook Part 2: the paper's ARMR results are in Table 3 (not Table 2), in %, mean ± std; checked against arXiv:2507.04428. Cite the metric definitions (Section 5.1) and the cohort (Table 2), and drop the unconfirmed "filtered by visit count". - Mark the examples that download the ATC DDI data with `# doctest: +SKIP` (ARMR, ddi_adjacency, SafeDrug; SafeDrug's text is identical to sunlabuiuc#1374's). - End-to-end test: Trainer trains ARMR for one epoch and evaluates. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BdtuVKBLhWpYbhTQbaZaTt
|
Follow-up to the review of 3f4689f, in dde9990. Before making these changes I merged master (including HeartLang, #1372) into the branch; there were no conflicts. Paper numbers (checked against arXiv:2507.04428 and corrected). The values are right, but they come from Table 3 ("The comparison results on MIMIC-III and MIMIC-IV datasets"), not Table 2, which holds the dataset statistics. Table 3 reports percentages, as mean ± std. For ARMR on MIMIC-III it gives Jaccard 54.51 ± 0.13, PRAUC 79.63 ± 0.28 and F1 69.59 ± 0.29. On MIMIC-IV it gives 51.74 ± 0.14, 76.95 ± 0.21 and 67.12 ± 0.18. The notebook now:
I removed "patients filtered by visit count", because I couldn't confirm it from the paper. Doctests. The examples that download the ATC DDI data are now marked Trainer test. A new test trains ARMR for one epoch with PR description. It now says that the shared co-occurrence helper keeps GAMENet's diagonal at zero. Before, a drug repeated within one visit could set it. It also says that GAMENet's co-occurrence graph is all zeros on processed samples, which predates this PR and is out of scope here. The synthetic Jaccard is updated to match the notebook (ARMR 24.48 vs 28.86–30.48), along with the other stale details.
The ARMR, GAMENet, SafeDrug, MICRON, MoleRec and HeartLang test modules pass when run one at a time, and |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BdtuVKBLhWpYbhTQbaZaTt
|
Merged master again (now including #1369). No conflicts; |
|
/review |
|
Merged master again (now including #1369). No conflicts; |
|
/review |
There was a problem hiding this comment.
Previous review
AI Review
suggestion: need change
decision: need change
Thank you for this contribution. It adds ARMR as a new drug-recommendation model with a pure-PyTorch selective SSM. It also moves the DDI and co-occurrence graph builders into shared helpers, and it comes with 17 tests and a notebook. The model logic reads correctly and the write-up is clear. The PR is close, with one thing to fix.
Coverage is fine. The total is 76.67%, above the 60% bar. armr.py is at 98.11%, and gamenet, micron, safedrug and utils are all above 80%. molerec.py is at 65.93%, but your change to it is a small refactor, so that gap isn't something this PR needs to close.
To get this merged:
- Make the default path safe against label leakage. With the default
use_graph=Trueand nograph_dataset, ARMR builds the drug co-occurrence graph from every sample indataset(armr.py, in__init__). In the usual workflow of building the model on the full dataset and then splitting, validation and test drug labels reach the model, which can silently inflate test metrics. AUserWarningalone is easy to miss. Please requiregraph_datasetwhenuse_graph=True, raising a clear error if it is missing. Alternatively, default to a path that doesn't read labels. Update the testtest_graph_without_graph_dataset_warnsto match.
Optional suggestions:
- ARMR rewrites the shared
ddi_adj.npycache on every construction. You already track the race in #1374, so this is fine for now. - The notebook's Colab badge and pip install point at a fork branch and a PR ref. Switch them to master or PyPI once merged.
- Once you have run Part 2 on real MIMIC-III, adding those numbers would help readers judge the reproduction.
Reviewed commit bf56c27
With the drug graphs (the default) and no graph_dataset, ARMR now raises a ValueError asking for the training split as graph_dataset, or use_graph=False, instead of falling back to the full dataset with a warning. Tests, docstring, docs page and notebook note updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BdtuVKBLhWpYbhTQbaZaTt
|
Follow-up to the review of bf56c27, in 55ab41b. Missing
The ARMR, GAMENet, SafeDrug, MICRON and MoleRec test modules pass when run one at a time, and |
|
/review |
There was a problem hiding this comment.
Previous review
AI Review
suggestion: need change
decision: need change
Thank you for this contribution. It adds ARMR as pyhealth.models.ARMR, with a pure-PyTorch selective SSM, shared DDI, co-occurrence and history-mapping helpers, docs, a notebook and 17 tests. The model looks carefully built, and you've described the choices you made where the paper is open. Your 17 tests cover shapes, gradients, the loss formula, the graph_dataset split and padding. Coverage is good: armr.py is at 98.1%, and utils.py, gamenet.py, micron.py and safedrug.py are above 80%. molerec.py shows 65.93%, but that is mostly existing code. Whole-repo coverage is 76.67%, above the 60% bar.
To get this merged:
_normalizeat the end ofarmr.pyrepeats theadj + Irow normalization already in GAMENet's GCN (gamenet.py, around lines 87-103). Please move it into a shared helper inpyhealth/models/utils.pyand use it from both places, or explain why they must differ. It is a small change, and it matches how you already shared the DDI and co-occurrence helpers.
Optional suggestions:
- Add a direct test for MICRON's
generate_ddi_adj, as you did for SafeDrug and MoleRec, since its refactor is currently untested. - The notebook's Colab badge and install cell point at a personal fork and a PR ref. Switch them to the main repo once the PR is merged.
- ARMR's constructor writes the shared
~/.cache/pyhealth/ddi_adj.npy. I understand #1374 addresses that race. - The Part 1 results are not like-for-like, because GAMENet's co-occurrence graph is all zeros on processed samples. You note this already, and a short remark next to the table would help readers.
Reviewed commit 55ab41b
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BdtuVKBLhWpYbhTQbaZaTt
- New pyhealth.models.utils.gcn_normalize_adjacency (D^-1 (A + I), zero rows stay zero). GAMENet's GCN and ARMR call it; ARMR's _normalize is removed. Normalized adjacencies are bit-identical before and after (torch.equal) for GAMENet's EHR/DDI GCNs and ARMR's buffers on mimic3demo and synthetic MIMIC-III. - Tests: the helper, and MICRON's generate_ddi_adj against ddi_adjacency. - Notebook Part 1: note that GAMENet's co-occurrence graph is all zeros on processed samples, so that comparison is not like-for-like. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BdtuVKBLhWpYbhTQbaZaTt
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BdtuVKBLhWpYbhTQbaZaTt
|
Follow-up to the review of 55ab41b, in ad3127b. Before making these changes I merged master (including TrajSurv, #1368) into the branch; there were no conflicts. Duplicated GCN normalization (fixed). The normalization now lives in one helper, The two implementations did not actually differ. Both are row normalization of
The PR rules wanted a Optional points (done). A MICRON test now checks The ARMR (18), GAMENet, MICRON (10), SafeDrug and MoleRec test modules pass when run one at a time, and |
|
/review |
| >>> gcn = GCN(adj=torch.tensor([[0.0, 1.0], [1.0, 0.0]]), hidden_size=4) | ||
| >>> gcn.adj | ||
| Parameter containing: | ||
| tensor([[0.5000, 0.5000], |
There was a problem hiding this comment.
[low] GCN docstring example shows the wrong Parameter repr
The new >>> gcn.adj example expects tensor([[0.5000, 0.5000],\n [0.5000, 0.5000]]). A Parameter with requires_grad=False prints Parameter containing: followed by tensor([[0.5000, 0.5000],\n [0.5000, 0.5000]], requires_grad=False), so the example does not match real output. Fix the expected output to include requires_grad=False, or mark the example # doctest: +SKIP as the other examples in the PR do.
| "source": [ | ||
| "# ARMR in PyHealth: medication recommendation on MIMIC-III\n", | ||
| "\n", | ||
| "[](https://colab.research.google.com/github/solarsys/PyHealth/blob/feat/armr/examples/armr_mimic3_drug_recommendation.ipynb)\n", |
There was a problem hiding this comment.
[low] Colab badge and install cell point at different repositories
The badge links to solarsys/PyHealth on branch feat/armr, but the setup cell installs git+https://github.com/sunlabuiuc/PyHealth@refs/pull/1371/head. Users who click the badge may run a different copy of the code than the one the setup cell installs. Point both at the same repository, for example the sunlabuiuc PR ref or the merged branch once this lands.
There was a problem hiding this comment.
AI Review
suggestion: approve
decision: approve
Thank you for adding ARMR (IJCAI 2025) as pyhealth.models.ARMR, with a pure-PyTorch selective SSM and shared DDI, co-occurrence, GCN-normalization and history-mapping helpers that GAMENet, SafeDrug, MICRON and MoleRec now use.
The change looks ready to merge. The model follows the paper's equations, graph_dataset is handled as you describe (including the ValueError when it is missing), and the refactors of the existing models keep their outputs the same, apart from the GAMENet diagonal change you documented. SelectiveSSM is distinct from ehrmamba.MambaBlock, as you explain, so this is not duplication.
Coverage: the whole repository is at 76.91%, above the 60% bar. armr.py is at 98.07%, utils.py at 92.19%, gamenet.py at 93.9%, safedrug.py at 85.49% and micron.py at 83.33%. molerec.py is at 65.93%, below the 80% guideline. The shortfall comes from existing code your diff doesn't touch, and your change there is covered by the new generate_ddi_adj test, so I don't consider it blocking.
Optional suggestions:
- Add a direct unit test for SelectiveSSM, for example checking causality, meaning that changing later steps leaves earlier outputs unchanged.
- The notebook's Colab badge points to solarsys/PyHealth, while the install cell uses sunlabuiuc/PyHealth. Aligning them would avoid confusion once the PR is merged.
- ARMR writes the shared ddi_adj.npy file in its constructor. That race is already tracked in #1374, so nothing is needed here.
Reviewed commit ad3127b
The five paper notebooks merged in #1368, #1369, #1371, #1372 and #1373 still installed PyHealth from their pull-request branches, and two Colab badges opened the fork's branch. They now install from sunlabuiuc master and open master's copy. The HeartLang notebook's PTB-XL download also failed in a clean environment: 32 parallel connections were reset by the S3 mirror, and a failed download left a truncated file that a rerun treated as finished. Downloads now retry with backoff, write to a temporary name and rename when complete, and use 8 threads. Claude-Session: https://claude.ai/code/session_01BdtuVKBLhWpYbhTQbaZaTt Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
… ones Six bounties are already fully merged but were still listed as open: 22 VAE (sunlabuiuc#1358), 27 YAIB (sunlabuiuc#1338, sunlabuiuc#1417, sunlabuiuc#1423), 40 DiPro (sunlabuiuc#1398), 43 ARMR (sunlabuiuc#1371), 56 TRACE (sunlabuiuc#1382) and 58 ETHOS-ARES (sunlabuiuc#1397). Eight more are partly merged. Their descriptions now say what is merged and what remains, so contributors can pick up the rest: 37 MIRA, 41 HeartLang, 42 APN, 52 APRICOT-M, 53 KnowRare, 54 LLMs as EHR Encoders, 55 MEME and 60 TrajSurv. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UxbiyTdwHAng6T548wdSda
Adds ARMR (Feiyue Wu, Tianxing Wu and Shenqi Jing, ARMR: Adaptively Responsive Network for Medication Recommendation, IJCAI 2025, arXiv:2507.04428) as
pyhealth.models.ARMR, for the existingDrugRecommendationMIMIC3/DrugRecommendationMIMIC4tasks.What it adds
pyhealth/models/armr.py:PiecewiseTemporalLearning(Eq. 1–4): the most recent visits through a feedforward network, earlier visits through a Mamba block, recent states attending over distant ones.SelectiveSSM: a pure-PyTorch Mamba block with input-dependent step size and B/C (Mamba's selection), unlike the time-invariantehrmamba.MambaBlock; nomamba_ssmdependency.0.7 · BCE + 0.3 · multi-label margin(Eq. 20–22).ARMR(..., graph_dataset=train_split)builds the co-occurrence graph from the training split; withuse_graph=True(the default)graph_datasetis required, and ARMR raises aValueErrorwithout it.pyhealth/models/utils.py:ddi_adjacency(now used by GAMENet, SafeDrug, MICRON, MoleRec and ARMR),history_to_label_index,ehr_cooccurrence_adjacencyandgcn_normalize_adjacency(GAMENet and ARMR).ARMRexported frompyhealth.models.tests/core/test_armr.py(18 tests): shapes with and without graphs, finite gradients, the loss falling in training, a Trainer train-and-evaluate run, inference without labels, the loss formula, the reused/new split, per-set attention normalization, the decay reaching the score, visit lengths with an empty middle visit, thegraph_dataseterror and split, PTL padding invariance, and the shared helpers. SafeDrug, MICRON and MoleRec tests checkgenerate_ddi_adjagainstddi_adjacency.examples/armr_mimic3_drug_recommendation.ipynb, a Colab notebook:MIMIC3_ROOTis set, next to the paper's Table 3 numbers.Implementation notes
use_graph(defaultTrue) adds GCN embeddings of the drug co-occurrence and DDI graphs, as the authors' code does.Falsefollows the paper's equations exactly.Reproduction status
Colab: https://colab.research.google.com/github/solarsys/PyHealth/blob/feat/armr/examples/armr_mimic3_drug_recommendation.ipynb
Behaviour notes for GAMENet
ehr_cooccurrence_adjacencykeeps the diagonal at zero. GAMENet's old loop could set a diagonal entry when a drug appeared twice in one visit's raw label list.Also found
~/.cache/pyhealth/ddi_adj.npy, and theddimetric reads it back. Two runs at once (e.g. tests alongside a notebook) overwrite each other's matrix, and evaluation fails with anIndexError. The notebook therefore computes the DDI rate from its own matrix. This is fixed separately in Fix the shared ddi_adj.npy cache race in the "ddi" metric #1374.🤖 Generated with Claude Code
https://claude.ai/code/session_01BdtuVKBLhWpYbhTQbaZaTt