Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
5 changes: 3 additions & 2 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

### Python Instructions

- Write code to support Python 3.11, 3.12, 3.13.
- Write code to support Python 3.12, 3.13, 3.14.
- Write clear and concise comments for each function.
- Ensure functions have descriptive names and include type hints.
- Provide docstrings following PEP 257 conventions.
Expand Down Expand Up @@ -54,7 +54,8 @@ def calculate_area(radius: float) -> float:
The area of the circle, calculated as π * radius^2.
"""
import math
return math.pi * radius ** 2

return math.pi * radius**2
```

## Development Commands
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/copilot-setup-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
python-version: "3.11"
python-version: "3.14"

- name: Install package
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docpages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
python-version: "3.11"
python-version: "3.14"

- name: Install package
run: |
Expand Down
12 changes: 8 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ jobs:
- ubuntu-latest
- gpu-runner
python-version:
- "3.11"
- "3.13"
- "3.12"
- "3.14"
test-group:
- "not slow and not perf"

Expand Down Expand Up @@ -129,7 +129,9 @@ jobs:
retention-days: 1

benchmark:
# Will fail if an slowdown in the median of more than 10% is detected
# Fails on a median slowdown of more than 25%. The threshold is wide
# because this runs on a shared runner, where no-op PRs have drifted by
# up to 20%; anything tighter reports noise as a regression.
name: 'Run Benchmark Comparison'
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
Expand All @@ -148,6 +150,8 @@ jobs:
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
# This job builds both the base and the PR checkout, so the version
# must satisfy `requires-python` on both sides of the comparison.
python-version: "3.13"

- name: 'Install dependencies'
Expand Down Expand Up @@ -185,7 +189,7 @@ jobs:
-W ignore::pytest_benchmark.logger.PytestBenchmarkWarning \
--log-cli-level=WARNING \
--benchmark-storage=file://baseline-benchmarks \
--benchmark-compare-fail=median:10% \
--benchmark-compare-fail=median:25% \
--benchmark-compare=0001

publish-test-results:
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,9 @@ Thumbs.db
*~
*.swp

### Nix ###
result
result-*
.direnv/

sandbox/**
5 changes: 3 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ repos:
- id: trailing-whitespace
exclude: '\.out$'

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.12.11
- repo: https://github.com/astral-sh/ruff-pre-commit
# Keep in sync with the ruff pin in pyproject.toml; update-ruff.yml bumps both.
rev: v0.16.5
hooks:
- id: ruff
exclude: '\.out$|^benches/'
Expand Down
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.11
3.14
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ accuracy, not just the shapes.

## Code style

The project targets Python 3.11+ and is checked with `ruff` under a strict rule
The project targets Python 3.12+ and is checked with `ruff` under a strict rule
set. Public functions carry type hints and Google-style docstrings without type
annotations in the argument list. Keep lines within the configured limit and
prefer clear code over clever code.
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Test src_method](https://github.com/Algorithmiq/src-method/actions/workflows/test.yml/badge.svg)](https://github.com/Algorithmiq/src-method/actions/workflows/test.yml)
[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](LICENSE)

An implementation of the SRC algorithm introduced in [Camaño, Epperly and Tropp, *Quantum* **10**, 2022 (2026)](https://doi.org/10.22331/q-2026-03-10-2022) ([arXiv:2504.06475](https://arxiv.org/abs/2504.06475)), extending the idea to other kinds of tensor networks.
An implementation of the SRC algorithm introduced in [Camaño, Epperly and Tropp, *Quantum* **10**, 2022 (2026)](https://doi.org/10.22331/q-2026-03-10-2022), extending the idea to other kinds of tensor networks.

### Features

Expand Down Expand Up @@ -116,6 +116,33 @@ process is done, you will have _all_ project dependencies installed, including
> DevContainer is non-deterministic. You might have to execute the *Reload Window*
> command to get everything to work as expected after a fresh build of the container.

### Alternative: Nix flake

If you prefer [Nix] over Docker, the repository ships a `flake.nix` that provides
a development shell with [uv], [Git] and the [GitHub CLI], plus the native
libraries the binary wheels need at runtime. Python itself and all project
dependencies remain managed by `uv`.

With [flakes enabled](https://nixos.wiki/wiki/Flakes#Enable_flakes_temporarily), run:

```bash
nix develop
```

Entering the shell runs `uv sync --all-groups` and activates the uv project
environment (`$UV_PROJECT_ENVIRONMENT` if set, otherwise `.venv`), so you land
in a ready-to-use environment. GPU extras are not installed by the flake: add them
explicitly with `uv sync --all-groups --extra gpu-nvidia` (or `--all-groups --extra gpu-rocm`) on a machine with the matching drivers.

If you use [direnv], the provided `.envrc` enters the shell automatically:
Comment thread
Panadestein marked this conversation as resolved.

```bash
direnv allow
```

Unlike the DevContainer, the Nix shell does not install the `pre-commit` hooks for
you. Run `pre-commit install --install-hooks` once after the first `nix develop`.

## Documentation

We use [MkDocs] to generate our documentation pages. You can find the latest version [at this link].
Expand All @@ -135,5 +162,9 @@ the editor will prompt you to open a new page in your browser, where you can see
[Docker]: https://docs.docker.com/get-docker/
[Visual Studio Code]: https://code.visualstudio.com/
[GitHub CLI]: https://cli.github.com/
[Git]: https://git-scm.com/
[Nix]: https://nixos.org/download/
[direnv]: https://direnv.net/
[uv]: https://docs.astral.sh/uv/
[MkDocs]: https://www.mkdocs.org/
[at this link]: https://docs.algorithmiq.fi/src_method
7 changes: 6 additions & 1 deletion cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
"devcontainers",
"diag",
"diagflat",
"direnv",
"dlopen",
"eigenpairs",
"eigenprojected",
"eigenprojection",
Expand Down Expand Up @@ -60,6 +62,8 @@
"ndarray",
"nditer",
"newaxis",
"nixfmt",
"nixpkgs",
"np",
"numba",
"numpy",
Expand Down Expand Up @@ -122,5 +126,6 @@
"sparray",
"spsolve",
"todense",
"triu",
"triu"
]
}
27 changes: 27 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
description = "src_method: Successive Randomized Compression";

inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";

outputs =
{ self, nixpkgs }:
let
# x86_64-darwin is not supported by nixpkgs-unstable since 26.11.
systems = [
"x86_64-linux"
"aarch64-linux"
"aarch64-darwin"
];
forEachSystem = f: nixpkgs.lib.genAttrs systems (system: f nixpkgs.legacyPackages.${system});
in
{
devShells = forEachSystem (pkgs: {
default = pkgs.mkShell {
packages = [
pkgs.uv
pkgs.git
pkgs.gh
];

env = {
# Python itself and all project dependencies stay under uv's control,
# so the flake only has to provide uv and the native libraries that
# binary wheels (numpy, quimb, cupy, ...) dlopen at runtime.
UV_PYTHON_DOWNLOADS = "automatic";
}
// pkgs.lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux {
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
pkgs.stdenv.cc.cc.lib
pkgs.zlib
];
};

# GPU extras are deliberately not synced: they are CUDA/ROCm specific.
shellHook = ''
uv sync --all-groups
# Activate by hand: .venv/bin/activate hardcodes paths that break
# when the checkout is shared, and uv may place the venv elsewhere.
export VIRTUAL_ENV="''${UV_PROJECT_ENVIRONMENT:-$PWD/.venv}"
export PATH="$VIRTUAL_ENV/bin:$PATH"
'';
};
});

formatter = forEachSystem (pkgs: pkgs.nixfmt);
};
}
9 changes: 5 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ description = "Successive Randomized Compression."
readme = "README.md"
license = "Apache-2.0"
license-files = ["LICENSE", "NOTICE"]
requires-python = ">=3.11,<3.14"
requires-python = ">=3.12,<3.15"
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Science/Research",
Expand All @@ -21,9 +21,9 @@ classifiers = [
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
"Topic :: Scientific/Engineering :: Chemistry",
"Topic :: Scientific/Engineering :: Physics",
"Topic :: Scientific/Engineering",
Expand Down Expand Up @@ -158,7 +158,8 @@ exclude_also = [

exclude = ["docs", "src/src_method/_version.py"]

target-version = "py311"
# Lint against the oldest supported interpreter, not the default one.
target-version = "py312"

[tool.ruff.format]
# enable auto-formatting of code examples in docstrings
Expand Down Expand Up @@ -272,7 +273,7 @@ required-imports = ["from __future__ import annotations"]


[tool.pyright]
pythonVersion = "3.11"
pythonVersion = "3.12"

include = ["src/src_method/**/*.py"]

Expand Down
9 changes: 7 additions & 2 deletions tests/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def random_mpo(
*,
phys: int = 2,
dtype: type = np.complex128,
rng: np.random.Generator = np.random.default_rng(),
rng: np.random.Generator | None = None,
) -> qtn.MatrixProductOperator:
"""Generate a random MPO with given bond dimensions and physical dimension.

Expand All @@ -48,11 +48,16 @@ def random_mpo(
bonds: List of bond dimensions for the MPO. The last site is implicit.
phys: Physical dimension. Defaults to 2.
dtype: Data type of the tensors. Defaults to np.complex128.
rng: Random number generator. Defaults to np.random.default_rng().
rng: Random number generator. Defaults to a fresh unseeded generator.

Returns:
qtn.MatrixProductOperator: The generated random MPO.
"""
# A default generator built here rather than in the signature: a default
# argument is evaluated once, so callers would share generator state.
if rng is None:
rng = np.random.default_rng()

# First site
tensors = [rng.normal(size=(bonds[0], phys, phys)).astype(dtype)]

Expand Down
Loading
Loading