Skip to content

Commit 34ca72d

Browse files
committed
Move tests and improve automatic documentation generation
1 parent 4a79426 commit 34ca72d

18 files changed

+569
-132
lines changed

.github/workflows/pytest.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Run tests
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
- master
9+
10+
jobs:
11+
run-tests:
12+
strategy:
13+
matrix:
14+
python-version: [ "3.10", "3.x" ]
15+
os: [ ubuntu-latest ]
16+
fail-fast: false
17+
runs-on: ${{ matrix.os }}
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
22+
- name: Set up Python ${{ matrix.python-version }}
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: ${{ matrix.python-version }}
26+
27+
- name: Install dependencies
28+
run: |
29+
python -m pip install --upgrade pip
30+
python -m pip install -e .[dev]
31+
32+
- name: Test with pytest
33+
run: |
34+
pytest -n auto

.pre-commit-config.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
repos:
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.6.7
4+
hooks:
5+
- id: ruff # linter
6+
types_or: [ python, pyi, jupyter ]
7+
args: [ --fix ]
8+
- id: ruff-format # formatter
9+
types_or: [ python, pyi, jupyter ]
10+
11+
12+
13+

.readthedocs.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# .readthedocs.yaml
2+
# Read the Docs configuration file
3+
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
4+
5+
# Required
6+
version: 2
7+
8+
# Set the OS, Python version and other tools you might need
9+
build:
10+
os: ubuntu-22.04
11+
tools:
12+
python: "3.11"
13+
14+
# Build documentation in the "docs/" directory with Sphinx
15+
sphinx:
16+
configuration: docs/conf.py
17+
18+
# Optional but recommended, declare the Python requirements required
19+
# to build your documentation
20+
python:
21+
install:
22+
- method: pip
23+
path: .
24+
extra_requirements:
25+
- docs

CHANGELOG.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Changelog
3030
* __Changed__: Due to above, `method` is now the second positional argument (this might break scripts that gave `steps`, `dt`, or `dtunit` as positonal arguments). Call `mre.coefficients(data, 'ts')` or as before via keyword `mre.coefficients(data, method='ts')`
3131
* __Fixed__: Typo that caused `full_analysis()` to crash when calling the consistency check.
3232
* __Fixed__: Workaround to prevent a memory leak when calling `full_analysis()` repeatedly. Always set `showoverview=False` when using `full_analysis()` in for loops.
33-
We now temporarily set `matplotlib.rcParams['interactive'] = showoverview` to avoid opening a new figure every time. This should make the panel and `showoverview` argument feel more consistent. The same workaround can be used in your custom scripts when using the `OutputHandler` (that also opens figures): Nest the loop inside a `with matplotlib.rc_context(rc={'interactive': False}):` (or adjust your rc parameters) to avoid figures.
33+
We now temporarily set `matplotlib.rcParams['interactive'] = showoverview` to avoid opening a new figure every time. This should make the panel and `showoverview` argument feel more consistent. The same workaround can be used in your custom scripts when using the `OutputHandler` (that also opens figures): Nest the loop inside a `with matplotlib.rc_context(rc={'interactive': False}):` (or adjust your rc parameters) to avoid figures.
3434
* __Fixed__: Various small bugs
3535
* __New__: `coefficients` has a new keyword argument `knownmean` to provide a known mean activity. If provdied, it will be used as the expectation value of the activity instead of calculating the mean as an approximation (both, in `stationarymean` and `trialseparated` method). This allows for custom estimates but, for instance, `m>1` will not be detectable as the covariance cannot diverge when the same (time independent) expectation value is used for `<a_{t}>` and `<a_{t+k}>`. As one example, `knownmean=0` restrains the fitted line (with slope `r_k`) to go through the origin `(0,0)`. See [Zierenberg et al., in press](https://arxiv.org/abs/1905.10402).
3636
@@ -47,9 +47,9 @@ We now temporarily set `matplotlib.rcParams['interactive'] = showoverview` to av
4747
* __Changed__: `full_analysis()` argument `fitfunctions` renamed to `fitfuncs` to be consistent with `fit()` and `coefficients()`
4848
* __Changed__: `full_analysis()` was rewritten, now only has three required arguments: `data`, `dt` and `kmax`, where `kmax` can be substituted by `steps` or `tmax`.
4949
* __Changed__: concerning the `seed` argument for various functions:
50-
all functions take either `seed=None` (no reseeding), `seed='random'` (reseeding to a random value - causing irreproducible resaults) or to a fixed value `seed=int(yourseed)`.
51-
Per default, analysis functions - `full_analysis()`, `fit()` and `coefficients()` - produce same results by seeding to a fixed value each call. (only confidence intervals are affected by seeding)
52-
Per default, `simulate_branching()` and `simulate_subsampling()` seed to `random`.
50+
all functions take either `seed=None` (no reseeding), `seed='random'` (reseeding to a random value - causing irreproducible resaults) or to a fixed value `seed=int(yourseed)`.
51+
Per default, analysis functions - `full_analysis()`, `fit()` and `coefficients()` - produce same results by seeding to a fixed value each call. (only confidence intervals are affected by seeding)
52+
Per default, `simulate_branching()` and `simulate_subsampling()` seed to `random`.
5353
* __Fixed__: when calling branching process with `subp` and providing a seed, the subsampling no longer reseeds the rng device. (hence every call produces the same outcome, as expected)
5454
* __Fixed__: `simulate_subsampling()` now returns np arrays of correct dimensions
5555
* __New__: `full_analysis()` now shows a warning in the overview panel if consistency checks fail (so far only one).

CONTRIBUTING.md

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
# Contributing
2+
3+
Contributions are welcome, and they are greatly appreciated! Every little bit
4+
helps, and credit will always be given.
5+
6+
You can contribute in many ways:
7+
8+
## Types of Contributions
9+
10+
### Report Bugs
11+
12+
Report bugs at https://github.com/Priesemann-Group/mrestimator/issues.
13+
14+
If you are reporting a bug, please include ideally a minimal reproducible example with:
15+
- Your operating system name and version
16+
- Python version and mrestimator version
17+
- Any details about your local setup that might be helpful in troubleshooting
18+
- Detailed steps to reproduce the bug
19+
20+
### Fix Bugs
21+
22+
Look through the GitHub issues for bugs. Anything tagged with "bug" and
23+
"help wanted" is open to whoever wants to implement it.
24+
25+
### Implement Features
26+
27+
Look through the GitHub issues for features. Anything tagged with
28+
"enhancement" and "help wanted" is open to whoever wants to implement
29+
it.
30+
31+
### Write Documentation
32+
33+
Mr. Estimator could always use more documentation,
34+
whether as part of the official docs,
35+
in docstrings, or even on the web in blog posts, articles, and such.
36+
37+
If you're interested in improving documentation, you can:
38+
- Fix typos and improve clarity in existing documentation
39+
- Add examples and tutorials
40+
- Improve docstrings in the code
41+
- Create blog posts or tutorials about using mrestimator
42+
43+
### Submit Feedback
44+
45+
The best way to send feedback is to file an issue at
46+
https://github.com/Priesemann-Group/mrestimator/issues.
47+
48+
If you are proposing a feature:
49+
50+
- Explain in detail how it would work.
51+
- Keep the scope as narrow as possible, to make it easier to
52+
implement.
53+
- Remember that this is a volunteer-driven project, and that
54+
contributions are welcome :)
55+
56+
## Get Started!
57+
58+
Ready to contribute? Here's how to set up `mrestimator` for local development.
59+
60+
1. Fork the `mrestimator` repo on GitHub.
61+
62+
2. Clone your fork locally:
63+
64+
```bash
65+
git clone [email protected]:your_name_here/mrestimator.git
66+
```
67+
68+
3. Create a virtual environment with your favorite tool. We recommend using conda:
69+
70+
```bash
71+
conda create --name mrestimator-dev python=3.11
72+
conda activate mrestimator-dev
73+
```
74+
75+
Or with venv:
76+
77+
```bash
78+
python -m venv mrestimator-dev
79+
source mrestimator-dev/bin/activate # On Windows: mrestimator-dev\Scripts\activate
80+
```
81+
82+
4. Install the package including dev dependencies in editable mode:
83+
84+
```bash
85+
cd mrestimator/
86+
pip install -e ".[dev]"
87+
```
88+
89+
This will install:
90+
- The mrestimator package in development mode
91+
- All runtime dependencies (numpy, scipy, matplotlib)
92+
- Optional dependencies (numba, tqdm)
93+
- Development tools (pre-commit, ruff, testing tools)
94+
- Documentation dependencies (sphinx, sphinx-book-theme, etc.)
95+
96+
5. Install pre-commit hooks:
97+
98+
```bash
99+
pre-commit install
100+
```
101+
102+
6. Create a branch for local development:
103+
104+
```bash
105+
git checkout -b name-of-your-bugfix-or-feature
106+
```
107+
108+
Now you can make your changes locally.
109+
110+
7. When you're done making changes, check that your code passes the linter and formatter,
111+
the tests pass, and the documentation builds correctly:
112+
113+
```bash
114+
# Run linting and formatting
115+
make lint
116+
make format
117+
118+
# Run tests
119+
make test
120+
121+
# Build documentation
122+
make docs-build
123+
124+
# Or preview documentation locally
125+
make docs-preview
126+
```
127+
128+
Look inside the `Makefile` for more commands. For instance:
129+
- `make clean` - Remove build artifacts
130+
- `make check` - Run both linting and tests
131+
- `make all` - Run the full development cycle
132+
133+
8. Commit your changes and push your branch to GitHub:
134+
135+
```bash
136+
git add .
137+
git commit -m "Your detailed description of your changes."
138+
git push origin name-of-your-bugfix-or-feature
139+
```
140+
141+
Please write clear, descriptive commit messages that explain what changes you made and why.
142+
143+
9. Submit a pull request through the GitHub website.
144+
145+
## Pull Request Guidelines
146+
147+
Before you submit a pull request, check that it meets these guidelines:
148+
149+
1. The pull request should include tests for any new functionality.
150+
2. If the pull request adds functionality, the docs should be updated.
151+
Put your new functionality into a function with a docstring.
152+
3. The pull request should work for Python 3.10, 3.11, and 3.12.
153+
4. Make sure all existing tests still pass.
154+
155+
## Coding Standards
156+
157+
### Code Style
158+
159+
We use `ruff` for code formatting and linting. The configuration is in `pyproject.toml`.
160+
Run `make format` to automatically format your code and `make lint` to check for issues.
161+
162+
### Documentation Style
163+
164+
- Use NumPy-style docstrings for functions and classes
165+
- Include examples in docstrings where helpful
166+
- Keep line length to 88 characters (enforced by ruff)
167+
168+
### Testing
169+
170+
- Write tests for new functionality
171+
- Use pytest for testing
172+
- Place tests in the `tests/` directory
173+
- Test file names should start with `test_`
174+
175+
## Development Environment
176+
177+
### Dependencies
178+
179+
The development environment includes:
180+
181+
**Core dependencies:**
182+
- numpy (>=1.11)
183+
- scipy (>=1.0.0)
184+
- matplotlib (>=1.7.0)
185+
186+
**Optional runtime dependencies:**
187+
- numba (>=0.44) - for performance improvements
188+
- tqdm - for progress bars
189+
190+
**Development tools:**
191+
- pre-commit - for git hooks
192+
- ruff - for linting and formatting
193+
- pytest - for testing
194+
195+
**Documentation tools:**
196+
- sphinx - documentation generator
197+
- sphinx-book-theme - modern documentation theme
198+
- myst-parser - Markdown support in docs
199+
- nbsphinx - Jupyter notebook support
200+
201+
### Performance Considerations
202+
203+
When running on clusters or in distributed environments, you may need to control
204+
thread usage. Set these environment variables:
205+
206+
```bash
207+
export OPENBLAS_NUM_THREADS=1
208+
export MKL_NUM_THREADS=1
209+
export NUMEXPR_NUM_THREADS=1
210+
export OMP_NUM_THREADS=1
211+
export NUMBA_NUM_THREADS=1
212+
```
213+
214+
## Questions?
215+
216+
If you have questions about contributing, feel free to:
217+
- Open an issue on GitHub
218+
- Contact the maintainers directly
219+
- Join discussions in existing issues
220+
221+
Thank you for contributing to Mr. Estimator!

0 commit comments

Comments
 (0)