Skip to content

Commit d5969b7

Browse files
Copilotyebai
andcommitted
Add comprehensive GitHub Copilot instructions for AbstractMCMC.jl
Co-authored-by: yebai <[email protected]>
1 parent b60eb45 commit d5969b7

File tree

1 file changed

+169
-0
lines changed

1 file changed

+169
-0
lines changed

.github/copilot-instructions.md

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
# AbstractMCMC.jl - GitHub Copilot Instructions
2+
3+
AbstractMCMC.jl provides abstract types and interfaces for Markov chain Monte Carlo methods in Julia. It is a foundational package in the TuringLang ecosystem that defines the common interface used by MCMC samplers.
4+
5+
Always reference these instructions first and fallback to search or bash commands only when you encounter unexpected information that does not match the info here.
6+
7+
## Working Effectively
8+
9+
### Bootstrap and Setup
10+
- Ensure Julia is available: `julia --version` (requires Julia 1.6 or later)
11+
- Navigate to project root: `cd /path/to/AbstractMCMC.jl`
12+
- Install package dependencies: `julia --project=. -e "using Pkg; Pkg.instantiate()"`
13+
- Takes 30-60 seconds on first run. NEVER CANCEL. Set timeout to 120+ seconds.
14+
- Downloads and precompiles ~50+ Julia packages including BangBang, LogDensityProblems, Transducers
15+
16+
### Run Tests
17+
- `julia --project=. -e "using Pkg; Pkg.test()"`
18+
- Takes 2 minutes 50 seconds. NEVER CANCEL. Set timeout to 5+ minutes.
19+
- Runs 234 tests covering sampling, steppers, transducers, and LogDensityProblems integration
20+
- All tests must pass - any failures indicate broken functionality
21+
22+
### Code Formatting
23+
- Check/fix code formatting: `julia --project=. -e "using Pkg; Pkg.add(\"JuliaFormatter\"); using JuliaFormatter; format(\".\")"`
24+
- Takes less than 1 second after JuliaFormatter is installed
25+
- Uses Blue style formatting (.JuliaFormatter.toml configures this)
26+
- ALWAYS run before committing - CI will fail without proper formatting
27+
28+
### Build Documentation
29+
- Navigate to docs: `cd docs`
30+
- Install doc dependencies: `julia --project=. -e "using Pkg; Pkg.instantiate(); Pkg.develop(PackageSpec(path=joinpath(\"..\")))"`
31+
- Takes 45-60 seconds. Set timeout to 120+ seconds.
32+
- Build docs: `julia --project=. make.jl`
33+
- Takes 10-15 seconds. Set timeout to 30+ seconds.
34+
- Documentation builds to docs/build/ folder
35+
36+
## Validation
37+
38+
### Basic Functionality Test
39+
After making changes, ALWAYS validate core functionality works by running this test:
40+
```bash
41+
cd /path/to/AbstractMCMC.jl
42+
julia --project=. -e "
43+
using AbstractMCMC
44+
using LogDensityProblems
45+
using Random
46+
47+
include(\"test/utils.jl\")
48+
Random.seed!(1234)
49+
50+
# Test basic MCMC sampling
51+
model = MyModel()
52+
sampler = MySampler()
53+
chain = sample(model, sampler, 10; progress=false)
54+
println(\"✓ Sample successful! Chain length: \", length(chain))
55+
println(\"✓ First sample: a=\", chain[1].a, \", b=\", chain[1].b)
56+
println(\"✓ Last sample: a=\", chain[end].a, \", b=\", chain[end].b)
57+
println(\"✓ Validation test completed successfully\")
58+
"
59+
```
60+
Expected output should show successful sampling with numerical values.
61+
62+
### CI Validation Requirements
63+
ALWAYS run these before submitting changes:
64+
1. `julia --project=. -e "using Pkg; Pkg.test()"` - All tests must pass
65+
2. `julia --project=. -e "using JuliaFormatter; format(\".\")"` - Code must be formatted
66+
3. Build documentation successfully in docs/ directory
67+
68+
## Repository Structure
69+
70+
### Source Code (`src/`)
71+
- `AbstractMCMC.jl` - Main module file defining abstract types and exports
72+
- `interface.jl` - Core interface definitions for step, sample functions
73+
- `sample.jl` - Main sampling implementation with serial/parallel support
74+
- `stepper.jl` - Iterator interface for MCMC chains
75+
- `transducer.jl` - Transducers.jl integration for MCMC sampling
76+
- `logging.jl` - Progress logging and output formatting
77+
- `logdensityproblems.jl` - LogDensityProblems.jl integration
78+
- `samplingstats.jl` - Statistics collection during sampling
79+
80+
### Tests (`test/`)
81+
- `runtests.jl` - Main test runner that includes all test files
82+
- `utils.jl` - Test utilities with MyModel, MySampler example implementations
83+
- `sample.jl` - Tests for sampling functions (serial, parallel, progress logging)
84+
- `stepper.jl` - Tests for iterator interface
85+
- `transducer.jl` - Tests for Transducers.jl integration
86+
- `logdensityproblems.jl` - Tests for LogDensityProblems.jl integration
87+
88+
### Documentation (`docs/`)
89+
- `src/index.md` - Main documentation homepage
90+
- `src/api.md` - User-facing API documentation
91+
- `src/design.md` - Developer guide for implementing interfaces
92+
- `make.jl` - Documentation build script
93+
94+
## Key Concepts
95+
96+
### Abstract Types
97+
- `AbstractModel` - Represents a probabilistic model for inference
98+
- `AbstractSampler` - Base type for MCMC sampling algorithms
99+
- `AbstractChains` - Stores parameter samples from MCMC process
100+
- `AbstractMCMCEnsemble` - Algorithms for parallel sampling (MCMCThreads, MCMCDistributed, MCMCSerial)
101+
102+
### Core Interface Functions
103+
Every MCMC sampler implementation must define:
104+
- `AbstractMCMC.step(rng, model, sampler, state; kwargs...)` - Single sampling step
105+
- Optionally `AbstractMCMC.step_warmup(...)` - Warm-up sampling step
106+
107+
### Common Parameters
108+
- `progress` - Enable/disable progress logging (default: true)
109+
- `chain_type` - Output type for collected samples (default: Any)
110+
- `num_warmup` - Number of warm-up steps before regular sampling
111+
- `discard_initial` - Number of initial samples to discard
112+
- `thinning` - Factor for thinning samples (keep every nth sample)
113+
114+
## CI Workflows
115+
116+
The repository has several GitHub Actions workflows:
117+
- **CI.yml** - Main testing across Julia versions and architectures (1.6+, x64/x86, Ubuntu/Windows/macOS)
118+
- **Format.yml** - Checks code formatting with JuliaFormatter
119+
- **Docs.yml** - Builds and deploys documentation
120+
- **IntegrationTest.yml** - Tests compatibility with downstream packages (AdvancedHMC.jl, Turing.jl, etc.)
121+
122+
## Common Development Tasks
123+
124+
### Adding New Functionality
125+
1. Implement changes in appropriate `src/` files
126+
2. Add corresponding tests in `test/` files
127+
3. Update documentation in `docs/src/` if needed
128+
4. Run validation: tests, formatting, documentation build
129+
5. Ensure integration tests pass with downstream packages
130+
131+
### Debugging Issues
132+
- Check test output for specific failure details
133+
- Use the validation test above to isolate basic functionality
134+
- Examine `test/utils.jl` for example implementations of interfaces
135+
- Review existing implementations in `src/` files for patterns
136+
137+
### Performance Considerations
138+
- This is an interface package - performance is mainly in downstream implementations
139+
- Focus on API design and interface completeness rather than algorithmic performance
140+
- Ensure abstractions don't introduce unnecessary overhead
141+
142+
## Package Dependencies
143+
144+
Key runtime dependencies:
145+
- **BangBang.jl** - Mutating/non-mutating function interface
146+
- **LogDensityProblems.jl** - Interface for log density functions
147+
- **Transducers.jl** - Composable algorithms for processing data
148+
- **ProgressLogging.jl/TerminalLoggers.jl** - Progress reporting
149+
- **StatsBase.jl** - Statistical computing foundation
150+
151+
## Troubleshooting
152+
153+
### Common Issues
154+
- **Package instantiation fails**: Check internet connection for package downloads
155+
- **Tests fail**: Ensure all dependencies installed correctly with `Pkg.instantiate()`
156+
- **Formatting errors**: Run JuliaFormatter before committing
157+
- **Documentation build fails**: Ensure package is added in development mode to docs environment
158+
159+
### Network Issues
160+
If package downloads fail due to network restrictions:
161+
- The package will attempt to download from GitHub and JuliaRegistries
162+
- Allow access to github.com and pkg.julialang.org domains
163+
- Alternatively, use offline Julia registries if available
164+
165+
### Integration Test Failures
166+
If downstream packages fail in IntegrationTest.yml:
167+
- Check if changes break SemVer compatibility
168+
- Review breaking changes impact on AdvancedHMC.jl, AdvancedMH.jl, MCMCChains.jl, etc.
169+
- Consider if changes require coordinated updates across TuringLang ecosystem

0 commit comments

Comments
 (0)