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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Binary file added .DS_Store
Binary file not shown.
99 changes: 99 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: CI

on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8, 3.9]
cuda-version: ['11.8.0']

steps:
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install CUDA
uses: Jimver/cuda-toolkit@v0.2.11
with:
cuda: ${{ matrix.cuda-version }}
method: 'network'
sub-packages: '["nvcc", "cudart", "cublas", "curand", "cusolver", "cusparse"]'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest pytest-cov
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
pip install -r requirements.txt
pip install -e .

- name: Run tests
run: |
pytest tests/ --cov=XuanjiNovo --cov-report=xml

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
flags: unittests
fail_ci_if_error: true

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 black isort mypy

- name: Run linters
run: |
flake8 XuanjiNovo tests
black --check XuanjiNovo tests
isort --check-only XuanjiNovo tests
mypy XuanjiNovo

build-extensions:
runs-on: ubuntu-latest
needs: [test, lint]
steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Install CUDA
uses: Jimver/cuda-toolkit@v0.2.11
with:
cuda: '11.8.0'
method: 'network'
sub-packages: '["nvcc", "cudart"]'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ninja
pip install -r requirements.txt

- name: Build C++ extensions
run: |
python setup.py build_ext --inplace
54 changes: 54 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- id: debug-statements

- repo: https://github.com/psf/black
rev: 24.1.1
hooks:
- id: black
language_version: python3
args: [--line-length=100]

- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
args: ["--profile", "black", "--line-length", "100"]

- repo: https://github.com/pycqa/flake8
rev: 7.0.0
hooks:
- id: flake8
additional_dependencies: [
'flake8-docstrings',
'flake8-bugbear',
'flake8-comprehensions',
]
args: [
"--max-line-length=100",
"--extend-ignore=E203", # For black compatibility
]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
hooks:
- id: mypy
additional_dependencies: [
'types-all',
'torch',
'numpy',
]
args: [
"--ignore-missing-imports",
"--disallow-untyped-defs",
"--check-untyped-defs",
"--warn-redundant-casts",
"--warn-unused-ignores",
"--show-error-codes",
]
178 changes: 178 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
# Development Guide for MassNet-DDA

This document outlines the development practices, testing procedures, and continuous integration setup for the MassNet-DDA project.

## Testing Framework

### Prerequisites

Before running tests, ensure you have the required dependencies:

```bash
pip install pytest pytest-cov flake8 black isort mypy
```

### Running Tests

We use pytest for our test suite. Here are common test commands:

```bash
# Run all tests with coverage report
pytest tests/ --cov=XuanjiNovo

# Run specific test file
pytest tests/test_model.py

# Run tests matching specific pattern
pytest -k "test_model"

# Run tests with detailed output
pytest -v tests/

# Run tests and generate HTML coverage report
pytest tests/ --cov=XuanjiNovo --cov-report=html
```

### Test Structure

- `tests/test_model.py`: Core model component tests
- `tests/conftest.py`: Shared pytest fixtures and configurations

## Code Quality Tools

We maintain code quality through several automated tools:

### Flake8 (Style Guide Enforcement)
```bash
# Check style
flake8 XuanjiNovo tests

# Common configuration in setup.cfg:
# [flake8]
# max-line-length = 100
# exclude = .git,__pycache__,build,dist
```

### Black (Code Formatting)
```bash
# Check formatting
black --check XuanjiNovo tests

# Apply formatting
black XuanjiNovo tests
```

### isort (Import Sorting)
```bash
# Check import sorting
isort --check-only XuanjiNovo tests

# Apply import sorting
isort XuanjiNovo tests
```

### mypy (Static Type Checking)
```bash
# Run type checking
mypy XuanjiNovo
```

## Continuous Integration

We use GitHub Actions for automated testing and quality assurance. The CI pipeline runs on:
- Push to main/master branches
- Pull request to main/master branches

### CI Pipeline Components

1. **Test Job**
- Runs on Ubuntu with Python 3.8 and 3.9
- Tests with CUDA 11.8.0
- Generates coverage reports
- Uploads coverage to Codecov

2. **Lint Job**
- Runs all code quality tools
- Ensures consistent code style
- Checks type annotations

3. **Build Extensions Job**
- Builds C++ extensions
- Verifies CUDA compatibility
- Tests compiled components

### CI Configuration

The complete CI configuration is in `.github/workflows/ci.yml`. Key features:
- Matrix testing across Python versions
- CUDA toolkit installation
- Dependency caching
- Automated coverage reporting

## Development Workflow

1. **Setting Up Development Environment**
```bash
# Clone repository
git clone https://github.com/your-username/MassNet-DDA.git
cd MassNet-DDA

# Create virtual environment
python -m venv venv
source venv/bin/activate # or `venv\Scripts\activate` on Windows

# Install dependencies
pip install -r requirements.txt
pip install -r requirements-dev.txt # Development dependencies
```

2. **Making Changes**
- Write tests for new features
- Ensure all tests pass locally
- Run code quality checks
- Update documentation as needed

3. **Pre-commit Checks**
```bash
# Run all checks
pytest tests/
flake8 XuanjiNovo tests
black --check XuanjiNovo tests
isort --check-only XuanjiNovo tests
mypy XuanjiNovo
```

## Test Coverage

We aim to maintain high test coverage for critical components:
- Model architecture and initialization
- Training and inference pipelines
- Data processing utilities
- CUDA-specific functionality

Current test coverage can be viewed:
- Locally: Generate HTML report with `pytest --cov=XuanjiNovo --cov-report=html`
- Online: Visit our Codecov dashboard

## Adding New Tests

When adding new features or fixing bugs:
1. Create corresponding test file in `tests/`
2. Use appropriate fixtures from `conftest.py`
3. Include both positive and negative test cases
4. Test edge cases and error conditions
5. Add CUDA-specific tests where relevant

## Debugging Tests

For failing tests:
```bash
# Run with detailed output
pytest -vv tests/

# Run specific failing test with debug output
pytest tests/test_model.py::test_name -vv

# Drop into debugger on failure
pytest --pdb tests/
```
19 changes: 19 additions & 0 deletions Dockerfile_cuda11
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM pytorch/pytorch:2.1.0-cuda11.8-cudnn8-runtime

ENV CUDA_HOME=/usr/local/cuda
ENV PATH=$CUDA_HOME/bin:$PATH
ENV LD_LIBRARY_PATH=$CUDA_HOME/lib64:$LD_LIBRARY_PATH
ENV GIT_PYTHON_REFRESH=quiet

WORKDIR /app

COPY . /app/

RUN apt update && apt install -y gcc g++ ninja-build

RUN cd /app/ctcdecode-master && pip install .

RUN pip install -r /app/requirements-docker-cuda11.txt
RUN cd /app/imputer-pytorch && pip install -e .

ENTRYPOINT ["python", "-m", "XuanjiNovo.XuanjiNovo"]
19 changes: 19 additions & 0 deletions Dockerfile_cuda12
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM pytorch/pytorch:2.1.0-cuda12.1-cudnn8-runtime

ENV CUDA_HOME=/usr/local/cuda
ENV PATH=$CUDA_HOME/bin:$PATH
ENV LD_LIBRARY_PATH=$CUDA_HOME/lib64:$LD_LIBRARY_PATH
ENV GIT_PYTHON_REFRESH=quiet

WORKDIR /app

COPY . /app/

RUN apt update && apt install -y gcc g++ ninja-build

RUN cd /app/ctcdecode-master && pip install .

RUN pip install -r /app/requirements-docker-cuda12.txt
RUN cd /app/imputer-pytorch && pip install -e .

ENTRYPOINT ["python", "-m", "XuanjiNovo.XuanjiNovo"]
Loading
Loading