Skip to content

Architecture

How the repository is organized, how dependencies flow, and the rules for components and reproductions. Scope is in vision.md; decision rights are in autonomy.md.

Layers and Dependency Direction

reproductions/<YYYY>_<keywords>/   paper-specific models, parameters, and plots
          |
tencirlab/                         reusable components
          |
TensorCircuit-NG (nightly), TensorNetwork-NG, TenCirPauli, JAX, Optax, ...
  • Imports only go downward. A component never imports from reproductions/; one reproduction never imports from another.
  • Only public APIs of TensorCircuit-NG, TensorNetwork-NG, and TenCirPauli are used: no private names, monkey-patching, or vendored copies.
  • An upstream bug or gap is worked around in one place in tencirlab/, with a link to the upstream issue or pull request, and the workaround is removed once the fix lands in the nightly build.

Repository Layout

README.md  AGENTS.md  CLAUDE.md  LICENSE  NOTICE  pyproject.toml
tencirlab/            the package
reproductions/        one folder per paper, plus README.md and taxonomy.yaml
tests/                component tests
scripts/              metadata check, reproduction runner, website generator
docs/                 vision, autonomy, architecture, records/, and site/ (website configuration)
.agents/skills/       agent workflows
.agents/memory/       durable lessons, indexed by .agents/memory/index.md
.github/              CONTRIBUTING.md, issue and pull request templates, workflows

The root stays small. Documents go under docs/, grouped by purpose; working notes that are not part of the repository stay out of Git.

Package Structure

The internal structure of tencirlab/ is not fixed in advance. It grows with the reproductions and is reorganized whenever a better structure becomes clear; topics overlap, and the layout should follow how the code is actually reused rather than a predefined taxonomy. Agents decide the structure and record significant reorganizations as decisions in records/.

Components

Interface

  • Design each component as the natural, general interface for its concept, consistent with similar interfaces here and in TensorCircuit-NG. It does not need to be trimmed to exactly what the current reproduction uses: options that obviously belong to the concept are fine even if nothing uses them yet. What is not fine is speculative machinery — extra layers, plug-in systems, or configuration for needs nobody has.
  • Components are plain functions and small classes or dataclasses that work as JAX pytrees where they carry arrays. Randomness is passed explicitly as jax.random keys.
  • Library code does not change global state such as tc.set_backend, tc.set_dtype, or JAX's x64 flag. Reproductions set these at the top of the script.
  • Public functions have a docstring stating the conventions that are not obvious (shapes, ordering, normalization) and the reference for the method.
  • No input validation or defensive branches beyond what the main path needs. Let wrong input fail naturally.

Performance

Components are written to be fast, since mature ones should be able to graduate into TensorCircuit-NG or a library of their own:

  • JAX only. Use jax.numpy and JAX transformations directly.
  • Static shapes inside compiled code; dynamic content uses masks rather than data-dependent shapes or in-place mutation.
  • Value-dependent control flow uses jax.lax; loops over steps or layers use scan where compile time matters.
  • Kernels called repeatedly are defined at module level and compiled once.
  • Batch with vmap; use scan or chunking when vmap would materialize too much.
  • Prebuild static structures such as contraction paths and operators outside compiled and differentiated functions.
  • Device-agnostic code with no device branches. Follow TensorCircuit-NG's known GPU practice, for example the QR-based SVD for complex matrices on GPU and disabling TF32 when complex64 results matter.
  • Optimize where it pays: a clear gain on a common path is worth some complexity; a marginal gain or a rare path is not.

Tests

A component comes with a small correctness test against an exact or independent reference on its main path, plus a gradient check if it is meant to be differentiated. No tests for corner cases the main path does not hit.

Change and Removal

  • No compatibility shims. A pull request that changes a component updates every caller.
  • Remove code that is superseded or abandoned: an old interface replaced by a better one, a component whose purpose moved elsewhere, a workaround whose upstream fix has landed.
  • Do not remove an option or function merely because nothing calls it right now if it is a coherent part of a general interface.
  • Merge components that do the same job.

Reproductions

Scales

Every reproduction can run at several sizes, selected on the command line:

python main.py                 # default: the scale used for the published figure
python main.py --scale test    # small: seconds to about a minute on CPU, used by CI
python main.py --scale paper   # optional: the paper's full scale when it differs from default

The design targets the paper's scale whatever scale is run; see Paper Scale.

  • The scales are defined in one module-level dictionary SCALES at the top of main.py; each entry only sets parameters such as system size, sample counts, and steps. The code path is the same at every scale.
  • default produces the figures in outputs/. Other scales write to a directory given by --out (CI uses a temporary directory), so a test run never overwrites the published figures.
  • The test scale must exercise the full pipeline, including compilation, and finish in about a minute on a CI CPU.
  • meta.yaml declares the runtime and hardware of each scale.

Checks

verify.py is optional. Add it when there is an independent check worth keeping, such as comparison with exact diagonalization, a conservation law, or a number from the paper. It runs on CPU in about a minute.

Size Budget

  • Counted lines: all .py files in a reproduction folder except verify.py, excluding blank lines, comments, and docstrings.
  • Target 150 lines, limit 300. Above the limit, meta.yaml must give a budget_note explaining why the rest cannot be a component.
  • These numbers are provisional and will be recalibrated from the observed distribution.

Dependencies

  • Required: tensorcircuit-nightly (built daily from TensorCircuit-NG's master), tensornetwork-ng, tencirpauli, jax, numpy, scipy, matplotlib. tencirpauli is installed with --no-deps, since its dependency tensorcircuit-ng would replace tensorcircuit-nightly; the two never share an environment.
  • Others are added when merged code needs them, under a permissive license, with a decision record. Frameworks that overlap the component layer itself, such as full neural-quantum-state or tensor-network packages, are avoided unless a decision record argues otherwise.
  • The project's own version is not released to PyPI; installation is from Git.

CI

Job Trigger Runs
ci every pull request and push to main black --check, pylint, pytest tests/, metadata check, size budget, and at --scale test every reproduction that imports a changed module (all of them when shared code changes broadly), with its verify.py
nightly schedule every reproduction at --scale test and every verify.py, against that day's tensorcircuit-nightly; opens an issue on failure
site every pull request (build only) and push to main build the website with --strict; publish it on push to main
full rerun weekly, on a maintainer GPU machine, from main only every reproduction at default scale, compared against the stored numerical outputs

No job runs code from forks on maintainer machines or self-hosted runners.

Website

The website, tensorcircuit.github.io/TenCirLab, is generated from the repository and published with GitHub Pages:

  • Gallery of reproductions on the home page, filterable by topic, upstream feature, component, and status.
  • One page per reproduction: the reproduced figures, the setup (model, method, computed quantity), agreement and simplifications, the paper-scale estimate, scales and runtimes, components and upstream features used, the reproduction's README.md, the code, and its history of change records. The paper's own figures are linked through the paper rather than embedded; one is embedded only when the paper's license allows it, such as CC BY.
  • Component reference generated from docstrings, with the reproductions using each component and its history.
  • Records: decisions, change records, and the weekly journal, each linked to its pull request and to the reproductions it touched.
  • About: the project documents (docs/, reproductions/README.md, AGENTS.md, contributing).
  • Trends (number of reproductions, reproduction size, and component reuse over time) are added once there is a history worth plotting.

It uses MkDocs Material, as TenCirPauli does, with mkdocstrings for the component reference and a little JavaScript for the gallery filters. Every page is generated at build time by the MkDocs hook scripts/website.py from meta.yaml, taxonomy.yaml, the reproduction folders, tencirlab/, and docs/; the configuration, home-page text, and styles are in docs/site/. Nothing generated is stored in Git, so a merged reproduction appears on the site without further work. The text fields of meta.yaml are rendered as Markdown. To preview:

pip install -r docs/site/requirements.txt
mkdocs serve -f docs/site/mkdocs.yml