|
| 1 | +# Contributing to Bijectors.jl |
| 2 | + |
| 3 | +Thank you for your interest in contributing to Bijectors.jl! This guide will help you set up your development environment and understand how to run tests locally. |
| 4 | + |
| 5 | +## Development Setup |
| 6 | + |
| 7 | + 1. **Clone the repository**: |
| 8 | + |
| 9 | + ```bash |
| 10 | + git clone https://github.com/TuringLang/Bijectors.jl.git |
| 11 | + cd Bijectors.jl |
| 12 | + ``` |
| 13 | + |
| 14 | + 2. **Install dependencies**: |
| 15 | + |
| 16 | + ```bash |
| 17 | + julia --project=. -e "using Pkg; Pkg.instantiate()" |
| 18 | + ``` |
| 19 | + 3. **Verify the package loads**: |
| 20 | + |
| 21 | + ```bash |
| 22 | + julia --project=. -e "using Bijectors; println(\"Package loaded successfully\")" |
| 23 | + ``` |
| 24 | + |
| 25 | +## Running Tests |
| 26 | + |
| 27 | +### Reproducing CI Test Failures |
| 28 | + |
| 29 | +When CI tests fail, the output often shows incomplete reproduction instructions. Here are the correct commands to reproduce different CI scenarios locally: |
| 30 | + |
| 31 | +#### Interface Tests |
| 32 | + |
| 33 | +```bash |
| 34 | +julia --project=. -e "ENV[\"GROUP\"] = \"Interface\"; using Pkg; Pkg.test()" |
| 35 | +``` |
| 36 | + |
| 37 | +#### AD Tests with Specific Backend |
| 38 | + |
| 39 | +Replace `BackendName` with the failing AD backend from the CI output: |
| 40 | + |
| 41 | +```bash |
| 42 | +# ForwardDiff |
| 43 | +julia --project=. -e "ENV[\"GROUP\"] = \"AD\"; ENV[\"AD\"] = \"ForwardDiff\"; using Pkg; Pkg.test()" |
| 44 | +
|
| 45 | +# ReverseDiff |
| 46 | +julia --project=. -e "ENV[\"GROUP\"] = \"AD\"; ENV[\"AD\"] = \"ReverseDiff\"; using Pkg; Pkg.test()" |
| 47 | +
|
| 48 | +# Tracker |
| 49 | +julia --project=. -e "ENV[\"GROUP\"] = \"AD\"; ENV[\"AD\"] = \"Tracker\"; using Pkg; Pkg.test()" |
| 50 | +
|
| 51 | +# Enzyme (may fail on some systems - this is expected) |
| 52 | +julia --project=. -e "ENV[\"GROUP\"] = \"AD\"; ENV[\"AD\"] = \"Enzyme\"; using Pkg; Pkg.test()" |
| 53 | +
|
| 54 | +# Mooncake |
| 55 | +julia --project=. -e "ENV[\"GROUP\"] = \"AD\"; ENV[\"AD\"] = \"Mooncake\"; using Pkg; Pkg.test()" |
| 56 | +``` |
| 57 | + |
| 58 | +#### Full Test Suite |
| 59 | + |
| 60 | +```bash |
| 61 | +julia --project=. -e "using Pkg; Pkg.test()" |
| 62 | +``` |
| 63 | + |
| 64 | +### CI Test Matrix |
| 65 | + |
| 66 | +Our CI runs tests with the following configurations: |
| 67 | + |
| 68 | + - **Interface tests**: Core functionality tests (GROUP=Interface) |
| 69 | + - **AD tests**: Automatic differentiation tests with multiple backends (GROUP=AD, AD={ForwardDiff,ReverseDiff,Tracker,Enzyme,Mooncake}) |
| 70 | + |
| 71 | +### Important Notes |
| 72 | + |
| 73 | + 1. **Always use `--project=.`**: This ensures Julia uses the correct project environment with the right dependencies. |
| 74 | + |
| 75 | + 2. **Environment variables matter**: The `GROUP` and `AD` environment variables control which tests run, matching the CI configuration. |
| 76 | + 3. **Enzyme tests may fail**: Due to system compatibility issues, Enzyme tests may fail on some machines. This is expected and not a blocker for development. |
| 77 | + 4. **Test timing**: |
| 78 | + |
| 79 | + + Interface tests: ~7.5 minutes |
| 80 | + + AD tests (single backend): ~1.5 minutes |
| 81 | + + Full test suite: 20+ minutes |
| 82 | + |
| 83 | +## Code Formatting |
| 84 | + |
| 85 | +We use JuliaFormatter.jl for consistent code formatting: |
| 86 | + |
| 87 | +```bash |
| 88 | +# Install formatter (one-time setup) |
| 89 | +julia --project=. -e "using Pkg; Pkg.add(\"JuliaFormatter\")" |
| 90 | +
|
| 91 | +# Format code |
| 92 | +julia --project=. -e "using JuliaFormatter; format(\".\")" |
| 93 | +``` |
| 94 | + |
| 95 | +## Documentation |
| 96 | + |
| 97 | +To build documentation locally: |
| 98 | + |
| 99 | +```bash |
| 100 | +julia --project=docs -e "using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate(); include(\"docs/make.jl\")" |
| 101 | +``` |
| 102 | + |
| 103 | +## Validation Checklist |
| 104 | + |
| 105 | +Before submitting a PR, please ensure: |
| 106 | + |
| 107 | + - [ ] Package loads without errors: `julia --project=. -e "using Bijectors"` |
| 108 | + - [ ] Interface tests pass: `julia --project=. -e "ENV[\"GROUP\"] = \"Interface\"; using Pkg; Pkg.test()"` |
| 109 | + - [ ] Code is formatted: `julia --project=. -e "using JuliaFormatter; format(\".\")"` |
| 110 | + - [ ] Basic functionality works (see test scenarios below) |
| 111 | + |
| 112 | +### Basic Test Scenarios |
| 113 | + |
| 114 | +You can manually verify basic functionality: |
| 115 | + |
| 116 | +```julia |
| 117 | +using Bijectors, Distributions |
| 118 | +
|
| 119 | +# Test 1: Basic bijector for LogNormal |
| 120 | +d = LogNormal() |
| 121 | +b = bijector(d) |
| 122 | +x = 1.0 |
| 123 | +y = b(x) # Should return 0.0 |
| 124 | +
|
| 125 | +# Test 2: Inverse transformation |
| 126 | +x_reconstructed = inverse(b)(y) # Should return 1.0 |
| 127 | +
|
| 128 | +# Test 3: Log absolute determinant of Jacobian |
| 129 | +logjac = logabsdetjac(b, x) |
| 130 | +
|
| 131 | +# Test 4: Combined transformation |
| 132 | +z, logabsdet = with_logabsdet_jacobian(b, x) |
| 133 | +``` |
| 134 | + |
| 135 | +## Getting Help |
| 136 | + |
| 137 | +If you need help: |
| 138 | + |
| 139 | + - Join the #turing channel on [Julia Slack](https://julialang.org/slack/) |
| 140 | + - Ask questions on [Julia Discourse](https://discourse.julialang.org) |
| 141 | + - Open a GitHub issue for bugs or feature requests |
| 142 | + |
| 143 | +Thank you for contributing to Bijectors.jl! |
0 commit comments