Contributing to telescopic

telescopic aims to be small, correct and pleasant to use. A change must keep every estimator exactly unbiased (or clearly label an approximation), come with tests, and read like the code around it.

Set-up

git clone https://github.com/joshspeagle/telescopic
cd telescopic
# In an environment of your own (venv, uv, conda), with pip 25.1 or newer:
python -m pip install -e . --group dev --group docs
pre-commit install      # ruff lint and format, and codespell, on every commit

Commands

scripts/verify.sh              # lint, format, spelling and type checks (Python 3.12+), fast tests
scripts/verify.sh --cov        # with the coverage floor that CI enforces
scripts/verify.sh --docs       # also the identity checks and the strict documentation build
scripts/verify.sh --slow       # also the slow statistical tests
python benchmarks/run.py       # timings against spec section 10, on an idle machine

The script runs the commands of CI’s lint and test jobs on the checkout’s sources. The fast tests finish in under 2 minutes and treat warnings as errors.

Documentation

The site is built with Sphinx from docs/, in its own theme. Every build executes the tutorials, and a failing cell fails it:

scripts/verify.sh --docs                              # the checks, then the strict build
sphinx-build -W --keep-going docs docs/_build/html    # the strict build alone

The gate builds from the checkout’s sources. A bare sphinx-build imports the installed package: in a second checkout or a worktree, prefix it with PYTHONPATH="$PWD/src". CI builds the site on every push and pull request, and publishes the build of each push to main on GitHub Pages.

The environment variable TELESCOPIC_DOCS_EXECUTE sets how the build runs the notebooks. force, the default and what CI uses, runs every notebook. cache reuses the outputs of a notebook whose cells have not changed since it last ran, so after a change to the package or to the plot style it can show old outputs. off runs nothing: pages show their code without outputs, and numbers glued from cells are missing, so build without -W. Use cache or off only for work on prose or styling, and check the result with a full build:

TELESCOPIC_DOCS_EXECUTE=cache sphinx-build docs docs/_build/html

The build reads the inventories of Python, NumPy, SciPy and Matplotlib, which resolve references to their documentation, from their sites. When the environment variable TELESCOPIC_DOCS_INVENTORIES names a directory by its absolute path, it reads <name>.inv there first, as python.inv, and the site when that file is missing. CI fetches the four into one with retries before it builds, so that a site that does not answer once does not fail the build.

The API reference, docs/api.md, is an index of autosummary tables, one per section. The build generates a page for each name the tables list into docs/api/, which is not committed: a class’s page shows its attributes and methods, and a module’s page its functions and data and a table of the classes of its __all__. A new public class or module, or a function that telescopic itself exports, is listed in docs/api.md under its section, and a new function or constant of a module in its module’s __all__; the tests fail when a public class, a module that telescopic exports, or a name of the __all__ of a module without a row has no page. Before generating the pages, the build deletes those of docs/api/ that no table lists any more, so a name removed or renamed leaves no stale page.

The colors, fonts, sizes, marks and plot style come from one script, docs/_scripts/brand.py, whose docstring lists the files it writes. Edit the values there and run it; CI runs it with --check, which names any file that is stale:

python docs/_scripts/fetch_fonts.py      # after a change to brand.FONTS: the woff2 files
python docs/_scripts/hero_pair.py        # after a change to the package moves the hero's pair
python docs/_scripts/brand.py            # writes the identity's files, the hero among them
python docs/_scripts/brand.py --check    # fails if a written file is stale

The hero is one coupled pair run by telescopic; hero_pair.py --check, which CI also runs, fails when the package no longer produces the saved pair and says what moved. Save the new pair with hero_pair.py, then run brand.py, which draws the hero from it.

The generated figures of the site are drawn by docs/_scripts/figures.py in the identity’s colors, from the package’s own runs and from computations the script shows, into docs/_static/figures/; a page inlines one with the {diagram} directive, whose content is its caption. After a change to a figure, or to the package that moves one, run the script; CI runs it with --check, which names any figure that is stale:

python docs/_scripts/figures.py          # redraws the generated figures
python docs/_scripts/figures.py --check  # fails if a committed figure is stale

The design records are read in the repository and are not built into the site: docs/design/ holds the specification, the test plan, the implementation plan and the design of the site’s identity, and research_notes/ and reports/ hold the census of published methods and software behind the design.

Validation philosophy

  • Exact references first. A coupling is tested draw for draw against an independent reference with injected random numbers, for its marginals against the exact one-step law, for faithfulness, and for its meeting frequency against closed forms. An estimator is tested by algebraic identities and exact finite-state expectations before any statistical test. Index bugs in the bias correction shift estimates by a fraction of a percent of their spread, far below what replicate averages can detect.

  • Tolerances come from the Monte Carlo error, by the one rule of docs/design/test-plan.md section 1, which references.assert_z_scores applies. Seeds are never tuned to make a test pass.

  • A test earns its place by catching a plausible bug that no other test catches.

Style

  • ruff check and ruff format (line length 99) and mypy --strict on src/.

  • Use the notation of docs/theory.md in code, docstrings and docs.

  • Randomness flows through a rng argument (SPEC 7) and, inside the engine, through each replicate’s own stream. Never use NumPy’s global random state.

  • User-facing problems raise ValueError or TypeError with a message that names the argument and says how to fix it. Questionable inputs emit InputWarning; results that may be unreliable emit ConvergenceWarning.

  • The Examples section of a docstring runs as a test (tests/test_docstrings.py), on the package that import telescopic finds. An example imports what it uses, fixes rng, runs well under a second without a warning, and prints shapes, counts, booleans or settings rather than digits that another platform’s random numbers would change. It must print the same at other seeds: an example that runs the sampler uses fewer than 100 replicates, below which the replicate-variance warning does not apply, and notes/experiments/i85_docstring_examples.py counts, for each example, the seeds at which it warns or prints something else. At 1,000 seeds none does, except check_coupling, whose passed() is random and fails at the rate its docstring states.

Adding a kernel

A kernel follows the rules of the guide’s Write a kernel page and passes telescopic.testing.check_coupling. Add the oracle, marginal and faithfulness tests of docs/design/test-plan.md section 2.4.

Pull requests

Keep each change focused, add a line to CHANGELOG.md under Unreleased, and describe how you validated any statistical change.

Releasing

Releases go to PyPI from .github/workflows/release.yml through trusted publishing; no token is stored anywhere. Pushing a tag vX.Y.Z starts it, and so does creating a release on GitHub with a new tag vX.Y.Z, which pushes that tag. The build job checks that the tag’s commit passed CI on main, that the tag names the package’s version and that CHANGELOG.md has that version’s section. The workflow then uploads to TestPyPI, checks that TestPyPI serves this build and that it installs and imports in a clean environment, waits for a reviewer of the pypi environment to approve, uploads to PyPI, and creates the GitHub release, or updates the one already made, with the version’s CHANGELOG section as notes and the wheel and sdist attached.

  1. In a pull request, set the version to X.Y.Z in src/telescopic/__init__.py and in CITATION.cff (with date-released), and turn Unreleased in CHANGELOG.md into ## [X.Y.Z] - YYYY-MM-DD.

  2. Merge the pull request, wait for CI on the merge commit to pass, then tag the merge commit and push the tag:

    git switch main && git pull
    git tag vX.Y.Z
    git push origin vX.Y.Z
    
  3. Approve the pypi job on the workflow’s run page once the TestPyPI check passes.

  4. Open a new Unreleased section and set the version to the next .dev0.

If a job fails, rerun only the failed jobs, so that the build stays the one on TestPyPI.