Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,28 @@ on:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.11']
steps:
- name: Checkout reposistory
uses: actions/checkout@v3
with:
submodules: recursive

- name: Set up Python
uses: actions/setup-python@v3
- name: Install Python environment needed for the relpo command
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
python-version: '3.13'

- name: Display Python version
run: python -c "import sys; print(sys.version)"
- name: Install pixi
run: 'curl -fsSL https://pixi.sh/install.sh | sh'

- name: Install dependent packages
run: 'make deps'
- name: Add pixi to path
run: 'echo "${HOME}/.pixi/bin" >> $GITHUB_PATH'

# we have to install the environment without --lock, as otherwise the
# pyproject.toml sha1 changes due to different whitespace in the build
# environment
- name: Create the enviornment, which updates the lock file
run: 'make init'

- name: Run tests
run: 'make test'
run: 'make testall'
11 changes: 11 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Copyright 2022 - 2025 The Regents of the University of Illinois

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62 changes: 45 additions & 17 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,56 @@

## Build
#
# directory with the unit tests
PY_TEST_DIR ?= tests
# test file glob pattern
PY_TEST_GLOB ?= test_metrics.py
TARG_DIR ?= target
DIST_DIR ?= $(TARG_DIR)/dist


## Targets
#
# install dependencies
.PHONY: deps
deps:
pip install -r requirements-nlp.txt
$(DIST_DIR):
mkdir -p $(DIST_DIR)

# run the unit test cases
.PHONY: test

# install the pixi program
.PHONY: installpixi
installpixi:
@echo "checking for pixi..."
@$(eval ex := $(shell which pixi > /dev/null 2>&1 ; echo $$?))
@if [ $(ex) -eq 1 ] ; then \
echo "pixi not found, install? (CNTL-C to stop)" ; \
read ; \
curl -fsSL https://pixi.sh/install.sh | sh ; \
fi
@echo "installed"

# install pixi and the Python environments
.PHONY: init
init: installpixi
@echo "installing environment..."
@pixi install

# run base module tests
.PHONY: test
test:
@echo "Running tests in $(PY_TEST_DIR)/$(PY_TEST_GLOB)"
python -m unittest discover \
-s $(PY_TEST_DIR) -p '$(PY_TEST_GLOB)' -v
@echo "running unit tests..."
@pixi run test

# run NLP specific tests
.PHONY: testnlp
testnlp:
@echo "running NLP unit tests..."
@pixi run testnlp

# run all tests
.PHONY: testall
testall: test testnlp

# build the wheel
.PHONY: wheel
wheel: $(DIST_DIR)
@PX_DIST_DIR=$(DIST_DIR) pixi run build-wheel

# clean derived objects
.PHONY: clean
.PHONY: clean
clean:
@echo "removing __pycache__"
@find . -type d -name __pycache__ -prune -exec rm -r {} \;
@echo "removing target: $(TARG_DIR)"
@rm -fr $(TARG_DIR)
6,499 changes: 6,499 additions & 0 deletions pixi.lock

Large diffs are not rendered by default.

8 changes: 0 additions & 8 deletions pyhealth/tasks/EEG_abnormal.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import os
import pickle
import pkg_resources
import mne
import pandas as pd
import numpy as np


def EEG_isAbnormal_fn(record):
Expand Down Expand Up @@ -155,7 +152,6 @@ def EEG_isAbnormal_fn(record):
return samples



if __name__ == "__main__":
from pyhealth.datasets import TUABDataset

Expand All @@ -167,7 +163,3 @@ def EEG_isAbnormal_fn(record):
EEG_abnormal_ds = dataset.set_task(EEG_isAbnormal_fn)
print(EEG_abnormal_ds.samples[0])
print(EEG_abnormal_ds.input_info)




8 changes: 1 addition & 7 deletions pyhealth/tasks/EEG_events.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import os
import pickle
import pkg_resources
import mne
import pandas as pd
import numpy as np


def EEG_events_fn(record):
"""Processes a single patient for the EEG events task on TUEV.

Expand Down Expand Up @@ -191,7 +190,6 @@ def readEDF(fileName):
return [signals, times, eventData, Rawdata]



if __name__ == "__main__":
from pyhealth.datasets import TUEVDataset

Expand All @@ -203,7 +201,3 @@ def readEDF(fileName):
EEG_events_ds = dataset.set_task(EEG_events_fn)
print(EEG_events_ds.samples[0])
print(EEG_events_ds.input_info)




3 changes: 0 additions & 3 deletions pyhealth/tasks/cardiology_detect.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import os
import pickle
import pkg_resources
from scipy.io import loadmat
import pandas as pd
import numpy as np


def cardiology_isAR_fn(record, epoch_sec=10, shift=5):
Expand Down
2 changes: 1 addition & 1 deletion pyhealth/tasks/medical_coding.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,4 @@ def main():
if len(samples[0]['icd_codes']) > 0:
print(f" - Sample ICD codes: {samples[0]['icd_codes'][:5] if len(samples[0]['icd_codes']) > 5 else samples[0]['icd_codes']}")
if __name__ == "__main__":
main()
main()
4 changes: 2 additions & 2 deletions pyhealth/tasks/sleep_staging.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import pickle
import pkg_resources
import mne
import pandas as pd
import numpy as np
Expand Down Expand Up @@ -259,7 +258,8 @@ def sleep_staging_shhs_fn(record, epoch_seconds=30):
# test whether the ogb and torch_scatter packages are ready
dependencies = ["elementpath"]
try:
pkg_resources.require(dependencies)
from importlib.metadata import version
version(dependencies)
Copy link

Copilot AI Jul 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable dependencies is a list but version() expects a string package name. This should be version(dependencies[0]) or loop through the dependencies list.

Suggested change
version(dependencies)
version(dependencies[0])

Copilot uses AI. Check for mistakes.
import xml.etree.ElementTree as ET
except Exception as e:
print(e)
Expand Down
2 changes: 0 additions & 2 deletions pyhealth/tasks/temple_university_EEG_tasks.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import os
import pickle
import pkg_resources
import mne
import pandas as pd
import numpy as np


Expand Down
154 changes: 154 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
#@meta {desc: "PyHealth build configuration", date: "2025-07-16"}


### Project
#
[project]
name = "pyhealth"
# must be kept in sync with git tags; is not updated by any automation tools
version = "1.2.0"
authors = [
{name = "John Wu", email = "johnwu3@illinois.edu"},
{name = "Chaoqi Yang"},
{name = "Zhenbang Wu"},
{name = "Patrick Jiang"},
{name = "Zhen Lin"},
{name = "Benjamin Danek"},
{name = "Junyi Gao"},
{name = "Paul Landes", email = "landes@mailc.net"},
{name = "Jimeng Sun"},
]
description = "A Python library for healthcare AI"
readme = "README.rst"
requires-python = ">=3.13,<3.14"
dependencies = [
"torch~=2.7.1",
"torchvision",
"transformers~=4.53.2",
"rdkit==2025.3.3",
"scikit-learn!=1.7.0",
"networkx==3.5",
"mne~=1.10.0",
"urllib3~=2.5.0",
"numpy~=1.26.4",
"tqdm",
"polars~=1.31.0",
"pandas~=2.3.1",
"pandarallel~=1.6.5",
"pydantic~=2.11.7",
]
license = "BSD-3-Clause"
license-files = ["LICENSE.md"]
keywords = [
"heathcare AI",
"healthcare",
"electronic health records",
"EHRs",
"machine learning",
"data mining",
"neural networks",
"deep learning",
]

[project.urls]
Homepage = "https://github.com/sunlabuiuc/PyHealth"
Documentation = "https://pyhealth.readthedocs.io/en/latest/about.html"
Repository = "https://github.com/sunlabuiuc/PyHealth.git"
Issues = "https://github.com/sunlabuiuc/PyHealth/issues"
Changelog = "https://github.com/sunlabuiuc/PyHealth/blob/master/CHANGELOG.md"

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"


### Hatchling
#
[tool.hatch.build.targets.wheel]
packages = ["pyhealth"]


### Pixi
#
# specifies properties for the whole workspace
[tool.pixi.project]
channels = ["conda-forge"]
platforms = ["osx-arm64", "linux-64", "linux-aarch64", "win-64"]
preview = ["pixi-build"]

# virtual environments (each under '.pixi/envs') for specific tasks
[tool.pixi.environments]
default = { features = ["pyverbase"], solve-group = "default" }
test = { features = ["pyverbase", "test"] }
base = { features = ["pyverbase", "base"] }
nlp = { features = ["pyverbase", "nlp"] }
build-pypi = { features = ["pyverbase", "build-pypi"], solve-group = "default" }
build-env = { features = ["pyverbase", "build-env"], solve-group = "default" }

# specify where to download the build backend that builds conda files
[tool.pixi.package.build]
backend = { name = "pixi-build-python", version = "0.1.*" }
channels = [
"https://prefix.dev/pixi-build-backends",
"https://prefix.dev/conda-forge",
]

# set the Python requirement for its environment
[tool.pixi.feature.pyverbase.dependencies]
python = "~=3.13"

# pixi directly supports depending on PyPI packages, the PyPA calls a
# distributed package a 'distribution'
[tool.pixi.feature.base.pypi-dependencies]
pyhealth = { path = ".", editable = true }

[tool.pixi.feature.test.pypi-dependencies]
pyhealth = { path = ".", editable = true }

[tool.pixi.feature.nlp.pypi-dependencies]
pyhealth = { path = ".", editable = true }

[tool.pixi.feature.nlp.dependencies]
pip = "*"

# dependencies for building the wheel
[tool.pixi.feature.build-pypi.dependencies]
hatchling = "==1.26.3"

[tool.pixi.feature.build-env.dependencies]
# pip for environment extract
pip = "*"

# dependencies needed during build/link time that are specific to the host
# machine
[tool.pixi.package.host-dependencies]
hatchling = "==1.26.3"
python = "~=3.13"


## Tasks
#
# task to use hatchling to build the wheel
[tool.pixi.feature.build-pypi.tasks]
build-wheel = "python -m hatchling build -t wheel --dir $PX_DIST_DIR"

# use Python built-in unittest library for tests
[tool.pixi.feature.test.tasks.test]
cmd = "python -m unittest discover -t tests -s tests/core -p 'test_*.py' -v"
[tool.pixi.feature.nlp.tasks.testnlp]
cmd = "python -m unittest discover -t tests -s tests/nlp -p 'test_*.py' -v"

# default environment tasks
[tool.pixi.tasks]
# env sanity check
defaultenv = "python -c 'import sys; print(sys.executable, sys.version)'"
# build the conda distribution file
build-conda = "pixi build --output-dir $PX_DIST_DIR"
# export environment.yml
export = "pixi workspace export conda-environment"

# command-line program invocation
[tool.pixi.tasks.invoke]
args = [{ "arg" = "args", "default" = "" }]
env = { CLASS = "zensols.relpo.cli", PYTHONPATH = "src" }
cmd = "\npython -c \"from $CLASS import main;print('_'*80);main('{{args}}'.split())\""
5 changes: 0 additions & 5 deletions requirements-nlp.txt

This file was deleted.

13 changes: 0 additions & 13 deletions requirements.txt

This file was deleted.

Loading