|
| 1 | +.. _how_to_contribute: |
| 2 | + |
| 3 | +===================== |
| 4 | +How to Contribute |
| 5 | +===================== |
| 6 | + |
| 7 | +We welcome contributions to PyHealth! This guide will help you get started with contributing datasets, tasks, models, bug fixes, or other improvements to the project. |
| 8 | + |
| 9 | +Getting Started |
| 10 | +=============== |
| 11 | + |
| 12 | +Prerequisites |
| 13 | +------------- |
| 14 | + |
| 15 | +PyHealth uses GitHub for development, so you'll need a GitHub account to contribute. |
| 16 | + |
| 17 | +Setting Up Your Development Environment |
| 18 | +--------------------------------------- |
| 19 | + |
| 20 | +To start contributing to PyHealth: |
| 21 | + |
| 22 | +1. **Fork the PyHealth repository** on GitHub |
| 23 | +2. **Clone your forked repository** to your local machine: |
| 24 | + |
| 25 | + .. code-block:: bash |
| 26 | +
|
| 27 | + git clone https://github.com/your_username/PyHealth.git |
| 28 | + cd PyHealth |
| 29 | +
|
| 30 | +3. **Install dependencies**: |
| 31 | + |
| 32 | + .. code-block:: bash |
| 33 | +
|
| 34 | + pip install mne pandarallel rdkit transformers accelerate polars |
| 35 | +
|
| 36 | +4. **Implement your code** with proper test cases |
| 37 | +5. **Push changes** to your forked repository |
| 38 | +6. **Create a pull request** to the main PyHealth repository |
| 39 | + |
| 40 | + - Target the ``main`` branch |
| 41 | + - Enable edits by maintainers |
| 42 | + - Rebase with the remote ``sunlabuiuc`` main branch before creating the PR |
| 43 | + |
| 44 | +Implementation Requirements |
| 45 | +=========================== |
| 46 | + |
| 47 | +Code File Headers |
| 48 | +----------------- |
| 49 | + |
| 50 | +For new contributors, include the following information at the top of your code files: |
| 51 | + |
| 52 | +- Your name(s) |
| 53 | +- Your NetID(s) (if applicable for UIUC students) |
| 54 | +- Paper title (if applicable to a reproducibility contribution) |
| 55 | +- Paper link (if applicable) |
| 56 | +- Description of the task/dataset/model you're implementing |
| 57 | + |
| 58 | +Code Style and Documentation |
| 59 | +----------------------------- |
| 60 | + |
| 61 | +**General Guidelines:** |
| 62 | + |
| 63 | +- Use object-oriented programming with well-defined and typed functions |
| 64 | +- Follow snake_case naming for variables and functions (e.g., ``this_variable``) |
| 65 | +- Use PascalCase for class names (e.g., ``ThisClass``) |
| 66 | +- Follow PEP8 style with 88 character line length |
| 67 | +- Use Google style for docstrings |
| 68 | + |
| 69 | +**Function Documentation Requirements:** |
| 70 | + |
| 71 | +Each function must document: |
| 72 | + |
| 73 | +- **Input arguments**: Define variable types and descriptions |
| 74 | +- **Output arguments**: Define variable types and descriptions |
| 75 | +- **High-level description** of what the function does |
| 76 | +- **Example use case** or where it will be called |
| 77 | + |
| 78 | +**Example Well-Documented Function:** |
| 79 | + |
| 80 | +.. code-block:: python |
| 81 | +
|
| 82 | + def parse_basic_info(self, patients: Dict[str, Patient]) -> Dict[str, Patient]: |
| 83 | + """Helper functions which parses patients and admissions tables. |
| 84 | +
|
| 85 | + Will be called in `self.parse_tables()` |
| 86 | +
|
| 87 | + Docs: |
| 88 | + - patients: https://mimic.mit.edu/docs/iv/modules/hosp/patients/ |
| 89 | + - admissions: https://mimic.mit.edu/docs/iv/modules/hosp/admissions/ |
| 90 | +
|
| 91 | + Args: |
| 92 | + patients: a dict of `Patient` objects indexed by patient_id. |
| 93 | +
|
| 94 | + Returns: |
| 95 | + The updated patients dict. |
| 96 | + """ |
| 97 | +
|
| 98 | +Types of Contributions |
| 99 | +====================== |
| 100 | + |
| 101 | +Contributing a Dataset |
| 102 | +---------------------- |
| 103 | + |
| 104 | +All datasets must follow these guidelines: |
| 105 | + |
| 106 | +- **Inherit from BaseDataset**: All datasets must inherit from the appropriate BaseDataset class |
| 107 | +- **Follow established patterns**: |
| 108 | + |
| 109 | + - For EHR datasets: See the `MIMIC4 dataset example <https://github.com/sunlabuiuc/PyHealth/blob/main/pyhealth/datasets/mimic4.py>`_ |
| 110 | + - For image datasets: See the `CovidCXR dataset example <https://github.com/sunlabuiuc/PyHealth/blob/main/pyhealth/datasets/covidcxr.py>`_ where each folder represents a sample |
| 111 | + |
| 112 | +- **Include a test task**: Datasets should ideally have an associated task for testing purposes |
| 113 | + |
| 114 | +**Key Requirements:** |
| 115 | + |
| 116 | +- Define all required variables outlined in the BaseDataset documentation |
| 117 | +- Provide clear data loading and processing methods |
| 118 | +- Include proper error handling and validation |
| 119 | + |
| 120 | +Contributing a Task |
| 121 | +------------------- |
| 122 | + |
| 123 | +Tasks must follow the established task class structure: |
| 124 | + |
| 125 | +- **Inherit from base task class**: Follow the pattern defined in existing tasks |
| 126 | +- **Examples to reference**: |
| 127 | + |
| 128 | + - `Mortality prediction task <https://github.com/sunlabuiuc/PyHealth/blob/main/pyhealth/tasks/mortality_prediction.py>`_ |
| 129 | + - `X-ray classification task <https://github.com/sunlabuiuc/PyHealth/blob/main/pyhealth/tasks/chest_xray_classification.py>`_ |
| 130 | + |
| 131 | +- **Flexibility**: Tasks can include various implementation details but must have clear inputs/outputs |
| 132 | +- **Test cases**: Include example test cases with defined inputs and expected outputs |
| 133 | + |
| 134 | +Contributing a Model |
| 135 | +-------------------- |
| 136 | + |
| 137 | +Models must follow the model base class structure: |
| 138 | + |
| 139 | +- **Inherit from BaseModel**: All models must inherit from the appropriate base model class |
| 140 | +- **Reference implementation**: See the `RNN model example <https://github.com/sunlabuiuc/PyHealth/blob/main/pyhealth/models/rnn.py>`_ |
| 141 | +- **Test cases**: Include example test cases with dummy inputs and expected outputs |
| 142 | + |
| 143 | +**Key Requirements:** |
| 144 | + |
| 145 | +- Implement required abstract methods from the base class |
| 146 | +- Provide clear forward pass implementation |
| 147 | +- Include proper initialization and configuration methods |
| 148 | + |
| 149 | +Test Case Requirements |
| 150 | +====================== |
| 151 | + |
| 152 | +Every contribution must include two types of test cases: |
| 153 | + |
| 154 | +1. **Automated tests**: These will be run by our continuous integration system |
| 155 | +2. **Manual test cases**: You must define these yourself with: |
| 156 | + |
| 157 | + - Clear input specifications |
| 158 | + - Expected output formats |
| 159 | + - Example usage demonstrating functionality |
| 160 | + |
| 161 | +**Note**: You can use frontier LLMs to help generate basic test cases, which we consider valid as long as they are reasonable and comprehensive. |
| 162 | + |
| 163 | +Pull Request Guidelines |
| 164 | +======================= |
| 165 | + |
| 166 | +Formatting Your Pull Request |
| 167 | +---------------------------- |
| 168 | + |
| 169 | +Every pull request must include the following information in the comment: |
| 170 | + |
| 171 | +1. **Who you are** (include NetID if you're an Illinois student) |
| 172 | +2. **Type of contribution** (dataset, task, model, bug fix, etc.) |
| 173 | +3. **High-level description** of what you've implemented |
| 174 | +4. **File guide**: Quick rundown of which files to examine to test your implementation |
| 175 | + |
| 176 | +**Example PR Description:** |
| 177 | + |
| 178 | +.. code-block:: text |
| 179 | +
|
| 180 | + **Contributor:** Jane Doe (jdoe2@illinois.edu) |
| 181 | + |
| 182 | + **Contribution Type:** New Dataset |
| 183 | + |
| 184 | + **Description:** Added support for the XYZ Hospital dataset with patient |
| 185 | + admission records and diagnostic codes. Includes data preprocessing and |
| 186 | + sample task for mortality prediction. |
| 187 | + |
| 188 | + **Files to Review:** |
| 189 | + - `pyhealth/datasets/xyz_hospital.py` - Main dataset implementation |
| 190 | + - `pyhealth/tasks/xyz_mortality.py` - Example task |
| 191 | + - `tests/core/test_xyz_dataset.py` - Test cases |
| 192 | +
|
| 193 | +Review Process |
| 194 | +-------------- |
| 195 | + |
| 196 | +After submitting your pull request: |
| 197 | + |
| 198 | +1. Maintainers will review your code for style, functionality, and completeness |
| 199 | +2. Automated tests will be run to ensure compatibility |
| 200 | +3. You may be asked to make revisions based on feedback |
| 201 | +4. Once approved, your contribution will be merged into the main branch |
| 202 | + |
| 203 | +Getting Help |
| 204 | +============ |
| 205 | + |
| 206 | +If you need assistance: |
| 207 | + |
| 208 | +- Check existing issues and discussions on GitHub |
| 209 | +- Review similar implementations in the codebase |
| 210 | +- Reach out to maintainers through GitHub issues |
| 211 | +- Consider using LLMs to help with code formatting and documentation |
| 212 | + |
| 213 | +We appreciate your contributions to making PyHealth better for the healthcare AI community! |
0 commit comments