Development¶
Resources for contributors and developers working with Diffid.
Getting Started with Development¶
-
Contributing
Guidelines for contributing code, documentation, and bug reports.
-
Architecture
Understanding Diffid's Rust core and PyO3 bindings design.
Quick Setup¶
# Clone the repository
git clone https://github.com/bradyplanden/diffid.git
cd diffid
# Create Python environment
uv sync
# Build Rust extension with Python bindings
uv run maturin develop
# Run tests
uv run pytest -v # Python tests
cargo test # Rust tests
Development Workflow¶
1. Make Changes¶
Edit Rust source in rust/src/ or Python bindings in python/.
2. Rebuild¶
3. Test¶
4. Update Stubs¶
If you modified Python bindings:
5. Format and Lint¶
Project Structure¶
diffid/
├── rust/ # Rust core implementation
│ ├── src/
│ │ ├── builders/ # Problem builders
│ │ ├── optimisers/ # Optimisation algorithms
│ │ ├── sampler/ # MCMC and nested sampling
│ │ ├── cost/ # Cost metrics
│ │ └── problem/ # Problem types
│ ├── Cargo.toml
│ └── tests/ # Rust tests
├── python/ # Python bindings
│ ├── src/diffid/
│ │ ├── __init__.py
│ │ └── _diffid.pyi # Generated type stubs
│ └── diffid/ # PyO3 bindings source
├── examples/ # Example scripts
├── tests/ # Python tests
├── docs/ # Documentation (this site)
├── pyproject.toml # Python package config
└── README.md
Key Technologies¶
- Rust: Core algorithms, high performance
- PyO3: Python bindings with minimal overhead
- Maturin: Build system for Rust Python extensions
- uv: Fast Python package management
- MkDocs Material: Documentation site
Testing Strategy¶
Unit Tests¶
Rust unit tests alongside code:
Integration Tests¶
Python integration tests in tests/:
def test_optimisation():
builder = diffid.ScalarBuilder().with_objective(func)
# ...
assert result.success
Continuous Integration¶
GitHub Actions runs: - Rust tests and clippy - Python tests on multiple versions - Type checking with mypy - Linting with ruff - Documentation builds
Documentation¶
Rust Docs¶
Python Docs¶
Edit markdown files in docs/:
Docstrings¶
Use NumPy-style docstrings:
def example(x, y):
"""
Brief description.
Parameters
----------
x : float
Description of x.
y : float
Description of y.
Returns
-------
float
Description of return value.
"""
Code Style¶
Rust¶
- Follow Rust API Guidelines
- Use
cargo fmt(automatic formatting) - Pass
cargo clippy(linting)
Python¶
- Follow PEP 8
- Use type hints
- Format with
ruff format
Performance Profiling¶
Rust¶
Python¶
See Also¶
- Architecture - System design
- Contributing - Contribution guidelines
- API Reference - API documentation