Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Contributing

Contributions through pull requests

If you would like to add a new feature, fix a bug or make some improvements, please follow this guideline. When planning a new feature, introduce the proposal and discuss it on the discussion page. Automated contributors must also follow the repository AGENTS.md and any instructions scoped to the directory being changed. Changes to the CyteBase catalog SDK or its build pipeline belong in the CyteBase repository.

The project uses Ruff for formatting and linting. Before opening a pull request, run the same static checks as CI:

uv run ruff check cytearc profiling tests
uv run ruff format --check cytearc profiling tests
uv run mypy cytearc profiling

Writing

Write names, messages, plot labels, docstrings, comments and documentation in US English, the spelling of CyteArc’s public names: color, neighbor, labeled, normalize, center, gray and analyze. Paper titles, proper names and text quoted from other tools keep their own spelling.

Licensing and provenance

CyteArc is released under the BSD 3-Clause License, and contributions are licensed under the same terms.

AI-assisted contributions

AI-assisted contributions follow the same rules, and you remain the author of the pull request:

  1. Read and understand every line before you open the pull request.

  2. Do not give an AI tool the source code of a project whose license is incompatible with BSD-3-Clause to port, translate, or imitate, and do not ask it to reproduce such an implementation. If generated code reproduces a recognizable implementation, treat it as that project’s code: attribute it under a compatible license, or discard it.

  3. Cite the methods and tools the code follows.

  4. Show that new behavior works, with tests, reference comparisons, or executed documentation pages.

Testing locally

You can run the tests locally on your branch with pytest. Configurations are in pyproject.toml. Install the development, profiling, and test dependencies with:

uv sync --group dev --group profiling --extra test --extra extra
uv run python -m tests.download_fixtures --with-h5ad

Python 3.13 or newer is required (requires-python >=3.13). .python-version makes 3.13 the default interpreter for uv sync and uv run, matching the Modal images. uv 0.13.4 or newer is required (required-version in pyproject.toml), because older releases trust the eMudhra emSign ECC Root CA - G3, whose intermediate certificates were compromised. Update uv with UV_SYSTEM_CERTS=true uv self update, which checks the download against the operating system’s certificates.

Two markers select the expensive parts of the suite: slow for tests that build neighborhood graphs or run iterative numerical workflows, and integration for tests that need live network access. An integration test downloads its files through download_or_skip of tests/network_helpers.py, which skips the test when a host cannot serve a file whole and fails it when a file is missing, and a run ends naming each test that skipped for the network. GEO’s file server also answers 404 under load for files that it holds, so a 404 from it fails the test only when the listing of the file’s directory no longer names the file. While iterating, skip both:

uv run pytest -m "not slow and not integration"

CI runs the whole suite, so run uv run pytest before opening a pull request. CI splits the suite into four jobs per configuration; uv run pytest --shard 2/4 runs the second of those shards locally. pandas stores text with pyarrow whenever pyarrow is installed, which the lock file does not do, so four more jobs layer pyarrow on the locked environment and split the quick suite into shards. uv run --with pyarrow pytest -m "not slow and not integration" runs it locally without changing the project environment.

A weekly run of the Newest releases workflow tests the newest releases of the dependencies, which an install that resolves afresh, such as pip install cytearc, takes: it calls the Tests workflow, whose four highest jobs install them on Python 3.14 without the lock and run the whole suite. Dispatch Newest releases to run them by hand. Its runs are its own, never Tests runs, so the release workflow’s check of the release commit’s Tests run never takes one.

Under a memory limit, such as a cgroup cap of 8 GiB, run the four shards one after another, with four workers each; the last command fails if any shard failed:

failed=0
for shard in 1 2 3 4; do uv run pytest --shard "$shard/4" -n 4 || failed=1; done
test "$failed" -eq 0

pytest-xdist starts its workers once for a run, and each worker runs file after file until the run ends (how xdist works), so the workers’ memory grows over a run: on an 8-core Mac with an empty Numba cache, a shard’s workers and controller together held at most 1.5 to 3.0 GiB of physical memory in its first tenth and 5.3 to 6.8 GiB near its end, although each shard runs its longest files first. Each shard starts new workers, which hold only what their quarter of the suite leaves. The four shards took 14 minutes there, without the tests that need the network.

Measure the coverage of a change with the directory of its package:

uv run pytest -n 0 --cov=cytearc/metadata --cov-branch --cov-report=term-missing tests/test_metadata_column_encoding.py

A dotted name such as --cov=cytearc.metadata.encoding makes coverage.py import and unload the parent package, leaving two copies of pandas, so unrelated tests fail with TypeError: the dtype str is not supported for parsing (coveragepy#2324).

New code charges its memory budget with the arrays and blocks that grow with its data, and does not model the runtime’s own memory, such as Python’s and Zarr’s objects, file buffers or NumPy’s temporaries. A memory test checks behavior at a fixed budget derived from its data’s size: a budget too small for the data raises MemoryBudgetError before anything is written, naming the step and what to change, and a small budget that streams in several blocks gives the result of a large one. A memory test traces no memory and searches for no smallest budget, since on toy data the runtime’s own memory is as large as the data; memory at scale is checked with notebooks and benchmarks on large data.

Several dependencies publish no Python 3.15 wheels, so the 3.15 jobs compile them from source. The test jobs cache the wheels uv builds, keyed by Python version, resolution, and runner image; a changed uv.lock restores the previous cache, so only new or changed packages compile. The 3.15 jobs also cache the Ubuntu packages they compile against, keyed by those packages’ versions, because a slow Ubuntu mirror took up to 11 minutes to download them; a changed version downloads only the changed packages. tests/shards.py balances the shards by the seconds each test file took, recorded in tests/shard_durations.json. After adding slow test files or changing how long existing ones take, refresh the record with a cold Numba cache, as on a CI runner:

NUMBA_CACHE_DIR=$(mktemp -d) uv run pytest --store-shard-durations

The first run after a change to a module that uses njit, or after a new release tag, compiles every kernel that the suite uses again; commits that change no such module load the kernels that earlier runs compiled. A process that sees a module that uses njit change while it runs, as under IPython’s autoreload, compiles its kernels without the cache until it restarts.

For full CI parity, also run the visual regression step (or see AGENTS.md):

MPLBACKEND=Agg CYTEARC_RUN_VISUAL_REGRESSION=1 \
  uv run pytest -n 0 -m visual tests/test_plotting_showcase.py

Performance benchmarks

tests/benchmarks/ times the operations that dominate large runs and projects each timing onto production sizes, such as one and ten million cells. test_kernels.py covers compute kernels, test_stages.py the DataStore stages, test_cold_start.py the import and compilation cost of a new process, and the test_scaling_*.py files readers, graphs, features, plotting, merge and export, identity checks, and the lineage kernels of trajectory analysis. Every benchmark also checks its result against an independent reference. A normal test run executes each benchmark once at a small size, without timing it. Timed runs need a quiet machine and their own process:

CYTEARC_RUN_BENCHMARKS=1 uv run pytest -n 0 tests/benchmarks

Each benchmark times a ladder of input sizes and fits one of three models: a power law for kernels, a fixed overhead plus a per-unit rate for calls whose overhead hides their per-unit work at small sizes, and a constant for per-call overheads and the cold start of a new process. Repeats are interleaved across sizes, so a change in machine load during the run slows every size alike instead of bending the fitted scaling. The run prints each benchmark’s largest measured time, its fitted scaling, and its projected single-thread time at the production sizes. When a baseline is available, it also reports the change from that baseline. With a comparison baseline, a benchmark fails only when its slowdown exceeds timing noise (30% by default, after calibrating for machine speed) and projects to a meaningful delay at some production size: 2 s per million cells by default, so 2 s at one million and 20 s at ten million, or 0.5 s of fixed overhead per call. Judging every size catches a superlinear cost that is still small at one million cells. A growing power-law exponent also fails when it projects to a meaningful delay at ten million cells, even if small inputs look unchanged. Scaling is judged only when both fits are tight (r-squared at least 0.97); a noisier fit is judged at its largest measured size alone. Before failing, a benchmark measures its ladder again and keeps the fastest time at each size, so a regression must survive two measurements and transient noise cannot fail it.

When tests/benchmarks/baseline.json is absent, a timed run records measurements in build/benchmarks/latest.json without comparing performance or declaring a regression. An explicitly configured CYTEARC_BENCHMARK_BASELINE must exist. For a comparison, measure the base and changed code on the same machine:

CYTEARC_RUN_BENCHMARKS=1 CYTEARC_BENCHMARK_OUTPUT=/tmp/base.json uv run pytest -n 0 tests/benchmarks
# then, in the changed checkout:
CYTEARC_RUN_BENCHMARKS=1 CYTEARC_BENCHMARK_BASELINE=/tmp/base.json uv run pytest -n 0 tests/benchmarks

To create or replace the default baseline with measurements from the current code:

CYTEARC_RUN_BENCHMARKS=1 CYTEARC_BENCHMARK_UPDATE=1 uv run pytest -n 0 tests/benchmarks

CYTEARC_BENCHMARK_SLOWDOWN sets the tolerated slowdown ratio, for example 1.5 when comparing across machines. CYTEARC_BENCHMARK_THREADS sets the Numba thread count, one by default. CYTEARC_BENCHMARK_OUTPUT sets where results are written, build/benchmarks/latest.json by default.

Operation revisions

A fix that changes what an analysis operation computes for unchanged parameters and inputs must also stop CyteArc from reusing the results that earlier code stored (Operation revisions). To change an operation’s outputs:

  1. Decide with the ladder in Operation revisions whether the change needs no revision, a scoped revision, or a revision of every artifact of the operation.

  2. Append the OperationRevision entry to the operation’s tuple in cytearc/storage/operation_revisions.py.

  3. Add a test that a new artifact of the operation records the revision and that an artifact of the earlier revision is recomputed, not reused.

  4. A change that needs no revision but still moves results is listed under Results that change while identities stay the same on the operation revisions page.

Contributions to the documentation

Author executable tutorials and the quick start as .ipynb files under docs/source/. Each tracked notebook is the page’s sole source, containing prose, code, outputs, and execution metadata. Edit it directly. Prose guides and API references remain Markdown; excluded pages retain their source-only MyST Markdown. MyST renders the main site; Sphinx builds the API reference from docs/source/reference/api/.

Use Node.js 24 and install the Python tools:

uv sync --group docs-modal --extra docs --extra test --extra extra

Execute affected notebooks

Choose the pages that need fresh results after changing their code, CyteArc, dependencies, or input datasets. Run them concurrently in separate ephemeral Modal containers:

make -C docs execute-docs-modal PAGES="tea_seq cell_cycle" MODAL_ENVIRONMENT=your_environment

The runner reads the selected source notebooks and atomically replaces each successful one at the same path in docs/source/. It records metadata.executed_at and the executed code’s metadata.executed_code_sha256 fingerprint, a hash of the code cells’ Python tokens that leaves out comments and blank lines. Editing a comment therefore keeps the saved outputs valid, while any change to the code itself requires re-execution. Do not edit the fingerprint by hand. Commit the updated notebook alongside any package changes that required re-execution. A failed page leaves its previous notebook intact and reports the error; rerun it after fixing the cause. Submit affected pages in one invocation, with one container per page. Do not execute the same notebook concurrently or render while the runner is replacing it. The runner consumes published datasets and does not rebuild or publish them. Provider-backed tutorials require separate credentials and authorization.

Each code cell’s output ends with its UTC start time and elapsed wall time, recorded automatically by the runner. CPU time is not measured. Keep %%time out of notebook cells.

Build and inspect

make -C docs html

Open docs/build/site/_build/html/index.html through a local static web server. This command builds the Sphinx API, checks its public-symbol coverage, and renders MyST without executing notebooks. Each source notebook supplies both the rendered page and its notebook download. Edits to prose and code comments reuse the saved outputs; other code changes require re-execution to update the fingerprint. Every executable page needs a complete, successful execution with a matching fingerprint.

Use make -C docs preview while editing unexecuted notebooks. Unexecuted pages display a source-preview warning explaining that their figures and results are unavailable. This command still rejects changed code and incomplete or failed executions. Pages excluded through project.exclude in docs/source/myst.yml remain source-only. Both commands rebuild the generated site and API output so removed pages do not leave old routes behind.

Run the documentation checks with:

uv run pytest -n 0 tests/test_docs_structure.py tests/test_docs_render.py \
    tests/test_docs_execution.py
make -C docs check-reference

Publish to GitHub Pages

The GitHub Pages workflow builds and publishes the complete site on pushes to master. Pull requests, PyPI release checks, and Pages validate and render the notebooks committed in docs/source/ with make -C docs html. CI does not execute notebooks. Missing, failed, or stale executions fail the build. After changing executable code, rerun the affected pages on Modal, inspect the complete HTML build, and commit the updated notebooks. Changes to prose and code comments can reuse outputs. Rendered site files under docs/build/ remain ignored by Git.

In the repository’s Pages settings, select GitHub Actions as the publishing source. Set the custom domain to docs.nygen.io; the documentation is served at https://docs.nygen.io/CyteArc/. The workflow checks each notebook’s execution metadata and code fingerprint, then builds with BASE_URL=/CyteArc and places the site inside the Pages artifact’s CyteArc/ directory. The deployment job alone receives Pages write permissions. A manual run of GitHub Pages on master can publish the current commit again.

Add a tutorial

  1. Add an .ipynb file under docs/source/tutorials/ with Markdown cells, code cells, and kernel metadata.

  2. Register it in docs/source/myst.yml, in the section of the question it answers, and list it under the same section of docs/source/llms.txt.

  3. Execute it on Modal and inspect its figures and downloaded notebook.

  4. Commit the notebook with its outputs and execution metadata. Keep rendered site files outside Git.

Fact-check method names against cytearc/, dataset identifiers against the cytearc_docs example repository (cytearc.datasets.connect("cytearc_docs").list_datasets()), and numerical claims against actual outputs. Keep credentials and private connection values out of sources and notebook outputs.

A page that opens a store with download_dataset(..., zarr=True) gets back, when a reader runs it again in the same directory, the store that the earlier run downloaded, with the results that run saved in it. Every step that creates a named result must therefore succeed when that result already exists: open a saved run or assay when it is there, insert columns with overwrite=True, and leave out labels that nothing reads.

Republishing the example stores

Pages that are not about building an artifact lineage open a pre-analyzed store with download_dataset(..., zarr=True). Source stores are rebuilt from raw counts, while declared derived stores are rebuilt from their published inputs. scripts/regenerate_docs_datasets.py writes both kinds and runs each store’s analysis with the pipeline recipes, saving every run under a label: rna, atac, or adt for a modality, and wnn or snn for a joint run of pipeline.multimodal. It creates a manifest under docs/source/developers/dataset_manifests/ recording the dataset recipe, cell counts, the artifact inventory, the pipeline-run inventory (each run’s ID, label, recorded recipe, and status), and the archive checksum:

uv run python scripts/regenerate_docs_datasets.py --all

--all excludes checksum-pinned external recipes and their direct derivatives so routine regeneration does not trigger large third-party downloads. Rebuild one of those recipes by name:

uv run python scripts/regenerate_docs_datasets.py swanson_7K_pbmc_teaseq

Prepare Tabula Sapiens once, then derive the teaching sample from its local store:

uv run python scripts/regenerate_docs_datasets.py tabula_sapiens tabula_sapiens_100k

The full atlas retains the authors’ annotations and UMAPs. The 100,000-cell sample adds a prepared CyteArc analysis shared by the quick start and result-reuse tutorial. Rebuilding only tabula_sapiens_100k reuses build/cytebase/tabula_sapiens/data.zarr when its archive is beside it, and stops at a store without one, which a rebuild that stopped partway leaves. Documentation rendering reads saved notebooks and does not rebuild either dataset.

Rebuild a store whenever its dataset recipe changes, or whenever the stored layout changes in a way that would stop the published artifacts from being reused. Nothing leaves build/cytebase until you publish:

uv run python scripts/publish_docs_datasets.py            # print the plan
uv run python scripts/publish_docs_datasets.py --apply    # needs a write token

Publishing replaces <dataset>/data.zarr.tar.gz and <dataset>/manifest.json. For stores used in remote examples, it also synchronizes their unpacked files, and it refuses an unpacked store whose size differs from the one its manifest records. A dataset needs a matching generated manifest and archive before it can be published. Run without names, the script publishes every dataset with an archive in build/cytebase, including archives of earlier rebuilds and of stores rebuilt only as sources for another dataset, and lists the ones it leaves out; name datasets to publish only those. A rebuild removes the dataset’s earlier archive before its earlier store, even if the rebuild then fails, so a dataset whose rebuild stopped partway has nothing to publish until it is rebuilt.

The bucket paths carry no version, so publishing replaces the stores that the tutorials of every CyteArc version download. A rebuild whose stores the latest release cannot read, or whose run labels that release’s tutorials do not open, breaks those tutorials until the next release. Stores rebuilt with the pipeline recipes are such a rebuild: the tutorials of CyteArc 1.3.0 open their saved run with pipeline.open(label="docs_default"), a label that the rebuilt stores do not hold, and the report() of 1.3.0 rejects stage records that carry summary or warnings. Note such a rebuild in the release’s changelog, and publish it as close to the release as practical.

Releasing

Publishing a GitHub release runs .github/workflows/publish.yml. Every job checks out the exact commit that the release tag named when the release was published (github.sha), and the upload to PyPI waits for four gates on that commit:

tests/smoke_wheel.py checks that the wheel is pure Python and complete, installs it into a clean environment with uv venv and uv pip install, imports the public modules from the installed wheel, and runs tests/smoke_workflow.py with that environment’s interpreter in isolated mode. That script imports a synthetic three-population count matrix with SparseToZarr and analyzes it with pipeline.rna; the run must complete, its UMAP coordinates must be finite, and Leiden must find at least two clusters. It then exports the run’s raw counts and normalized values with to_h5ad in that environment, which has no anndata, and reads both files back with h5py. On Linux x86_64 the environment installs the tsne extra and the run must also produce finite t-SNE coordinates; on every other platform the environment has no sgtsnepi, and embeddings.tsne must raise the ImportError that names the extra. No smoke environment may have an sgtsne executable on PATH.

Nothing is uploaded when a gate fails, and runs for the same tag publish one at a time. Fix the cause on master, then publish a release whose tag names the fixed commit. Re-running a failed workflow tests the same commit again, which helps only when the failure came from outside the commit, such as a network error.

Run the smoke locally against a wheel you build. It installs the wheel’s dependencies, so it needs network access or a warm uv cache:

uv build --wheel --clear --out-dir dist
uv run --no-project python tests/smoke_wheel.py dist/cytearc-*.whl

Acknowledgements

Contributors

Contributors to the CyteArc repository. Thank you everyone!

Gautam Ahuja, Saatvik Viniak, and Yi Su.

Open-source stack

A diverse number of open-source packages in Python scientific stack are being used to build CyteArc. Here we acknowledge some of them (at least those with pretty logos).

Python, Zarr, NumPy, SciPy, UMAP, scikit-learn, Gensim, pandas, statsmodels, NetworkX, Numba, Matplotlib, seaborn, Jupyter, and Hugging Face.