Skip to content

Commit 740a411

Browse files
Add comprehensive GitHub Copilot instructions for BindsNET
Co-authored-by: Hananel-Hazan <3954715+Hananel-Hazan@users.noreply.github.com>
1 parent a0e6178 commit 740a411

File tree

1 file changed

+222
-0
lines changed

1 file changed

+222
-0
lines changed

.github/copilot-instructions.md

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
# BindsNET - Spiking Neural Networks for Machine Learning
2+
3+
**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.**
4+
5+
BindsNET is a Python spiking neural network library built on PyTorch for machine learning applications. It provides tools for creating, training, and analyzing spiking neural networks with focus on biologically-plausible learning algorithms.
6+
7+
## Working Effectively
8+
9+
### Prerequisites and Environment Setup
10+
- **CRITICAL**: Requires Python >=3.10 (currently tested with Python 3.12.3)
11+
- **NEVER CANCEL**: All build and dependency installation commands can take 15-45 minutes. Always set timeouts to 60+ minutes.
12+
- Install Poetry for dependency management: `pip install poetry` (takes ~2 minutes)
13+
14+
### Bootstrap and Install Dependencies
15+
**Primary method (Poetry - recommended but may fail due to network issues):**
16+
```bash
17+
export PATH="$HOME/.local/bin:$PATH"
18+
poetry config virtualenvs.create false # Use system Python to avoid conflicts
19+
poetry install # NEVER CANCEL: Takes 15-45 minutes, set timeout to 60+ minutes
20+
poetry run pre-commit install # Setup code formatting hooks
21+
```
22+
23+
**Alternative method (pip - use when Poetry fails):**
24+
```bash
25+
# Install core dependencies first
26+
pip install torch torchvision numpy scipy matplotlib tqdm pytest
27+
28+
# Install additional packages as needed (may require system packages)
29+
sudo apt update && sudo apt install -y python3-pandas python3-sklearn python3-dev
30+
pip install tensorboardX scikit-learn opencv-python gymnasium[atari] ale-py
31+
32+
# Install in editable mode
33+
pip install -e .
34+
```
35+
36+
**IMPORTANT NOTES:**
37+
- Poetry installation may fail due to network timeouts or system package conflicts
38+
- When Poetry fails, use pip-based installation as backup
39+
- Some dependencies (like pandas) may have numpy version conflicts - use system packages via apt when needed
40+
- Network timeouts are common - retry operations with longer timeouts
41+
42+
### Testing and Validation
43+
**Run tests:**
44+
```bash
45+
# With Poetry (if installed successfully)
46+
poetry run pytest # NEVER CANCEL: Takes 5-15 minutes
47+
48+
# With pip installation
49+
export PYTHONPATH="/home/runner/work/bindsnet/bindsnet:$PYTHONPATH"
50+
python -m pytest test/ -v # May have import issues due to missing dependencies
51+
```
52+
53+
**CRITICAL**: Many tests may fail due to missing optional dependencies (pandas, scikit-learn, opencv). This is expected in environments with incomplete dependency installation.
54+
55+
## Validation Scenarios
56+
57+
**ALWAYS test these scenarios after making changes:**
58+
59+
1. **Basic import test (most reliable):**
60+
```bash
61+
python -c "
62+
import sys, os
63+
print('Python version:', sys.version)
64+
try:
65+
import torch, numpy as np, matplotlib
66+
print('✓ Core dependencies (torch, numpy, matplotlib) available')
67+
print(' PyTorch version:', torch.__version__)
68+
print(' NumPy version:', np.__version__)
69+
print('✓ Basic validation complete')
70+
except Exception as e:
71+
print('✗ Error:', e)
72+
"
73+
```
74+
75+
2. **Repository structure validation:**
76+
```bash
77+
# Verify key directories and files exist
78+
test -d bindsnet && echo "✓ bindsnet/ directory exists" || echo "✗ bindsnet/ missing"
79+
test -d examples && echo "✓ examples/ directory exists" || echo "✗ examples/ missing"
80+
test -d test && echo "✓ test/ directory exists" || echo "✗ test/ missing"
81+
test -f pyproject.toml && echo "✓ pyproject.toml exists" || echo "✗ pyproject.toml missing"
82+
```
83+
84+
3. **Example help text (limited validation):**
85+
```bash
86+
# These will likely fail due to import issues but show example structure
87+
cd examples/mnist && python eth_mnist.py --help 2>&1 | head -5 || echo "Import dependencies missing (expected)"
88+
cd examples/benchmark && python benchmark.py --help 2>&1 | head -5 || echo "Import dependencies missing (expected)"
89+
```
90+
91+
4. **Code formatting and linting (when dev tools available):**
92+
```bash
93+
# Only works if dev dependencies successfully installed
94+
poetry run pre-commit run -a || echo "pre-commit tools not available"
95+
```
96+
97+
## Repository Structure
98+
99+
### Key directories:
100+
- `bindsnet/`: Main package code
101+
- `network/`: Core network components (nodes, connections, topology)
102+
- `learning/`: Learning algorithms (STDP, reward-modulated learning)
103+
- `encoding/`: Input encoding methods (Poisson, rank-order, etc.)
104+
- `models/`: Pre-built network architectures
105+
- `analysis/`: Analysis and visualization tools
106+
- `datasets/`: Dataset handling utilities
107+
- `environment/`: RL environment interfaces
108+
109+
- `examples/`: Example scripts and tutorials
110+
- `mnist/`: MNIST classification examples with different architectures
111+
- `breakout/`: Atari Breakout reinforcement learning
112+
- `benchmark/`: Performance benchmarking tools
113+
- `tensorboard/`: TensorBoard integration examples
114+
115+
- `test/`: Unit tests (pytest-based)
116+
- `docs/`: Documentation source files
117+
118+
### Important files:
119+
- `pyproject.toml`: Poetry configuration and dependencies
120+
- `setup.py`: Fallback setup script for pip installation
121+
- `CONTRIBUTING.md`: Development workflow and guidelines
122+
- `.github/workflows/`: CI/CD pipelines (python-app.yml, black.yml)
123+
124+
## Common Tasks and Troubleshooting
125+
126+
### Dependency Installation Issues:
127+
- **Poetry fails with timeout**: Use pip-based installation method
128+
- **numpy.dtype size error**: Install system packages via apt instead of pip
129+
- **Module not found errors**: Export PYTHONPATH or use `pip install -e .`
130+
131+
### Development Workflow:
132+
1. Create feature branch: `git branch feature-name`
133+
2. Install pre-commit hooks: `poetry run pre-commit install`
134+
3. Make changes and test locally
135+
4. Format code: `poetry run pre-commit run -a`
136+
5. Run tests: `poetry run pytest`
137+
6. Commit and push changes
138+
139+
### Performance Notes:
140+
- **CPU vs GPU**: Examples default to CPU, use `--gpu` flag for CUDA acceleration
141+
- **Memory usage**: Large networks may require significant RAM (8GB+ recommended)
142+
- **Training time**:
143+
- eth_mnist.py: ~1 hour on Intel i7 CPU for full training
144+
- batch_eth_mnist.py: ~1 minute/epoch on GPU (GTX 1080ti)
145+
- Benchmark tests: 5-15 minutes depending on parameters
146+
147+
## Known Limitations and Common Issues
148+
149+
1. **Dependency Installation Challenges:**
150+
- Poetry may fail with network timeouts (common in CI environments)
151+
- System package conflicts between pip and apt-installed packages
152+
- numpy/pandas version mismatches causing import errors
153+
- **SOLUTION**: Use pip-based installation as fallback, install system packages via apt
154+
155+
2. **Import and Module Issues:**
156+
- Many examples fail to import bindsnet due to missing analysis dependencies (pandas)
157+
- tensorboardX and other optional dependencies may not be available
158+
- **SOLUTION**: Set PYTHONPATH and install core dependencies only for basic functionality
159+
160+
3. **Development Tool Availability:**
161+
- pre-commit hooks may not work if dev dependencies not installed
162+
- black/isort formatters may not be in PATH
163+
- **SOLUTION**: Install formatting tools separately or skip formatting validation
164+
165+
4. **Example Execution:**
166+
- Full MNIST examples require 1+ hours and significant computing resources
167+
- GPU examples need CUDA-compatible PyTorch installation
168+
- **SOLUTION**: Use minimal parameters for testing (small epochs, reduced data)
169+
170+
5. **Testing Issues:**
171+
- pytest may fail on multiple test modules due to missing dependencies
172+
- Analysis and conversion tests especially prone to import errors
173+
- **SOLUTION**: Focus on core network functionality tests, accept partial test failures
174+
175+
## Example Command Reference
176+
177+
```bash
178+
# Quick start with minimal MNIST example (1 epoch, reduced data)
179+
export PYTHONPATH=".:$PYTHONPATH"
180+
python examples/mnist/eth_mnist.py --n_epochs 1 --n_train 100 --n_test 50 --time 100
181+
# NEVER CANCEL: Still takes 15-30 minutes even with reduced parameters
182+
183+
# Benchmark network performance
184+
python examples/benchmark/benchmark.py --start 100 --stop 500 --step 100
185+
186+
# Run tests (may fail due to missing dependencies)
187+
poetry run pytest test/ -v --tb=short || python -m pytest test/ -v
188+
189+
# Format code (requires dev dependencies)
190+
poetry run pre-commit run -a
191+
# Alternative if poetry dev deps not available:
192+
pip install black isort && black bindsnet/ examples/ test/ && isort bindsnet/ examples/ test/
193+
```
194+
195+
**TIMEOUT WARNINGS AND TIMING EXPECTATIONS:**
196+
- **Poetry install**: 60+ minutes timeout (15-45 minutes typical, varies by network)
197+
- **pip install torch/dependencies**: 30+ minutes timeout (10-20 minutes typical)
198+
- **pytest execution**: 30+ minutes timeout (5-15 minutes, many tests may fail)
199+
- **MNIST example (full)**: 90+ minutes timeout (~1 hour typical on Intel i7)
200+
- **MNIST example (minimal params)**: 45+ minutes timeout (15-30 minutes typical)
201+
- **pre-commit formatting**: 15+ minutes timeout (2-5 minutes typical)
202+
- **NEVER CANCEL** any long-running operations - they are expected to take significant time
203+
204+
## Validated Commands
205+
206+
The following commands have been tested and work reliably:
207+
208+
```bash
209+
# Environment check (always works)
210+
python --version && echo "✓ Python available"
211+
212+
# Dependencies check
213+
python -c "import torch, numpy, matplotlib; print('Core deps OK')"
214+
215+
# Repository structure
216+
test -d bindsnet && test -d examples && test -d test && echo "✓ Repo structure OK"
217+
218+
# Poetry availability
219+
poetry --version || echo "Poetry not available, use pip method"
220+
```
221+
222+
Always validate any changes by running at least the basic dependency and structure checks to ensure the environment is functional.

0 commit comments

Comments
 (0)