Skip to content

Commit 654b271

Browse files
authored
Merge pull request #31 from nanophys/copilot/setup-copilot-instructions
Add GitHub Copilot instructions for repository context
2 parents 8a27380 + 39d70de commit 654b271

File tree

1 file changed

+221
-0
lines changed

1 file changed

+221
-0
lines changed

.github/copilot-instructions.md

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
# GitHub Copilot Instructions for MeasureIt
2+
3+
## Project Overview
4+
5+
MeasureIt (installed as `qmeasure`, imported as `measureit`) is a measurement software package built on top of QCoDeS for condensed matter physics experiments at the University of Washington. It provides sweep-based measurement capabilities with real-time Qt-based plotting and threading.
6+
7+
### Key Technologies
8+
- **Language**: Python 3.8+ (officially tested on 3.8-3.11)
9+
- **Core Framework**: QCoDeS for instrument control and data management
10+
- **GUI**: PyQt5 with pyqtgraph for real-time plotting
11+
- **Threading**: Qt-based threading (RunnerThread, PlotterThread)
12+
- **Package Manager**: uv (recommended) or pip
13+
- **Testing**: pytest with pytest-qt for Qt event loop handling
14+
15+
## Architecture
16+
17+
### Core Components
18+
19+
1. **Sweep System** (`src/measureit/sweep/`):
20+
- `BaseSweep`: Foundation class providing parameter following, measurement creation, and thread management
21+
- `Sweep0D`: Time-based measurements without parameter sweeping
22+
- `Sweep1D`: Single parameter sweep measurements
23+
- `Sweep2D`: Dual parameter sweep measurements
24+
- `SweepQueue`: Batch experiment execution manager
25+
26+
2. **Driver Layer** (`src/measureit/Drivers/`):
27+
- Custom instrument drivers interfacing with lab equipment
28+
- Built on top of QCoDeS instrument base classes
29+
30+
3. **Threading Architecture**:
31+
- `RunnerThread`: Handles data acquisition in background
32+
- `PlotterThread`: Manages real-time plot updates
33+
- Uses Qt signals/slots for thread-safe communication
34+
35+
4. **Data Management**:
36+
- Integration with QCoDeS for data storage
37+
- Configurable data directory via `MEASUREIT_HOME` environment variable or `measureit.set_data_dir()`
38+
- Default locations: `~/.local/share/measureit/` (Linux), `~/Library/Application Support/measureit/` (macOS), `C:\Users\<user>\AppData\Local\measureit\` (Windows)
39+
40+
### Package Structure
41+
```
42+
src/measureit/
43+
sweep/ # Measurement implementations (sweep0d, sweep1d, sweep2d, base_sweep)
44+
tools/ # Utilities (sweep_queue, util, safe_ramp, tracking)
45+
Drivers/ # Instrument drivers
46+
visualization/ # Plotting components (heatmap_thread, helper)
47+
legacy/ # Legacy matplotlib-based plotters
48+
config.py # Configuration management
49+
logging_utils.py # Logging utilities
50+
```
51+
52+
## Development Environment
53+
54+
### Setup
55+
```bash
56+
# Using uv (recommended)
57+
uv pip install -e ".[dev,docs,jupyter]"
58+
59+
# Or using pip
60+
pip install -e ".[dev,docs,jupyter]"
61+
62+
# Install pre-commit hooks
63+
pre-commit install
64+
```
65+
66+
### Tools and Configuration
67+
68+
- **Formatting & Linting**: `ruff` (configured in `pyproject.toml`)
69+
- Replaces black, isort, and flake8
70+
- Run: `make format` or `ruff format src/ tests/`
71+
72+
- **Type Checking**: `mypy` (configured in `pyproject.toml`)
73+
- Run: `mypy src/`
74+
- Not all code is fully typed; add type hints to new code
75+
76+
- **Testing**: `pytest` with `pytest-qt` and `pytest-cov`
77+
- Run: `make test` or `pytest`
78+
- With coverage: `pytest --cov=src/measureit --cov-report=html`
79+
- Qt tests may be flaky in CI; run locally for Qt-specific validation
80+
81+
### Makefile Commands
82+
```bash
83+
make install # Install dependencies
84+
make format # Format code with ruff
85+
make lint # Run all quality checks
86+
make test # Run tests with coverage
87+
make docs # Build documentation
88+
make clean # Clean build artifacts
89+
```
90+
91+
## Code Quality Standards
92+
93+
### Style Guidelines
94+
- Follow PEP 8 with ruff formatting (88 character line length)
95+
- Use Google-style docstrings
96+
- Add type hints to new code (mypy compliance)
97+
- Keep imports sorted (handled automatically by ruff)
98+
99+
### Testing Requirements
100+
- Write tests in `tests/` directory using pytest
101+
- Use `pytest.mark.slow` for slow tests
102+
- Use `pytest.mark.integration` for integration tests
103+
- Mock external dependencies (instruments, hardware) using QCoDeS mock instruments
104+
- Each test run uses isolated temporary database and `MEASUREIT_HOME`
105+
- Qt tests should use `pytest-qt` fixtures (`qtbot`)
106+
107+
### Test Organization
108+
```
109+
tests/
110+
unit/ # Fast, isolated unit tests
111+
integration/ # Component interaction tests
112+
e2e/ # End-to-end workflow tests
113+
stress/ # Performance tests
114+
```
115+
116+
## Common Patterns
117+
118+
### Creating a Sweep
119+
```python
120+
import measureit
121+
from qcodes import Station
122+
123+
# Set up station
124+
station = Station()
125+
# ... add instruments ...
126+
127+
# Create a 1D sweep
128+
sweep = measureit.Sweep1D(
129+
set_param=dac.voltage,
130+
start=0,
131+
stop=1,
132+
step=0.01,
133+
inter_delay=0.1
134+
)
135+
136+
# Follow parameters
137+
sweep.follow_param(dmm.voltage, lockin.x)
138+
139+
# Start measurement
140+
sweep.start()
141+
```
142+
143+
### Thread Safety
144+
- Use Qt signals/slots for cross-thread communication
145+
- Never directly modify GUI elements from background threads
146+
- Use `QMetaObject.invokeMethod` for thread-safe calls if needed
147+
148+
### Data Directory Configuration
149+
```python
150+
import measureit
151+
152+
# Programmatic configuration
153+
measureit.set_data_dir('/custom/path')
154+
155+
# Or use environment variable
156+
# export MEASUREIT_HOME="/path/to/data"
157+
```
158+
159+
## Important Considerations
160+
161+
### Known Issues
162+
- `ipykernel` 7.0.x has event-loop bug preventing Qt/pyqtgraph updates
163+
- Stick to `ipykernel>=6.29,!=7.*` (dependency enforced in pyproject.toml)
164+
- pytest-qt tests are not checked in GitHub Actions CI due to flakiness but can be run locally
165+
166+
### Platform-Specific Dependencies
167+
- Windows: Requires NI DAQmx drivers and NI VISA
168+
- Windows: `multipyvu>=1.2.0` for PPMS integration
169+
- Optional drivers: `nidaqmx`, `zhinst`
170+
171+
### Package Names
172+
- **PyPI package name**: `qmeasure`
173+
- **Import name**: `measureit`
174+
- **Repository name**: MeasureIt
175+
- Always use `import measureit` in code, not `import qmeasure`
176+
177+
## Contributing Guidelines
178+
179+
### Before Making Changes
180+
1. Read `CONTRIBUTING.md` for detailed setup instructions
181+
2. Understand existing code patterns and architecture
182+
3. Run tests locally to ensure baseline passes
183+
4. Create focused, minimal changes
184+
185+
### Pull Request Checklist
186+
1. Run `make format` to format code
187+
2. Run `make lint` to check code quality
188+
3. Run `make test` to verify all tests pass
189+
4. Update documentation if adding features
190+
5. Test with real instruments if possible
191+
6. Write descriptive commit messages
192+
193+
### Commit Message Format
194+
```
195+
Add support for new instrument driver
196+
197+
Fix issue with sweep interruption
198+
- Handle keyboard interrupts gracefully
199+
- Ensure proper cleanup of resources
200+
```
201+
202+
## Documentation
203+
204+
- **Online**: https://measureituw.readthedocs.io/
205+
- **Local build**: `make docs` (output in `docs/source/_build/html/`)
206+
- **API docs**: Use Sphinx with Google-style docstrings
207+
- **Format**: ReStructuredText and Markdown (via myst-parser)
208+
209+
## External Resources
210+
211+
- QCoDeS documentation: https://qcodes.github.io/
212+
- PyQt5 documentation: https://www.riverbankcomputing.com/static/Docs/PyQt5/
213+
- Project repository: https://github.com/nanophys/MeasureIt
214+
- Contributing guide: `CONTRIBUTING.md`
215+
- Bug reports: https://github.com/nanophys/MeasureIt/issues
216+
217+
## Active Users
218+
219+
The package is actively used by condensed matter physics labs at:
220+
- University of Washington (David Cobden's lab, Xiaodong Xu's lab)
221+
- MIT (Pablo Jarillo-Herrero's lab, Long Ju's lab)

0 commit comments

Comments
 (0)