Repository navigation
Conversation
Part 1 of 4 of sunlabuiuc#1609. Co-authored-by: rainiehu <57816421+Rainie-Hu@users.noreply.github.com>
Test CoverageTotal: 88.84% (62149 / 69959 lines)
|
|
/review |
| num_workers=num_workers, | ||
| ) | ||
| if itemid_map is not None: | ||
| self.sub_datasets["ehr"].itemid_map = os.fspath(itemid_map) |
There was a problem hiding this comment.
Fixed in bd76618 and f6d0cfc: a custom itemid_map now adds a digest of its file to dataset_name, so each map gets its own cache (test: test_custom_item_map_gets_its_own_cache), and MedModMIMIC4Dataset.set_task raises a ValueError when the task's item ids are not all in the dataset's map (test: test_task_item_ids_must_be_in_the_dataset_map).
| ------------------ | ||
|
|
||
| MedMod's models read their data through two code paths, and the task | ||
| reproduces each. Both use the same cohort, labels and split; only the EHR rows |
There was a problem hiding this comment.
Fixed in bd76618: the "Per-model settings" section now says the task sets the EHR rows with hours_zero, returns image_path and applies no image transform, and that the "Image transform" column is what the model's own image loader applies.
There was a problem hiding this comment.
Previous review
AI Review
suggestion: need change
decision: human review
Thank you for this contribution. It adds MedMod's in-hospital mortality pipeline to PyHealth. That means a MIMIC-IV v1.0 + MIMIC-CXR dataset with MedMod's fixed split, a task that builds one 48 × 76 EHR sample per ICU stay, and an EHR processor. Your description of why this is a separate dataset and task is clear. The subclassing of MIMIC4Dataset and MIMIC4EHRDataset is named with its reason. Coverage meets the bar: the whole repository is at 87.14%, and every changed file under pyhealth/ is above 92%.
This is close. One documentation fix is needed.
To get this merged:
- In
docs/api/tasks/pyhealth.tasks.MedModInHospitalMortality.rst, the "Per-model settings" section says the task reproduces each model's code path, including an "Image transform" column (ImageNet-normalized vs. pixels in [0, 1]). The task only exposeshours_zeroand returnsimage_path. It applies no image transform and has no setting for one. Please reword that section so the image-transform column is clearly guidance for the downstream model or loader, not behavior of this task. Alternatively, remove the column.
Optional suggestions:
MedModMIMIC4Dataset(itemid_map=...)filters the event table before PyHealth caches it. The cache key does not include the item map. If someone uses a different map with the samecache_dir, they will silently reuse a table filtered with the old map. Consider putting a digest of the map indataset_nameor the cache path. You could also state in the docstring that a custom map needs a freshcache_dir.MedModEHRSequenceProcessorhas no consumer in this PR. A short note in its docstring saying which later PR uses it would help reviewers.- The docs page quotes the 6,214-stay parity and the AUROC figures. The tests in this PR don't reproduce them. A one-line pointer to how you obtained them would make them easier to trust.
Reviewed commit 4401bfa
The task page now says the image transform belongs to the model's image loader; the task returns image_path only. A custom itemid_map adds a digest of its file to dataset_name, so each map gets its own PyHealth cache, with a test that builds two maps on one cache_dir. Co-authored-by: rainiehu <57816421+Rainie-Hu@users.noreply.github.com>
The dataset drops events outside its item map before caching, so a task whose item map has other ids would silently miss their events. set_task now raises a ValueError naming them, with a test. This is the second half of the AI review's item-map comment. Co-authored-by: rainiehu <57816421+Rainie-Hu@users.noreply.github.com>
| num_workers=num_workers, | ||
| ) | ||
| if itemid_map is not None: | ||
| self.sub_datasets["ehr"].itemid_map = os.fspath(itemid_map) |
There was a problem hiding this comment.
Fixed in bd76618 and f6d0cfc: a custom itemid_map now adds a digest of its file to dataset_name, so each map gets its own cache (test: test_custom_item_map_gets_its_own_cache), and MedModMIMIC4Dataset.set_task raises a ValueError when the task's item ids are not all in the dataset's map (test: test_task_item_ids_must_be_in_the_dataset_map).
| ------------------ | ||
|
|
||
| MedMod's models read their data through two code paths, and the task | ||
| reproduces each. Both use the same cohort, labels and split; only the EHR rows |
There was a problem hiding this comment.
Fixed in bd76618: the "Per-model settings" section now says the task sets the EHR rows with hours_zero, returns image_path and applies no image transform, and that the "Image transform" column is what the model's own image loader applies.
|
/review |
|
|
||
| def find_class(self, module: str, name: str) -> type: | ||
| if (module, name) not in self._ALLOWED: | ||
| raise pickle.UnpicklingError(f"global {module}.{name} is not allowed") |
There was a problem hiding this comment.
[medium] Restricted unpickler's refusal is untested
_NumpyOnlyUnpickler.find_class raises pickle.UnpicklingError for any global outside the numpy allow-list, and Normalizer.load_params documents that other objects are refused. The MedMod tests only load the bundled ph_ts1.0.normalizer (the positive path). No test checks the refusal. Add a test in tests/core/test_medmod_mimic4_processor.py that writes a pickle whose payload references a disallowed global (for example os.system or builtins.eval) and asserts that Normalizer().load_params(path) raises pickle.UnpicklingError. Without this, the security property the docstring claims has no coverage.
| return (True, False) # time bins, then features | ||
|
|
||
|
|
||
| class MedModEHRSequenceProcessor(MedModEHRProcessor): |
There was a problem hiding this comment.
[low] MedModEHRSequenceProcessor is unused and undocumented in this PR
Nothing in this PR uses MedModEHRSequenceProcessor: the task uses MedModEHRProcessor, and the description does not mention the class. It is only exercised by its own test. If it is for the models PR (#1638), move it there; otherwise remove it. This keeps the processor API surface to what the description describes.
| :undoc-members: | ||
| :show-inheritance: | ||
|
|
||
| Per-model settings |
There was a problem hiding this comment.
[low] Task API page is much longer than comparable pages
The 'Per-model settings' and 'Paper vs code' sections, with file:line citations into the MedMod and MedFuse repositories and CI-level experiment numbers, add a lot to an API reference page. Keep the short 'hours_zero' and 'normalizer' explanation on the page, and move the paper-vs-code table and experiment results to the PR description or a short note. Comparable task pages in docs/api/tasks/ do not carry this detail.
| """One sample per ICU stay that survives MedMod's IHM pipeline. | ||
| Sample: ``patient_id`` (subject_id), ``visit_id`` (stay_id), ``ehr`` | ||
| (float32, (48 / timestep) x 76: 48 x 76 by default), ``image_path`` |
There was a problem hiding this comment.
[low] Docstring says ehr is float32, but direct calls return float64
The class docstring describes the sample's ehr as float32. That holds after set_task runs the MedModEHRProcessor. task(patient) and StayResult.sample() return the unnormalized float64 array; test_sample_format asserts float64. Say that the float32, standardized tensor comes from the processor in set_task, and that __call__ returns the raw binned values.
There was a problem hiding this comment.
AI Review
suggestion: approve
decision: human review
Thank you for this contribution, and for splitting #1609 into reviewable parts. It adds MedMod's in-hospital mortality pipeline: MedModMIMIC4Dataset with the fixed MedMod split, the MedModInHospitalMortality task with its 48×76 discretized EHR, and MedModEHRProcessor. It looks ready to merge.
- Not a duplicate: the description explains why this isn't redundant with
EHRCXRMortalityMIMIC4andMedModDecompensationMIMIC4. Those use a 34-column EHR, and this adds MedMod's 76-column one. - Sharing is disclosed: subclassing
MIMIC4DatasetandMIMIC4EHRDatasetis named in the description with its purpose, which is to reuse the MIMIC-IV loading. - Dataset source: the docs page and module docstring cite the MedMod paper and code, and link to the MIMIC-IV and MIMIC-CXR-JPG sources.
- Coverage: the whole repository is at 87.14%, above the 60% bar. Every added file is above 80%, from 92.6% for
extraction.pyto 100% formedmod_mimic4.py.
Optional suggestions:
- Unpickler test: add a small test that
_NumpyOnlyUnpicklerrefuses a non-numpy global, for example a pickle that referencesos.system. That branch guards against a tampered normalizer file, and no test exercises it. - Unused processor:
MedModEHRSequenceProcessorisn't used anywhere in this PR and isn't mentioned in the description. Consider a short mention that it is for the models in part 2, or move it to that PR. - EHR dtype: the task docstring says
ehris float32.task(patient)returns the unnormalized float64 array, and the processor casts to float32 afterwards. A clarifying phrase would avoid confusion. - Task cache key: custom
resourcesfiles are keyed by path only, so editing a file in place won't invalidate the task cache. A note in the docs would help. - Docs length: the task API page is long. The "Paper vs code" section could move to a separate page, or be trimmed.
Reviewed commit f6d0cfc
|
@solarsys Hi Professor, could you take a look at #1637 when you have time? It's part 1 of 4 of our original PR #1609, and parts 3 and 4 build on it. I saw it's in #1668 for a licensing check. The bundled MedMod files are unchanged, and we include MedMod's Apache-2.0 license and a NOTICE listing everything we bundled or ported. We can download those files on first use instead, if you'd prefer. Please let us know if we should change anything. Thank you! |
Same code as sunlabuiuc#1637-sunlabuiuc#1640 after their reviews. sunlabuiuc#1638 is merged as 1aaeaea. Co-authored-by: rainiehu <57816421+Rainie-Hu@users.noreply.github.com>
Starting and stopping PyHealth's local Dask cluster took about 5 s per event-table build on 28 fake rows. The dataset tests now run the same Dask graph in the test process, and the custom item map test checks its cache key and row filter without a second build. The slowest step is now the module's one shared build (about 1.7 s); every test takes under 0.5 s. Co-authored-by: rainiehu <57816421+Rainie-Hu@users.noreply.github.com>
Faster dataset tests from sunlabuiuc#1637. Co-authored-by: rainiehu <57816421+Rainie-Hu@users.noreply.github.com>
Contributors: Yuqing Hu (GT username yhu672, yhu672@gatech.edu) and Hanh Trang Do (GT username hdo61, hdo61@gatech.edu), Georgia Tech CSE 6250
Contribution Type: Dataset + Task (part 1 of the Full Pipeline contribution #1609)
Part 1 of 4 of #1609. #1609 was too large for review, so it is split into: 1. dataset, task and processor (this PR); 2. models (#1638); 3. image tools, synthetic data, MedSigLIP embeddings, pretraining samples, examples and results (#1639, draft until 1 and 2 merge); 4. runner scripts and Colab notebook (#1640, draft until 3 merges). This PR needs nothing from the others.
Paper: Elsharief, S., et al. (2025). MedMod: Multimodal Benchmark for Medical Prediction Tasks with Electronic Health Records and Chest X-Ray Scans. CHIL 2025, PMLR 287. https://proceedings.mlr.press/v287/elsharief25a.html (code: https://github.com/nyuad-cai/MedMod)
What it adds:
MedModMIMIC4Datasetreads MIMIC-IV v1.0 and MIMIC-CXR-JPG 2.0.0 and applies MedMod's fixed train / validation / test split (MedModSplit,split_by_medmod).MedModInHospitalMortalitybuilds one sample per ICU stay: a 48 × 76 EHR time series (MedMod's 17 variables, discretized as in its released code), the image path and the mortality label. Our samples match MedMod's own extraction output for all 6,214 stays.MedModEHRProcessornormalizes the EHR inside PyHealth's processor framework.Why a separate dataset and task: PyHealth already has
EHRCXRMortalityMIMIC4(MedFuse's in-hospital mortality) andMedModDecompensationMIMIC4(#1510), which share the 34-column EHR ofehr_cxr_mimic4(17 values with ordinal Glasgow scores, plus masks, normalized on the training split). MedMod's models instead read MedMod's 76-column discretization: the 5 categorical variables one-hot encoded (47 columns), 12 continuous values and 17 masks, in MedMod's column order and with its stored normalizer. MedFuse's released EHR encoder was trained on exactly this input: its first LSTM layer is 1024 × 76, so it cannot load 34-column data. The fixed MedMod split also keeps the test patients out of the checkpoints' training data.Links to other components:
MedModMIMIC4DatasetandMedModEHRDatasetsubclassMIMIC4DatasetandMIMIC4EHRDatasetto reuse PyHealth's MIMIC-IV loading. They add the v1.0 config and MedMod's row filters. A customitemid_mapadds a digest of its file todataset_name, so each map gets its own cache. Nothing else imports or changes existing tasks or datasets.Files to review:
pyhealth/datasets/medmod_mimic4.py- dataset, MedMod splitpyhealth/datasets/medmod/- EHR extraction, discretizer, the download of MedMod's item map and split lists on first use, and MedMod's discretizer config and normalizer (files/, Apache-2.0)pyhealth/datasets/configs/mimic4_ehr_v1.0.yaml- MIMIC-IV v1.0 table configpyhealth/tasks/medmod_mortality_mimic4.py- taskpyhealth/processors/medmod_ehr_processor.py- EHR normalizertests/core/test_medmod_mimic4_dataset.py,test_medmod_mimic4_extraction.py,test_medmod_mimic4_processor.py, with helpers intests/core/medmod_test_utils.py;test-resources/medmod/itemid_to_variable_map.csv(10 rows of MedMod's item map, so the tests need no download)pyhealth/datasets/__init__.pyandpyhealth/tasks/__init__.py; docs pages for the dataset and task and their index entriesTesting: our 50 tests run on synthetic data only, with no network access. Together with upstream's MedMod decompensation tests, all 71 pass.
python tools/check_pr_rules.pypasses.Data: MIMIC-IV and MIMIC-CXR need PhysioNet credentialing. No MIMIC data or identifiers are in this PR.
🤖 Generated with Claude Code