Thank you for your interest in contributing to Performance RNN! This document provides guidelines and instructions for contributing to the project.
- Code of Conduct
- Getting Started
- Development Setup
- Project Structure
- Coding Standards
- Testing
- Pull Request Process
- Reporting Bugs
- Suggesting Enhancements
This project adheres to a code of conduct that all contributors are expected to follow. Please be respectful and professional in all interactions.
- Fork the repository on GitHub
- Clone your fork locally:
git clone https://github.com/YOUR_USERNAME/performance_rnn_torch.git cd performance_rnn_torch - Add the upstream repository:
git remote add upstream https://github.com/anatrini/performance_rnn_torch.git
- Create a branch for your changes:
git checkout -b feature/your-feature-name
- Python 3.10 or higher
- Git
- Miniconda or Anaconda (download here)
-
Fork and clone the repository:
git clone https://github.com/YOUR_USERNAME/performance_rnn_torch.git cd performance_rnn_torch -
Create the development environment:
# This installs all dependencies including dev tools conda env create -f environment-dev.yml # Activate the environment conda activate py_magenta # Install the package in development mode pip install -e ".[dev]"
Note: If you need GPU support for development:
# For NVIDIA GPU: conda env create -f environment-cuda.yml conda activate py_magenta pip install -e ".[dev]" # For Apple Silicon: conda env create -f environment-mps.yml conda activate py_magenta pip install -e ".[dev]"
-
(Optional) Install pre-commit hooks for automatic code formatting:
pre-commit install
# Activate your conda environment
conda activate py_magenta
# Run tests
pytest
# Check code formatting
black --check performance_rnn_torch/ scripts/
isort --check-only performance_rnn_torch/ scripts/
# Run linting
flake8 performance_rnn_torch/ scripts/
# Type checking
mypy performance_rnn_torch/performance_rnn_torch/
├── performance_rnn_torch/ # Main package
│ ├── core/ # Core functionality (model, sequence, data)
│ ├── training/ # Training utilities
│ ├── utils/ # Utility modules
│ └── config.py # Configuration
├── scripts/ # CLI scripts
├── tests/ # Unit tests
├── docs/ # Documentation
└── data/ # Data directory (not in git)
We follow PEP 8 with some modifications:
- Line length: 100 characters (enforced by Black)
- Import order: Managed by
isortwith Black profile - Docstrings: Google style docstrings for all public functions and classes
- Type hints: Use type hints for function signatures
We use the following tools (automatically run by pre-commit hooks):
- Black for code formatting
- isort for import sorting
- flake8 for linting
- mypy for type checking
Format your code before committing:
# Activate your conda environment
conda activate py_magenta
# Format code
black performance_rnn_torch/ scripts/
isort performance_rnn_torch/ scripts/
# Check linting
flake8 performance_rnn_torch/ scripts/
# Type check
mypy performance_rnn_torch/def train_model(model, dataset, epochs=100):
"""
Train a Performance RNN model.
Args:
model: The PerformanceRNN model to train
dataset: Dataset instance containing training data
epochs: Number of training epochs (default: 100)
Returns:
dict: Training history with loss values
Raises:
ValueError: If dataset is empty
Example:
>>> model = PerformanceRNN(**config.model)
>>> dataset = Dataset('data/processed/')
>>> history = train_model(model, dataset, epochs=50)
"""
passImports should be organized in the following order:
- Standard library imports
- Third-party imports
- Local application imports
# Standard library
import os
from pathlib import Path
from typing import Optional, List
# Third-party
import numpy as np
import torch
from tqdm import tqdm
# Local
from performance_rnn_torch import config
from performance_rnn_torch.core import PerformanceRNN
from performance_rnn_torch.utils import paths- Place tests in the
tests/directory - Name test files as
test_*.py - Name test functions as
test_* - Use descriptive test names
Example test:
# tests/test_model.py
import pytest
import torch
from performance_rnn_torch.core import PerformanceRNN
from performance_rnn_torch import config
def test_model_creation():
"""Test that model can be created with default config."""
model = PerformanceRNN(**config.model)
assert isinstance(model, PerformanceRNN)
assert model.hidden_dim == config.model['hidden_dim']
def test_model_forward_pass():
"""Test model forward pass with dummy data."""
model = PerformanceRNN(**config.model)
batch_size, seq_len = 4, 100
# Create dummy inputs
events = torch.randint(0, config.model['event_dim'], (seq_len, batch_size))
controls = torch.randn(seq_len, batch_size, config.model['control_dim'])
# Forward pass
output, losses = model(events, controls)
assert output.shape == (seq_len, batch_size, config.model['event_dim'])
assert 'loss' in losses# Activate your conda environment
conda activate py_magenta
# Run all tests
pytest
# Run with coverage
pytest --cov=performance_rnn_torch --cov-report=html
# Run specific test file
pytest tests/test_model.py
# Run specific test
pytest tests/test_model.py::test_model_creation
# Run tests in parallel
pytest -n auto- Aim for at least 80% code coverage
- Write tests for all public APIs
- Include edge cases and error conditions
- Update documentation if you've changed APIs
- Add tests for new functionality
- Update README if needed
- Activate your conda environment:
conda activate py_magenta
- Run the test suite:
pytest
- Check code quality:
black --check performance_rnn_torch/ scripts/ flake8 performance_rnn_torch/ scripts/ mypy performance_rnn_torch/
-
Push your changes to your fork:
git push origin feature/your-feature-name
-
Create a pull request on GitHub with:
- Clear title describing the change
- Detailed description of what changed and why
- Link to any related issues
- Screenshots/examples if applicable
-
Wait for review and address any feedback
## Description
Brief description of the changes
## Type of Change
- [ ] Bug fix
- [ ] New feature
- [ ] Breaking change
- [ ] Documentation update
## Testing
- [ ] Tests added/updated
- [ ] All tests pass
- [ ] Code coverage maintained
## Checklist
- [ ] Code follows project style guidelines
- [ ] Self-reviewed the code
- [ ] Commented complex code sections
- [ ] Updated documentation
- [ ] No new warnings generated- Check existing issues to avoid duplicates
- Update to the latest version to see if the bug persists
- Gather information about your environment
**Describe the Bug**
Clear description of what the bug is
**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Run '...'
3. See error
**Expected Behavior**
What you expected to happen
**Screenshots/Logs**
If applicable, add screenshots or error logs
**Environment:**
- OS: [e.g., Ubuntu 22.04]
- Python Version: [e.g., 3.10.5]
- PyTorch Version: [e.g., 2.0.1]
- Package Version: [e.g., 1.0.0]
**Additional Context**
Any other context about the problem**Is your feature request related to a problem?**
Clear description of the problem
**Describe the solution you'd like**
What you want to happen
**Describe alternatives you've considered**
Alternative solutions or features
**Additional context**
Any other context, screenshots, or examples- Discuss first: Open an issue to discuss major features
- Keep it focused: One feature per pull request
- Maintain compatibility: Don't break existing APIs without discussion
- Update documentation: Document new features thoroughly
- Code is readable and well-documented
- Follows project coding standards
- Tests are comprehensive
- No unnecessary dependencies added
- Performance impact is minimal
- Security implications considered
- GitHub Issues: For bug reports and feature requests
- Email: alessandro.anatrini@hfmt-hamburg.de
- Documentation: Check the README and inline docs
Contributors will be recognized in:
- Release notes
- README acknowledgments
- Git commit history
Thank you for contributing to Performance RNN!
Happy Coding! 🎵🎹