This repo contains my notes and code related to the course Tensor Network.
This is a uv project using Python 3.14 or newer. Setting up the environment is easy:
- If you have not got
uvinstalled, follow the instructions to install it. - Run
uv syncto create an environment and get dependencies, including development dependencies that you need to run the code in a notebook.
The dependencies were refreshed to stable releases on 2026-10-30, including PyTorch 2.15.0, TorchVision 0.29.2, MLX 0.32.4, and nbdev 3.3.27.
Use uv sync --locked --all-extras to reproduce the locked environment, including the optional MLX dependency.
For a deliberate dependency refresh, run uv lock --upgrade followed by uv sync --locked --all-extras.
The resolver retains the transitive dependency mpmath at 1.3.0 because SymPy requires <1.4; its newer stable release is incompatible with that constraint.
We use poe to run tools. Available commands are:
lab: run Jupyter Labsync: export notebook code to thetensor_networkpackage withnbdev-exportformat: format the code in notebooks- Checking: use ruff linter to check code
check_tensor_network: check the exported code intensor_networkpackagecheck: check code in.check_all: check code in.andtensor_network
precommit: run pre-commit hooks
Ruff uses the E4, E7, E9, and F lint rules, with the exceptions configured in pyproject.toml.
Sample usage:
# if your shell detects venvs automatically, you can run poe directly
poe lab
# if your shell does not detect venvs automatically, you can run uv run poe directly
uv run poe labSee the repo on Huggingface.
Contributions are very welcome. Please file an issue or PR if you have any questions or suggestions.
A few points to note:
- The code should primarily live in notebooks, not Python scripts. We use nbdev 3 to export useful code from notebooks to the
tensor_networkpackage for reusability. After editing notebook source, runuv run poe syncto regenerate the Python modules and symbol index. Keep notebook cell IDs, which nbdev uses to map exported code back to its source cells. - Run
pre-commit install, oruv run pre-commit installif your shell doesn't autodetect venv
Project metadata and dependencies live in pyproject.toml, with notebook paths and export settings in [tool.nbdev]. This replaces the legacy settings.ini, setup.py, and MANIFEST.in files. Hatch remains the package build backend.
The package version is defined in tensor_network/__init__.py, which both nbdev and Hatch read. To increment it, run uv run nbdev-bump-version, then uv sync --locked to refresh the installed package metadata. uv tracks the version file when deciding whether to rebuild the package.
- Big thanks to Prof. Ran for the course
- Thanks to Gemini 2.0 and Claude Sonnet for transcribing a lot of equations