Contributions are welcome: bug fixes, documentation improvements, tests, and support for new backends. This document describes how to set up your environment and submit changes.
We accept:
- Bug reports and fixes — reproducible issues with clear steps
- Documentation — clarifications, examples, guide updates
- Tests — coverage for new behavior or edge cases
- New backends — adapters for additional tensor-network libraries (see below)
- Small enhancements — focused improvements that fit the existing design
For larger changes, open an issue first to discuss scope and approach.
- Clone and enter the repository:
git clone https://github.com/DOKOS-TAYOS/Tensor-Network-Visualization.git
cd Tensor-Network-Visualization- Create and activate a virtual environment:
python -m venv .venv- Windows:
.\.venv\Scripts\Activate.ps1or.\.venv\Scripts\activate.bat - Linux/macOS:
source .venv/bin/activate
- Install the pinned development requirements:
python -m pip install -r requirements.dev.txtThis installs the pinned local toolchain plus the optional backends required for the full test suite.
All commands below assume the project .venv is active.
From the project root:
pytestWith the project venv (Windows):
.\.venv\Scripts\python -m pytestAdd tests for new features or bug fixes. All tests must pass before opening a PR.
Preferred full verification flow from the project .venv:
.\.venv\Scripts\python scripts\verify.py quality
.\.venv\Scripts\python scripts\verify.py tests
.\.venv\Scripts\python scripts\verify.py smoke
.\.venv\Scripts\python scripts\verify.py packageOn Linux/macOS with the venv activated:
python scripts/verify.py quality
python scripts/verify.py tests
python scripts/verify.py smoke
python scripts/verify.py packagePytest markers are available for the render-specific regression checks:
pytest -m smoke
pytest -m perfUse smoke for lightweight draw sanity checks and perf for runtime-sensitive guards.
For larger local comparisons outside CI, run:
python scripts/bench_render_workflows.pyThat benchmark compares first render vs repeated render, network object vs list input,
and static render vs interactive controls through the public show_tensor_network(...)
entry point.
Automated tests do not open interactive Matplotlib windows. After pytest passes, sanity-check layout and drawing by running the examples below from the repository root (with pip install -r requirements.dev.txt or the matching optional extras). Run one command at a time (each line is a separate invocation).
For a quick batch pass that mirrors the grouped commands below, use the Python runner from the repository root with the project venv:
.\.venv\Scripts\python examples\run_all_examples.py --group default
.\.venv\Scripts\python examples\run_all_examples.py --group contraction
.\.venv\Scripts\python examples\run_all_examples.py --group hover --views 2d
.\.venv\Scripts\python examples\run_all_examples.py --group all --fail-fastOn Linux/macOS, replace the interpreter with python:
python examples/run_all_examples.py --group default
python examples/run_all_examples.py --group contraction
python examples/run_all_examples.py --group hover --views 2d
python examples/run_all_examples.py --group all --fail-fastThat runner saves PNGs under .tmp/run-all-examples/ and appends --save plus
--no-show to every demo call, so the demos automatically disable figure widgets for those
exports. The hover batch group only checks that the CLI flag path still works; for real hover
interaction you still need one of the manual interactive commands below.
For headless runs use --no-show / --save. The public launcher is:
python examples/run_demo.py <engine> <example> [options]Useful flags include --view, --labels-nodes, --labels-edges, --labels,
--hover-labels, --scheme, --playback, --hover-cost,
--from-scratch, and --from-list.
--hover-labels only has a visible effect in a real interactive Matplotlib session (or
%matplotlib widget in Jupyter). --playback and --hover-cost automatically enable scheme
rendering. Install tensor-network-visualization[einsum] (PyTorch) for the einsum demos. See
examples/README.md for the engine/example matrix and copy-paste commands.
Ruff (lint and format):
ruff check .
ruff format .Pyright (type checking):
pyrightConfiguration lives in pyproject.toml (ruff) and pyrightconfig.json (pyright).
One-command verification from the project venv:
Windows:
.\.venv\Scripts\python scripts\verify.pyLinux/macOS (with the venv activated):
python scripts/verify.py- Line length: 100 characters
- Target: Python 3.11+
- Ruff rules: E, F, I, B, UP, C4, SIM
- Typing: Use type hints on public functions and modules; the codebase is
py.typed - Exceptions: prefer
tensor_network_viz.exceptionsclasses at public boundaries instead of rawValueError/ImportErrorwhen you are surfacing user-facing library errors - Logging: use the
tensor_network_vizlogger; never calllogging.basicConfig()from library code
Run python scripts/verify.py before committing. If you prefer, you can still run ruff, pyright, and pytest individually.
When you finish a Python task locally, run:
.\.venv\Scripts\python -m ruff check . --fix
.\.venv\Scripts\python -m ruff format .Use the issue tracker.
Bug reports should include:
- Clear description of what went wrong and what you expected
- Environment: OS, Python version,
pip list(or relevant packages) - Minimal steps or code to reproduce
- Backend used (tensorkrowch, tensornetwork, quimb, tenpy, einsum)
Feature requests should describe the use case and how it fits the existing API.
- Fork the repo and create a branch from
main. - Implement changes following the code style above.
- Run
ruff check .,ruff format .,pyright, andpytestbefore submitting. - Open a PR with a clear title and description.
- Link any related issues.
Keep PRs focused. For larger work, split into smaller PRs or discuss in an issue first.
Adding a new engine (e.g. a new tensor-network library) requires:
- Adapter module under
src/tensor_network_viz/<engine>/:
graph.py— convert backend-native objects to_GraphData(see_core/graph.py)renderer.py— implementplot_<engine>_network_2dandplot_<engine>_network_3dusing the shared_coredrawing layer__init__.py— export the two plot functions
- Registration in
config.py/_engine_specs.py:
- add the new literal to
EngineName - add the module/function triple to
ENGINE_MODULE_MAPinsrc/tensor_network_viz/_engine_specs.py _registry.pyreads that map to resolve the public plotters
- Optional dependency in
pyproject.tomlunder[project.optional-dependencies]. - Tests in
tests/test_integration_<engine>.pyand optionaltests/test_<engine>_backend.py. - Example script in
examples/<engine>_demo.pyand an entry inexamples/README.md.
Open an issue to discuss the backend and its API before implementing.
- README.md — high-level overview, installation, modes,
show_tensor_network/PlotConfig, quick troubleshooting - docs/guide.md — full manual: backends, recipes, layout/draw behavior, architecture, extended troubleshooting
- CHANGELOG.md — user-facing release notes; add an entry when cutting a PyPI release
- examples/ — runnable demos centered on
examples/run_demo.pyplus examples/README.md; update both when adding launcher flags or new engine/example entries - Docstrings — document public functions with Args, Returns, and a short Example where helpful
When you change the public API or defaults, update README.md, docs/guide.md, and any affected examples text so PyPI and the repo stay aligned with _core behavior.
Before opening a pull request, confirm:
ruff check .andruff format .passpyrightpassespytestpassesscripts/verify.py smokepassesscripts/verify.py packagepasses- New code has type hints and tests where appropriate
- Documentation and examples are updated if behavior changed
- PR description explains the change and links related issues