Skip to content

Commit 9ba3b6c

Browse files
authored
Refactor test suite (#298)
* setup test framework * setup buildkite * skip AD tests on apple and prerelease * separate tests into groups * update action * properly namespace the `show` tests * fix missing type_repr implementations * attempt to fix compat check * some fixes after merges * slightly larger space to avoid cutting everything * more tweaks * more tweaks * fix tensorkitsectors issue * add compatchecker comment * add code suggestions * better fix of ZNIrrep shenanigans
1 parent ea6bff6 commit 9ba3b6c

File tree

17 files changed

+878
-821
lines changed

17 files changed

+878
-821
lines changed

.github/workflows/CI.yml

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,71 @@
11
name: CI
2+
23
on:
34
push:
45
branches:
5-
- 'master'
66
- 'main'
77
- 'release-'
8+
89
tags: '*'
10+
11+
paths-ignore:
12+
- 'docs/**'
913
pull_request:
1014
workflow_dispatch:
1115

1216
concurrency:
1317
group: ${{ github.workflow }}-${{ github.ref }}
14-
cancel-in-progress: true
18+
# Cancel intermediate builds: only if it is a pull request build.
19+
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
1520

1621
jobs:
1722
test:
18-
name: Julia ${{ matrix.version }} - ${{ matrix.os }}
19-
runs-on: ${{ matrix.os }}
2023
strategy:
2124
fail-fast: false
2225
matrix:
2326
version:
24-
- '1'
2527
- 'lts'
28+
- '1'
29+
group:
30+
- symmetries
31+
- tensors
32+
- other
33+
- autodiff
2634
os:
2735
- ubuntu-latest
2836
- macOS-latest
2937
- windows-latest
30-
steps:
31-
- uses: actions/checkout@v5
32-
- uses: julia-actions/setup-julia@v2
33-
with:
34-
version: ${{ matrix.version }}
35-
- uses: julia-actions/cache@v2
36-
- uses: julia-actions/julia-buildpkg@latest
37-
- uses: julia-actions/julia-runtest@latest
38-
env:
39-
JULIA_NUM_THREADS: 4
40-
- uses: julia-actions/julia-processcoverage@v1
41-
- uses: codecov/codecov-action@v5
42-
env:
43-
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
44-
with:
45-
files: lcov.info
38+
uses: "QuantumKitHub/QuantumKitHubActions/.github/workflows/Tests.yml@main"
39+
with:
40+
group: "${{ matrix.group }}"
41+
julia-version: "${{ matrix.version }}"
42+
os: "${{ matrix.os }}"
43+
nthreads: 4
44+
timeout-minutes: 120
45+
secrets:
46+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
47+
4648
test-nightly:
4749
needs: test
48-
name: Julia nightly - ${{ matrix.os }} - ${{ matrix.arch }}
49-
runs-on: ${{ matrix.os }}
5050
strategy:
5151
matrix:
5252
version:
5353
- 'nightly'
54+
group:
55+
- symmetries
56+
- tensors
57+
- other
58+
- autodiff
5459
os:
5560
- ubuntu-latest
5661
- macOS-latest
5762
- windows-latest
58-
continue-on-error: true
59-
steps:
60-
- uses: actions/checkout@v5
61-
- uses: julia-actions/setup-julia@v2
62-
with:
63-
version: ${{ matrix.version }}
64-
- uses: julia-actions/cache@v2
65-
- uses: julia-actions/julia-buildpkg@latest
66-
- uses: julia-actions/julia-runtest@latest
67-
env:
68-
JULIA_NUM_THREADS: 4
63+
uses: "QuantumKitHub/QuantumKitHubActions/.github/workflows/Tests.yml@main"
64+
with:
65+
group: "${{ matrix.group }}"
66+
julia-version: "${{ matrix.version }}"
67+
os: "${{ matrix.os }}"
68+
nthreads: 4
69+
timeout-minutes: 120
70+
secrets:
71+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

.github/workflows/CompatCheck.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ jobs:
2020
runs-on: ubuntu-latest
2121
strategy:
2222
matrix:
23-
downgrade_mode: ['alldeps']
24-
julia-version: ['1.10', '1']
23+
downgrade_mode: ['deps']
24+
# TODO: this should be ['1.10', '1'] but that is currently broken:
25+
# https://github.com/julia-actions/julia-downgrade-compat/issues/25
26+
julia-version: ['1.10', '1.12']
2527
steps:
2628
- uses: actions/checkout@v5
2729
- uses: julia-actions/setup-julia@v2
@@ -31,5 +33,6 @@ jobs:
3133
with:
3234
mode: ${{ matrix.downgrade_mode }}
3335
skip: Random, LinearAlgebra, Test, Combinatorics
36+
julia_version: ${{ matrix.julia-version }}
3437
- uses: julia-actions/julia-buildpkg@v1
3538
- uses: julia-actions/julia-runtest@v1

Project.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ TensorKitFiniteDifferencesExt = "FiniteDifferences"
2727

2828
[compat]
2929
Aqua = "0.6, 0.7, 0.8"
30+
ArgParse = "1.2.0"
3031
ChainRulesCore = "1"
3132
ChainRulesTestUtils = "1"
3233
Combinatorics = "1"
@@ -37,9 +38,10 @@ MatrixAlgebraKit = "0.5.0"
3738
OhMyThreads = "0.8.0"
3839
PackageExtensionCompat = "1"
3940
Random = "1"
41+
SafeTestsets = "0.1"
4042
ScopedValues = "1.3.0"
4143
Strided = "2"
42-
TensorKitSectors = "0.3"
44+
TensorKitSectors = "=0.3.0, 0.3.2"
4345
TensorOperations = "5.1"
4446
Test = "1"
4547
TestExtras = "0.2,0.3"
@@ -49,16 +51,18 @@ Zygote = "0.7"
4951
julia = "1.10"
5052

5153
[extras]
54+
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
5255
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
5356
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
5457
ChainRulesTestUtils = "cdddcdb0-9152-4a09-a978-84456f9df70a"
5558
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
5659
FiniteDifferences = "26cc04aa-876d-5657-8c51-4c34ba976000"
5760
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
61+
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
5862
TensorOperations = "6aa20fa7-93e2-5fca-9bc0-fbd0db3c71a2"
5963
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
6064
TestExtras = "5ed8adda-3752-4e41-b88a-e8b09835ee3a"
6165
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
6266

6367
[targets]
64-
test = ["Aqua", "Combinatorics", "LinearAlgebra", "TensorOperations", "Test", "TestExtras", "ChainRulesCore", "ChainRulesTestUtils", "FiniteDifferences", "Zygote"]
68+
test = ["ArgParse", "Aqua", "Combinatorics", "LinearAlgebra", "TensorOperations", "Test", "TestExtras", "SafeTestsets", "ChainRulesCore", "ChainRulesTestUtils", "FiniteDifferences", "Zygote"]

test/ad.jl renamed to test/autodiff/ad.jl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
using Test, TestExtras
2+
using TensorKit
3+
using TensorKit: type_repr, SectorDict
4+
using TensorOperations
15
using ChainRulesCore
26
using ChainRulesTestUtils
37
using FiniteDifferences: FiniteDifferences, central_fdm, forward_fdm
@@ -33,7 +37,7 @@ function ChainRulesTestUtils.test_approx(
3337
end
3438

3539
# make sure that norms are computed correctly:
36-
function FiniteDifferences.to_vec(t::TK.SectorDict)
40+
function FiniteDifferences.to_vec(t::SectorDict)
3741
T = scalartype(valtype(t))
3842
vec = mapreduce(vcat, t; init = T[]) do (c, b)
3943
return reshape(b, :) .* sqrt(dim(c))
@@ -43,7 +47,7 @@ function FiniteDifferences.to_vec(t::TK.SectorDict)
4347
function from_vec(x_real)
4448
x = T <: Real ? x_real : reinterpret(T, x_real)
4549
ctr = 0
46-
return TK.SectorDict(
50+
return SectorDict(
4751
c => (
4852
n = length(b);
4953
b′ = reshape(view(x, ctr .+ (1:n)), size(b)) ./ sqrt(dim(c));
@@ -187,7 +191,7 @@ spacelist = (
187191
Vect[SU2Irrep](0 => 1, 1 // 2 => 1, 3 // 2 => 1)',
188192
),
189193
(
190-
Vect[FibonacciAnyon](:I => 1, => 1),
194+
Vect[FibonacciAnyon](:I => 2, => 1),
191195
Vect[FibonacciAnyon](:I => 1, => 2)',
192196
Vect[FibonacciAnyon](:I => 2, => 2)',
193197
Vect[FibonacciAnyon](:I => 2, => 3),
@@ -197,7 +201,7 @@ spacelist = (
197201

198202
for V in spacelist
199203
I = sectortype(eltype(V))
200-
Istr = TK.type_repr(I)
204+
Istr = type_repr(I)
201205
eltypes = isreal(sectortype(eltype(V))) ? (Float64, ComplexF64) : (ComplexF64,)
202206
symmetricbraiding = BraidingStyle(sectortype(eltype(V))) isa SymmetricBraiding
203207
println("---------------------------------------")
@@ -593,7 +597,7 @@ for V in spacelist
593597
# TODO: I'm not sure how to properly test with spaces that might change
594598
# with the finite-difference methods, as then the jacobian is ill-defined.
595599

596-
trunc = truncrank(round(Int, min(dim(domain(t)), dim(codomain(t))) ÷ 2))
600+
trunc = truncrank(max(2, round(Int, min(dim(domain(t)), dim(codomain(t))) * (3 / 4))))
597601
USVᴴ_trunc = svd_trunc(t; trunc)
598602
ΔUSVᴴ_trunc = rand_tangent.(USVᴴ_trunc)
599603
remove_svdgauge_dependence!(

test/braidingtensor.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# TODO: Make into proper tests and integrate in testset
2+
# note: this is not part of the testsuite!
23

34
import TensorKit: BraidingTensor
45

test/bugfixes.jl

Lines changed: 0 additions & 83 deletions
This file was deleted.

test/other/aqua.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
using TensorKit
2+
using Aqua
3+
4+
Aqua.test_all(TensorKit)

0 commit comments

Comments
 (0)