Skill Tracer
Skills › Scientific Agent Skills › pyhealth › installation.md

installation.md

90 lines · skills/pyhealth/references/installation.md at 5f2bc03

Open on GitHub

Most marks come from matching words in the file, so treat them as pointers.

1# Installation and environment
2
3Reviewed for the released **PyHealth 2.0.2** wheel on 2026-09-30. Its metadata
4requires Python `>=3.12,<3.14` and `torch~=2.7.1`, which excludes Torch 2.8 and later.
5The tested macOS CPU environment resolved Torch 2.7.1 and torchvision 0.22.1.
6Do not independently upgrade to the newest Torch or copy CUDA 12.1 commands from
7older PyHealth examples. The [release metadata](https://pypi.org/project/pyhealth/2.0.2/)
8is authoritative for this pin; `/en/latest/` documentation may describe newer source.
9

Installation and environment

Reviewed for the released PyHealth 2.0.2 wheel on 2026-09-30. Its metadata requires Python >=3.12,<3.14 and torch~=2.7.1, which excludes Torch 2.8 and later. The tested macOS CPU environment resolved Torch 2.7.1 and torchvision 0.22.1. Do not independently upgrade to the newest Torch or copy CUDA 12.1 commands from older PyHealth examples. The release metadata is authoritative for this pin; /en/latest/ documentation may describe newer source.

Raw lines 1 to 9
10## Project setup
12```bash
13uv init --python 3.12 my-pyhealth-project
14cd my-pyhealth-project
15uv add 'pyhealth==2.0.2'
16uv run python -c 'import torch; import importlib.metadata as m; print(m.version("pyhealth"), torch.__version__)'
17```
19Keep the generated lockfile. To run independently of the surrounding project's
20Python requirement or dependencies:
22```bash
23uv run --no-project --isolated --python 3.12 --with pyhealth==2.0.2 python train.py
24```
26PyHealth 1.x has different datasets, task functions, schemas and model arguments.
27Treat an existing 1.x environment as a separate migration; these examples target
282.0.2 and do not claim legacy compatibility.

Project setup

uv init --python 3.12 my-pyhealth-project
cd my-pyhealth-project
uv add 'pyhealth==2.0.2'
uv run python -c 'import torch; import importlib.metadata as m; print(m.version("pyhealth"), torch.__version__)'

Keep the generated lockfile. To run independently of the surrounding project's Python requirement or dependencies:

uv run --no-project --isolated --python 3.12 --with pyhealth==2.0.2 python train.py

PyHealth 1.x has different datasets, task functions, schemas and model arguments. Treat an existing 1.x environment as a separate migration; these examples target 2.0.2 and do not claim legacy compatibility.

Raw lines 10 to 29
Runs code python train.py :23
30## CPU, CUDA and MPS
32Start with `Trainer(..., device="cpu")`. GPU selection at runtime does not determine
33which wheel the installer downloads. For Linux CUDA/ROCm, choose a supported
34**Torch 2.7.1 / torchvision 0.22.1** pair from the
35[official previous-version installer](https://pytorch.org/get-started/previous-versions/),
36and configure the package index appropriately for that environment. CUDA installation
37was not tested in this review.
39On Apple Silicon, check `torch.backends.mps.is_available()` before explicitly passing
40`device="mps"`; the trainer's automatic device choice is CUDA-or-CPU. MPS operation
41coverage is model-dependent and was not tested here. Optional graph models may need
42`pyhealth[graph]==2.0.2`; pretrained text/image models can require separate downloads.

CPU, CUDA and MPS

Start with Trainer(..., device="cpu"). GPU selection at runtime does not determine which wheel the installer downloads. For Linux CUDA/ROCm, choose a supported Torch 2.7.1 / torchvision 0.22.1 pair from the official previous-version installer, and configure the package index appropriately for that environment. CUDA installation was not tested in this review.

On Apple Silicon, check torch.backends.mps.is_available() before explicitly passing device="mps"; the trainer's automatic device choice is CUDA-or-CPU. MPS operation coverage is model-dependent and was not tested here. Optional graph models may need pyhealth[graph]==2.0.2; pretrained text/image models can require separate downloads.

Raw lines 30 to 43
44## Data access and layout
46The public PyHealth `Synthetic_MIMIC-III` bucket is an unauthenticated collection of
47CSV files, not a clinical production dataset or JSON API:
48`https://storage.googleapis.com/pyhealth/Synthetic_MIMIC-III/`.
49The 2.0.2 loader tries configured `.csv.gz` files and then `.csv` alternatives.
51Real MIMIC and eICU require the relevant PhysioNet access conditions (credentialing,
52training and the data use agreement). Confirm access and release-specific conditions
53on the [dataset landing page](https://physionet.org/content/mimiciv/); download through
54an authorized channel and pass a local path. Do not embed access credentials in code.
56For MIMIC-IV the root must contain `hosp/` **and** `icu/` because the default config
57loads `hosp/patients.csv.gz`, `hosp/admissions.csv.gz`, `icu/icustays.csv.gz` plus
58requested clinical tables. PyHealth's bundled MIMIC-IV config is labeled 2.2;
59compatibility with all newer PhysioNet releases has not been established here.
61```python
62from pyhealth.datasets import MIMIC4EHRDataset
63base = MIMIC4EHRDataset(
64 root="./data/mimic-iv", # contains hosp/ and icu/
65 tables=["diagnoses_icd", "procedures_icd", "prescriptions"],
66 cache_dir="./cache/mimic4", num_workers=1,
68```
70This constructor was checked against released source; restricted data parsing was
71not executed. MIMIC-III uses lowercase selectors with uppercase source filenames.
72OMOP uses its own bundled config: inspect it before assuming a particular CDM export
73naming convention.

Data access and layout

The public PyHealth Synthetic_MIMIC-III bucket is an unauthenticated collection of CSV files, not a clinical production dataset or JSON API: https://storage.googleapis.com/pyhealth/Synthetic_MIMIC-III/. The 2.0.2 loader tries configured .csv.gz files and then .csv alternatives.

Real MIMIC and eICU require the relevant PhysioNet access conditions (credentialing, training and the data use agreement). Confirm access and release-specific conditions on the dataset landing page; download through an authorized channel and pass a local path. Do not embed access credentials in code.

For MIMIC-IV the root must contain hosp/ and icu/ because the default config loads hosp/patients.csv.gz, hosp/admissions.csv.gz, icu/icustays.csv.gz plus requested clinical tables. PyHealth's bundled MIMIC-IV config is labeled 2.2; compatibility with all newer PhysioNet releases has not been established here.

from pyhealth.datasets import MIMIC4EHRDataset
base = MIMIC4EHRDataset(
    root="./data/mimic-iv",  # contains hosp/ and icu/
    tables=["diagnoses_icd", "procedures_icd", "prescriptions"],
    cache_dir="./cache/mimic4", num_workers=1,
)

This constructor was checked against released source; restricted data parsing was not executed. MIMIC-III uses lowercase selectors with uppercase source filenames. OMOP uses its own bundled config: inspect it before assuming a particular CDM export naming convention.

Raw lines 44 to 74
75## Caching and small runs
77`BaseDataset(cache_dir=None)` uses a persistent platform-specific user cache.
78An explicit cache root gains a dataset UUID subdirectory; task/schema/processor
79caches live below it. It is incorrect that omitting `cache_dir` always reparses.
80The dataset cache key includes root, tables, dataset name and `dev`, but not the raw
81file contents or full config contents. A task source edit need not invalidate the
82task cache either. Choose a new cache root after changing those inputs and record
83raw-data checksums/release and task version with each run.
85`dev=True` limits BaseDataset processing to 1000 patients; it is not a guarantee
86that only 1000 patients' CSV bytes are downloaded or scanned. Not every wrapper
87exposes it: `SleepEDFDataset`, for example, has no `dev` or `cache_dir` parameter.
88Use a `main()` guard for executable examples because dataset processing can spawn
89workers on macOS/Windows. `num_workers=1` is a useful initial setting, not a guarantee
90that every upstream library avoids subprocesses.

Caching and small runs

BaseDataset(cache_dir=None) uses a persistent platform-specific user cache. An explicit cache root gains a dataset UUID subdirectory; task/schema/processor caches live below it. It is incorrect that omitting cache_dir always reparses. The dataset cache key includes root, tables, dataset name and dev, but not the raw file contents or full config contents. A task source edit need not invalidate the task cache either. Choose a new cache root after changing those inputs and record raw-data checksums/release and task version with each run.

dev=True limits BaseDataset processing to 1000 patients; it is not a guarantee that only 1000 patients' CSV bytes are downloaded or scanned. Not every wrapper exposes it: SleepEDFDataset, for example, has no dev or cache_dir parameter. Use a main() guard for executable examples because dataset processing can spawn workers on macOS/Windows. num_workers=1 is a useful initial setting, not a guarantee that every upstream library avoids subprocesses.

Raw lines 75 to 90
Starts an agent spawn :88