Skip to content

Commit 84b6061

Browse files
Copilotyebai
andcommitted
Add comprehensive testing instructions to docs
Co-authored-by: yebai <[email protected]>
1 parent bc34fd8 commit 84b6061

File tree

6 files changed

+182
-11
lines changed

6 files changed

+182
-11
lines changed

CONTRIBUTING.md

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
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!

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,37 @@ This package is used heavily in the probabilistic programming language Turing.jl
1212

1313
See the [documentation](https://turinglang.github.io/Bijectors.jl) for more.
1414

15+
## Development
16+
17+
### Running Tests Locally
18+
19+
To reproduce CI test failures locally, use the following commands:
20+
21+
```bash
22+
# Install dependencies
23+
julia --project=. -e "using Pkg; Pkg.instantiate()"
24+
25+
# Interface tests (reproduces "Interface tests" CI workflow)
26+
julia --project=. -e "ENV[\"GROUP\"] = \"Interface\"; using Pkg; Pkg.test()"
27+
28+
# AD tests with specific backend (reproduces "AD tests" CI workflow)
29+
# Replace "ReverseDiff" with the specific AD backend from the failing CI job
30+
julia --project=. -e "ENV[\"GROUP\"] = \"AD\"; ENV[\"AD\"] = \"ReverseDiff\"; using Pkg; Pkg.test()"
31+
32+
# Other AD backends available:
33+
# julia --project=. -e "ENV[\"GROUP\"] = \"AD\"; ENV[\"AD\"] = \"ForwardDiff\"; using Pkg; Pkg.test()"
34+
# julia --project=. -e "ENV[\"GROUP\"] = \"AD\"; ENV[\"AD\"] = \"Mooncake\"; using Pkg; Pkg.test()"
35+
# julia --project=. -e "ENV[\"GROUP\"] = \"AD\"; ENV[\"AD\"] = \"Tracker\"; using Pkg; Pkg.test()"
36+
# julia --project=. -e "ENV[\"GROUP\"] = \"AD\"; ENV[\"AD\"] = \"Enzyme\"; using Pkg; Pkg.test()"
37+
38+
# Run all tests
39+
julia --project=. -e "using Pkg; Pkg.test()"
40+
```
41+
42+
**Note**: When reproducing CI failures, ensure you use the correct environment variables (`GROUP` and `AD`) and always include `--project=.` in your Julia commands. These are required for the tests to run in the same configuration as CI.
43+
44+
For more detailed development instructions, see [CONTRIBUTING.md](CONTRIBUTING.md).
45+
1546
## Do you want to contribute?
1647

1748
If you feel you have some relevant skills and are interested in contributing, please get in touch!

src/bijectors/named_bijector.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ deps(b::NamedCoupling{<:Any,Deps}) where {Deps} = Deps
139139
return quote
140140
b = nc.f($([:(x.$d) for d in deps]...))
141141
x_target, logjac = with_logabsdet_jacobian(b, x.$target)
142-
return merge(x, ($target=x_target,)), logjac
142+
return merge(x, (($target)=x_target,)), logjac
143143
end
144144
end
145145

@@ -149,6 +149,6 @@ end
149149
return quote
150150
ib = inverse(ni.orig.f($([:(x.$d) for d in deps]...)))
151151
x_target, logjac = with_logabsdet_jacobian(ib, x.$target)
152-
return merge(x, ($target=x_target,)), logjac
152+
return merge(x, (($target)=x_target,)), logjac
153153
end
154154
end

test/ad/enzyme.jl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
@testset "forward" begin
77
# No batches
88
@testset for RT in (Const, Duplicated, DuplicatedNoNeed),
9-
Tx in (Const, Duplicated),
10-
Ty in (Const, Duplicated),
9+
Tx in (Const, Duplicated), Ty in (Const, Duplicated),
1110
Tz in (Const, Duplicated)
1211

1312
# Rule not picked up by Enzyme on Julia 1.11?!
@@ -21,8 +20,7 @@
2120

2221
# Batches
2322
@testset for RT in (Const, BatchDuplicated, BatchDuplicatedNoNeed),
24-
Tx in (Const, BatchDuplicated),
25-
Ty in (Const, BatchDuplicated),
23+
Tx in (Const, BatchDuplicated), Ty in (Const, BatchDuplicated),
2624
Tz in (Const, BatchDuplicated)
2725

2826
# Rule not picked up by Enzyme on Julia 1.11?!
@@ -37,8 +35,7 @@
3735
@testset "reverse" begin
3836
# No batches
3937
@testset for RT in (Const, Active),
40-
Tx in (Const, Active),
41-
Ty in (Const, Active),
38+
Tx in (Const, Active), Ty in (Const, Active),
4239
Tz in (Const, Active)
4340

4441
test_reverse(Bijectors.find_alpha, RT, (x, Tx), (y, Ty), (z, Tz))

test/bijectors/product_bijector.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ has_square_jacobian(b, x) = Bijectors.output_size(b, x) == size(x)
3939
y,
4040
logjac,
4141
changes_of_variables_test=has_square_jacobian(b, xs[1]),
42-
test_not_identity=!isidentity,
42+
test_not_identity=(!isidentity),
4343
)
4444
end
4545

@@ -63,7 +63,7 @@ has_square_jacobian(b, x) = Bijectors.output_size(b, x) == size(x)
6363
y,
6464
logjac,
6565
changes_of_variables_test=has_square_jacobian(b, xs[1]),
66-
test_not_identity=!isidentity,
66+
test_not_identity=(!isidentity),
6767
)
6868
end
6969
end

test/bijectors/rational_quadratic_spline.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ using LogExpFunctions
4646

4747
# Outside of domain
4848
x = 5.0
49-
test_bijector(b, -x; y=-x, logjac=0)
49+
test_bijector(b, -x; y=(-x), logjac=0)
5050
test_bijector(b, x; y=x, logjac=0)
5151

5252
# multivariate

0 commit comments

Comments
 (0)