Skip to content
Draft
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
143 changes: 105 additions & 38 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
paths-ignore:
- 'docs/**'
pull_request:
types: [opened, synchronize, reopened, ready_for_review, converted_to_draft]
workflow_dispatch:

concurrency:
Expand All @@ -19,55 +20,121 @@ concurrency:
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}

jobs:
setup-matrix:
runs-on: ubuntu-latest
outputs:
groups: ${{ steps.mk.outputs.groups }}
version: ${{ steps.mk.outputs.version }}
os: ${{ steps.mk.outputs.os }}
steps:
- uses: actions/checkout@v6
- id: mk
shell: bash
run: |
# Auto-discover test groups from all subdirectory names.
groups=$(find test -mindepth 1 -maxdepth 1 -type d \
| xargs -I{} basename {} | sort \
| jq -R -s -c '[split("\n")[] | select(length > 0)]')

echo "groups=${groups}" >> "$GITHUB_OUTPUT"

# Draft PR: only run ubuntu-latest + version=1
if [[ "${{ github.event_name }}" == "pull_request" && "${{ github.event.pull_request.draft }}" == "true" ]]; then
echo 'version=["1"]' >> "$GITHUB_OUTPUT"
echo 'os=["ubuntu-latest"]' >> "$GITHUB_OUTPUT"
else
echo 'version=["lts","1"]' >> "$GITHUB_OUTPUT"
echo 'os=["ubuntu-latest","macOS-latest","windows-latest"]' >> "$GITHUB_OUTPUT"
fi

test:
name: "Tests"
needs: setup-matrix
strategy:
fail-fast: false
matrix:
version:
- 'lts'
- '1'
group:
- symmetries
- tensors
- other
- mooncake
- chainrules
os:
- ubuntu-latest
- macOS-latest
- windows-latest
uses: "QuantumKitHub/QuantumKitHubActions/.github/workflows/Tests.yml@main"
with:
group: "${{ matrix.group }}"
julia-version: "${{ matrix.version }}"
os: "${{ matrix.os }}"
nthreads: 4
timeout-minutes: 120
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
version: ${{ fromJSON(needs.setup-matrix.outputs.version) }}
os: ${{ fromJSON(needs.setup-matrix.outputs.os) }}
group: ${{ fromJSON(needs.setup-matrix.outputs.groups) }}
runs-on: ${{ matrix.os }}
timeout-minutes: 120
steps:
- uses: actions/checkout@v6
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.version }}
- uses: julia-actions/cache@v2
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
with:
test_args: '${{ matrix.group }}${{ github.event.pull_request.draft == true && '' --fast'' || '''' }}'
env:
JULIA_NUM_THREADS: "4"
- uses: julia-actions/julia-processcoverage@v1
with:
directories: 'src,ext'
- uses: codecov/codecov-action@v5
with:
files: lcov.info
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: false

test-nightly:
needs: test
name: "Tests (nightly)"
needs: [setup-matrix, test]
if: github.event.pull_request.draft != true
strategy:
fail-fast: false
matrix:
version:
- 'nightly'
group:
- symmetries
- tensors
- other
- mooncake
- chainrules
group: ${{ fromJSON(needs.setup-matrix.outputs.groups) }}
os:
- ubuntu-latest
- macOS-latest
- windows-latest
uses: "QuantumKitHub/QuantumKitHubActions/.github/workflows/Tests.yml@main"
with:
group: "${{ matrix.group }}"
julia-version: "${{ matrix.version }}"
os: "${{ matrix.os }}"
nthreads: 4
timeout-minutes: 120
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
runs-on: ${{ matrix.os }}
timeout-minutes: 120
steps:
- uses: actions/checkout@v6
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.version }}
- uses: julia-actions/cache@v2
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
with:
test_args: '${{ matrix.group }}'
continue-on-error: true
- uses: julia-actions/julia-processcoverage@v1
with:
directories: 'src,ext'
- uses: codecov/codecov-action@v5
with:
files: lcov.info
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: false

compatcheck:
name: "Compat check - ${{ matrix.julia-version }}"
needs: [setup-matrix, test]
if: github.event.pull_request.draft != true
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
downgrade_mode: ['deps']
group: ${{ fromJSON(needs.setup-matrix.outputs.groups) }}
julia-version: ['1.10', '1']
steps:
- uses: actions/checkout@v6
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.julia-version }}
- uses: julia-actions/julia-downgrade-compat@v2
with:
mode: ${{ matrix.downgrade_mode }}
skip: Random, LinearAlgebra, Test, Combinatorics
julia_version: ${{ matrix.julia-version }}
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
38 changes: 0 additions & 38 deletions .github/workflows/CompatCheck.yml

This file was deleted.

37 changes: 3 additions & 34 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,58 +32,27 @@ TensorKitChainRulesCoreExt = "ChainRulesCore"
TensorKitFiniteDifferencesExt = "FiniteDifferences"
TensorKitMooncakeExt = "Mooncake"

[workspace]
projects = ["test"]

[compat]
Adapt = "4"
AllocCheck = "0.2.3"
Aqua = "0.6, 0.7, 0.8"
ArgParse = "1.2.0"
CUDA = "5.9"
ChainRulesCore = "1"
ChainRulesTestUtils = "1"
Combinatorics = "1"
FiniteDifferences = "0.12"
GPUArrays = "11.3.1"
JET = "0.9, 0.10, 0.11"
LRUCache = "1.0.2"
LinearAlgebra = "1"
MatrixAlgebraKit = "0.6.5"
Mooncake = "0.5"
OhMyThreads = "0.8.0"
Printf = "1"
Random = "1"
SafeTestsets = "0.1"
ScopedValues = "1.3.0"
Strided = "2"
TensorKitSectors = "0.3.6"
TensorOperations = "5.1"
Test = "1"
TestExtras = "0.2,0.3"
TupleTools = "1.5"
VectorInterface = "0.4.8, 0.5"
Zygote = "0.7"
cuTENSOR = "2"
julia = "1.10"

[extras]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
AllocCheck = "9b6a8646-10ed-4001-bbdc-1d2f46dfbb1a"
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
ChainRulesTestUtils = "cdddcdb0-9152-4a09-a978-84456f9df70a"
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
FiniteDifferences = "26cc04aa-876d-5657-8c51-4c34ba976000"
GPUArrays = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7"
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Mooncake = "da2b9cff-9c12-43a0-ae48-6db2b0edb7d6"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
TensorOperations = "6aa20fa7-93e2-5fca-9bc0-fbd0db3c71a2"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TestExtras = "5ed8adda-3752-4e41-b88a-e8b09835ee3a"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
cuTENSOR = "011b41b2-24ef-40a8-b3eb-fa098493e9e1"

[targets]
test = ["ArgParse", "Adapt", "Aqua", "AllocCheck", "Combinatorics", "CUDA", "cuTENSOR", "GPUArrays", "JET", "LinearAlgebra", "SafeTestsets", "TensorOperations", "Test", "TestExtras", "ChainRulesCore", "ChainRulesTestUtils", "FiniteDifferences", "Zygote", "Mooncake"]
40 changes: 40 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name = "TensorKitTests"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
ChainRulesTestUtils = "cdddcdb0-9152-4a09-a978-84456f9df70a"
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
FiniteDifferences = "26cc04aa-876d-5657-8c51-4c34ba976000"
GPUArrays = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7"
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MatrixAlgebraKit = "6c742aac-3347-4629-af66-fc926824e5e4"
Mooncake = "da2b9cff-9c12-43a0-ae48-6db2b0edb7d6"
ParallelTestRunner = "d3525ed8-44d0-4b2c-a655-542cee43accc"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
TensorKit = "07d1fe3e-3e46-537d-9eac-e9e13d0d4cec"
TensorKitSectors = "13a9c161-d5da-41f0-bcbd-e1a08ae0647f"
TensorOperations = "6aa20fa7-93e2-5fca-9bc0-fbd0db3c71a2"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TestExtras = "5ed8adda-3752-4e41-b88a-e8b09835ee3a"
TupleTools = "9d95972d-f1c8-5527-a6e0-b4b365fa01f6"
VectorInterface = "409d34a3-91d5-4945-b6ec-7529ddf182d8"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
cuTENSOR = "011b41b2-24ef-40a8-b3eb-fa098493e9e1"

[compat]
Aqua = "0.6, 0.7, 0.8"
ChainRulesTestUtils = "1"
Combinatorics = "1"
GPUArrays = "11.3.1"
JET = "0.9, 0.10, 0.11"
ParallelTestRunner = "2"
Test = "1"
TestExtras = "0.2,0.3"
Zygote = "0.7"

[sources]
TensorKit = {path = ".."}
81 changes: 81 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# TensorKit.jl test suite

Tests use [ParallelTestRunner.jl](https://github.com/vchuravy/ParallelTestRunner.jl) for parallel
execution. Each test file runs in its own worker process. Shared helpers are loaded automatically
via `init_code` — test files do not need to include `setup.jl` themselves.

## Running tests

```julia
# Standard — works on all supported Julia versions
using Pkg; Pkg.test()
```

```bash
# Direct invocation — requires Julia 1.12+ (workspace support)
julia --project=test test/runtests.jl

# Run only a specific group (directory prefix)
julia --project=test test/runtests.jl symmetries

# Run only a specific file
julia --project=test test/runtests.jl tensors/factorizations

# Fast mode: fewer sectors, fewer scalar types, AD tests skipped
julia --project=test test/runtests.jl --fast

# Combine --fast with a group or file filter
julia --project=test test/runtests.jl --fast tensors

# Control parallelism
julia --project=test test/runtests.jl --jobs=4
```

## Test groups

| Group | Contents |
|-------|----------|
| `symmetries` | Spaces and fusion trees |
| `tensors` | Core tensor operations, factorizations, planar tensors, diagonal tensors |
| `other` | Aqua code-quality checks, bug-fix regressions |
| `chainrules` | ChainRulesCore AD tests |
| `mooncake` | Mooncake AD tests |
| `cuda` | CUDA GPU tests (only run when a functional GPU is present) |

## Fast mode (`--fast`)

Skips `chainrules` and `mooncake` groups entirely, and reduces coverage in the remaining tests:

- **Sector types**: tests only `Z2Irrep`, `SU2Irrep`, `FermionParity ⊠ U1Irrep ⊠ SU2Irrep`,
and `FibonacciAnyon` (instead of the full `sectorlist`)
- **Space lists**: tests only `(Vtr, Vℤ₂, VSU₂)` (trivial, abelian, non-abelian)
- **Scalar types**: tests only `Float64` and `ComplexF64` (instead of all integer/float variants)

## `setup.jl`

Defines the `TestSetup` module, which is loaded into every worker sandbox automatically. It
exports:

- **Spaces**: `Vtr`, `Vℤ₂`, `Vfℤ₂`, `Vℤ₃`, `VU₁`, `VfU₁`, `VCU₁`, `VSU₂`, `VfSU₂`,
`VSU₂U₁`, `Vfib`, `VIB_diag`, `VIB_M`
- **Sector lists**: `sectorlist` (full), `fast_sectorlist` (reduced)
- **Utilities**: `randsector`, `smallset`, `hasfusiontensor`, `force_planar`, `random_fusion`,
`randindextuple`, `randcircshift`, `_repartition`, `trivtuple`, `test_dim_isapprox`, `default_tol`

The `fast_tests::Bool` constant is also available in every test file (injected alongside
`TestSetup` via `init_code` in `runtests.jl`).

## Adding a new test file

Create a `.jl` file anywhere under `test/`. It is auto-discovered by `ParallelTestRunner` and
must be self-contained (worker processes have no shared state). `TestSetup` and `fast_tests` are
already in scope — no include needed.

```julia
using Test, TestExtras
using TensorKit

@testset "My tests" begin
# fast_tests and all TestSetup exports (Vtr, sectorlist, …) are available here
end
```
Loading
Loading