Skip to content

Commit ec7af8f

Browse files
lkdvoskshyattJuthoborisdevosKatharine Hyatt
authored
Overhaul test infrastructure (#389)
* update testing infrastructure and Project.toml * simplify testcode include * update CI instructions * add fast testing * add a readme file * small fixes * run fast tests in draft mode * rework some test infrastructure again * small changes to avoid accidental diagonal tensors * split up chainrules tests * split up factorization tests * split up tensor tests * split up fusiontree tests * more shared code in the setup * fix Mooncake test * fix version of downgrade-compat * remove unneeded exports * simplify chainrules testsets * simplify mooncake testsets * update all versions of actions [skip ci] * only test compat on latest version * incorporate code suggestions * remove `_project_hermitian` * final tweaks to testsetup * properly filter cuda tests * small fixes for CUDA * Fix CUDA tests for IsingBimodule * whole lotta change * changes, turn and face the strange * cuda concistency revival * Try to help out CUDA a bit * Reduce size of tensor for norm-preservation test * Use mul-supporting Strided * Formatter * reduce tensor product and deligne product tensor sizes * remove outdated assert * Clearer print statements in tests * `_artin_braid_local` for uniquefusion case * Some CUDA fixes * Death to sources * further finetune/reduce spaces * more space tweaking * small fix in rank tests * Revert "`_artin_braid_local` for uniquefusion case" This reverts commit bf7a376. * revert braiding_manipulations changes * fix factorization test spaces and tolerances * fix formatting * separate out CompatCheck * disable nightly test --------- Co-authored-by: Katharine Hyatt <khyatt@flatironinstitute.org> Co-authored-by: Jutho Haegeman <jutho.haegeman@ugent.be> Co-authored-by: Boris De Vos <boris.devos@ugent.be> Co-authored-by: Katharine Hyatt <katharine.s.hyatt@gmail.com>
1 parent 393d6ff commit ec7af8f

40 files changed

Lines changed: 3164 additions & 3320 deletions

.buildkite/pipeline.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ steps:
1515
queue: "juliagpu"
1616
cuda: "*"
1717
if: build.message !~ /\[skip tests\]/
18-
timeout_in_minutes: 60
18+
timeout_in_minutes: 90
1919
matrix:
2020
setup:
2121
julia:
@@ -36,7 +36,7 @@ steps:
3636
rocm: "*"
3737
rocmgpu: "*"
3838
if: build.message !~ /\[skip tests\]/
39-
timeout_in_minutes: 60
39+
timeout_in_minutes: 90
4040
matrix:
4141
setup:
4242
julia:

.github/workflows/CI.yml

Lines changed: 81 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ on:
1111
paths-ignore:
1212
- 'docs/**'
1313
pull_request:
14+
types: [opened, synchronize, reopened, ready_for_review, converted_to_draft]
1415
workflow_dispatch:
1516

1617
concurrency:
@@ -19,55 +20,88 @@ concurrency:
1920
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
2021

2122
jobs:
23+
setup-matrix:
24+
runs-on: ubuntu-latest
25+
outputs:
26+
groups: ${{ steps.mk.outputs.groups }}
27+
version: ${{ steps.mk.outputs.version }}
28+
os: ${{ steps.mk.outputs.os }}
29+
steps:
30+
- uses: actions/checkout@v6
31+
- id: mk
32+
shell: bash
33+
run: |
34+
# Auto-discover test groups from all subdirectory names.
35+
groups=$(find test -mindepth 1 -maxdepth 1 -type d \
36+
| xargs -I{} basename {} | sort \
37+
| jq -R -s -c '[split("\n")[] | select(length > 0)]')
38+
39+
echo "groups=${groups}" >> "$GITHUB_OUTPUT"
40+
41+
# Draft PR: only run ubuntu-latest + version=1
42+
if [[ "${{ github.event_name }}" == "pull_request" && "${{ github.event.pull_request.draft }}" == "true" ]]; then
43+
echo 'version=["1"]' >> "$GITHUB_OUTPUT"
44+
echo 'os=["ubuntu-latest"]' >> "$GITHUB_OUTPUT"
45+
else
46+
echo 'version=["lts","1"]' >> "$GITHUB_OUTPUT"
47+
echo 'os=["ubuntu-latest","macOS-latest","windows-latest"]' >> "$GITHUB_OUTPUT"
48+
fi
49+
2250
test:
51+
name: "Tests (${{ matrix.group }}, ${{ matrix.os }}, Julia ${{ matrix.version }})"
52+
needs: setup-matrix
2353
strategy:
2454
fail-fast: false
2555
matrix:
26-
version:
27-
- 'lts'
28-
- '1'
29-
group:
30-
- symmetries
31-
- tensors
32-
- other
33-
- mooncake
34-
- chainrules
35-
os:
36-
- ubuntu-latest
37-
- macOS-latest
38-
- windows-latest
39-
uses: "QuantumKitHub/QuantumKitHubActions/.github/workflows/Tests.yml@main"
40-
with:
41-
group: "${{ matrix.group }}"
42-
julia-version: "${{ matrix.version }}"
43-
os: "${{ matrix.os }}"
44-
nthreads: 4
45-
timeout-minutes: 120
46-
secrets:
47-
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
56+
version: ${{ fromJSON(needs.setup-matrix.outputs.version) }}
57+
os: ${{ fromJSON(needs.setup-matrix.outputs.os) }}
58+
group: ${{ fromJSON(needs.setup-matrix.outputs.groups) }}
59+
runs-on: ${{ matrix.os }}
60+
timeout-minutes: 120
61+
steps:
62+
- uses: actions/checkout@v6
63+
- uses: julia-actions/setup-julia@v2
64+
with:
65+
version: ${{ matrix.version }}
66+
- uses: julia-actions/cache@v3
67+
- uses: julia-actions/julia-buildpkg@v1
68+
- uses: julia-actions/julia-runtest@v1
69+
with:
70+
test_args: '${{ matrix.group }}${{ github.event.pull_request.draft == true && '' --fast'' || '''' }}'
71+
env:
72+
JULIA_NUM_THREADS: "4"
73+
- uses: julia-actions/julia-processcoverage@v1
74+
with:
75+
directories: 'src,ext'
76+
- uses: codecov/codecov-action@v6
77+
with:
78+
files: lcov.info
79+
token: ${{ secrets.CODECOV_TOKEN }}
80+
fail_ci_if_error: false
4881

49-
test-nightly:
50-
needs: test
51-
strategy:
52-
matrix:
53-
version:
54-
- 'nightly'
55-
group:
56-
- symmetries
57-
- tensors
58-
- other
59-
- mooncake
60-
- chainrules
61-
os:
62-
- ubuntu-latest
63-
- macOS-latest
64-
- windows-latest
65-
uses: "QuantumKitHub/QuantumKitHubActions/.github/workflows/Tests.yml@main"
66-
with:
67-
group: "${{ matrix.group }}"
68-
julia-version: "${{ matrix.version }}"
69-
os: "${{ matrix.os }}"
70-
nthreads: 4
71-
timeout-minutes: 120
72-
secrets:
73-
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
82+
# test-nightly:
83+
# name: "Tests (${{ matrix.group }}, ${{ matrix.os }}, Julia nightly)"
84+
# needs: [setup-matrix, test]
85+
# if: github.event.pull_request.draft != true
86+
# strategy:
87+
# fail-fast: false
88+
# matrix:
89+
# version:
90+
# - 'nightly'
91+
# group: ${{ fromJSON(needs.setup-matrix.outputs.groups) }}
92+
# os:
93+
# - ubuntu-latest
94+
# - macOS-latest
95+
# - windows-latest
96+
# runs-on: ${{ matrix.os }}
97+
# timeout-minutes: 120
98+
# steps:
99+
# - uses: actions/checkout@v6
100+
# - uses: julia-actions/setup-julia@v2
101+
# with:
102+
# version: ${{ matrix.version }}
103+
# - uses: julia-actions/cache@v3
104+
# - uses: julia-actions/julia-buildpkg@v1
105+
# - uses: julia-actions/julia-runtest@v1
106+
# with:
107+
# test_args: '${{ matrix.group }}'

.github/workflows/CompatCheck.yml

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,69 @@
1-
name: Compat Check
1+
name: CompatCheck
22

33
on:
44
push:
55
branches:
6-
- 'master'
76
- 'main'
87
- 'release-'
8+
99
tags: '*'
10+
11+
paths:
12+
- 'Project.toml'
13+
- 'test/Project.toml'
14+
1015
pull_request:
16+
types: [opened, synchronize, reopened, ready_for_review, converted_to_draft]
1117
workflow_dispatch:
1218

1319
concurrency:
1420
group: ${{ github.workflow }}-${{ github.ref }}
15-
cancel-in-progress: true
21+
# Cancel intermediate builds: only if it is a pull request build.
22+
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
1623

1724
jobs:
18-
test:
19-
name: Compat bounds check - ${{ matrix.julia-version }}
25+
setup-matrix:
26+
runs-on: ubuntu-latest
27+
outputs:
28+
groups: ${{ steps.mk.outputs.groups }}
29+
version: ${{ steps.mk.outputs.version }}
30+
os: ${{ steps.mk.outputs.os }}
31+
steps:
32+
- uses: actions/checkout@v6
33+
- id: mk
34+
shell: bash
35+
run: |
36+
# Auto-discover test groups from all subdirectory names.
37+
groups=$(find test -mindepth 1 -maxdepth 1 -type d \
38+
| xargs -I{} basename {} | sort \
39+
| jq -R -s -c '[split("\n")[] | select(length > 0)]')
40+
41+
echo "groups=${groups}" >> "$GITHUB_OUTPUT"
42+
compatcheck:
43+
name: "Compat (${{ matrix.group }}, Julia ${{ matrix.julia-version }})"
44+
needs: setup-matrix
45+
if: github.event.pull_request.draft != true
2046
runs-on: ubuntu-latest
2147
strategy:
48+
fail-fast: false
2249
matrix:
2350
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']
51+
group: ${{ fromJSON(needs.setup-matrix.outputs.groups) }}
52+
julia-version: ['1', '1.10']
2753
steps:
2854
- uses: actions/checkout@v6
2955
- uses: julia-actions/setup-julia@v2
3056
with:
3157
version: ${{ matrix.julia-version }}
58+
- uses: julia-actions/cache@v3
3259
- uses: julia-actions/julia-downgrade-compat@v2
3360
with:
3461
mode: ${{ matrix.downgrade_mode }}
3562
skip: Random, LinearAlgebra, Test, Combinatorics
3663
julia_version: ${{ matrix.julia-version }}
3764
- uses: julia-actions/julia-buildpkg@v1
3865
- uses: julia-actions/julia-runtest@v1
66+
with:
67+
test_args: '${{ matrix.group }} --fast'
68+
env:
69+
JULIA_NUM_THREADS: "4"

Project.toml

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -33,59 +33,27 @@ TensorKitChainRulesCoreExt = "ChainRulesCore"
3333
TensorKitFiniteDifferencesExt = "FiniteDifferences"
3434
TensorKitMooncakeExt = "Mooncake"
3535

36+
[workspace]
37+
projects = ["test"]
38+
3639
[compat]
3740
Adapt = "4"
38-
AllocCheck = "0.2.3"
39-
Aqua = "0.6, 0.7, 0.8"
40-
ArgParse = "1.2.0"
4141
CUDA = "5.9"
4242
ChainRulesCore = "1"
43-
ChainRulesTestUtils = "1"
44-
Combinatorics = "1"
4543
Dictionaries = "0.4"
4644
FiniteDifferences = "0.12"
47-
GPUArrays = "11.3.1"
48-
JET = "0.9, 0.10, 0.11"
4945
LRUCache = "1.0.2"
5046
LinearAlgebra = "1"
5147
MatrixAlgebraKit = "0.6.5"
5248
Mooncake = "0.5"
5349
OhMyThreads = "0.8.0"
5450
Printf = "1"
5551
Random = "1"
56-
SafeTestsets = "0.1"
5752
ScopedValues = "1.3.0"
5853
Strided = "2"
5954
TensorKitSectors = "0.3.6"
6055
TensorOperations = "5.1"
61-
Test = "1"
62-
TestExtras = "0.2,0.3"
6356
TupleTools = "1.5"
6457
VectorInterface = "0.4.8, 0.5"
65-
Zygote = "0.7"
6658
cuTENSOR = "2"
6759
julia = "1.10"
68-
69-
[extras]
70-
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
71-
AllocCheck = "9b6a8646-10ed-4001-bbdc-1d2f46dfbb1a"
72-
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
73-
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
74-
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
75-
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
76-
ChainRulesTestUtils = "cdddcdb0-9152-4a09-a978-84456f9df70a"
77-
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
78-
FiniteDifferences = "26cc04aa-876d-5657-8c51-4c34ba976000"
79-
GPUArrays = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7"
80-
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
81-
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
82-
Mooncake = "da2b9cff-9c12-43a0-ae48-6db2b0edb7d6"
83-
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
84-
TensorOperations = "6aa20fa7-93e2-5fca-9bc0-fbd0db3c71a2"
85-
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
86-
TestExtras = "5ed8adda-3752-4e41-b88a-e8b09835ee3a"
87-
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
88-
cuTENSOR = "011b41b2-24ef-40a8-b3eb-fa098493e9e1"
89-
90-
[targets]
91-
test = ["ArgParse", "Adapt", "Aqua", "AllocCheck", "Combinatorics", "CUDA", "cuTENSOR", "GPUArrays", "JET", "LinearAlgebra", "SafeTestsets", "TensorOperations", "Test", "TestExtras", "ChainRulesCore", "ChainRulesTestUtils", "FiniteDifferences", "Zygote", "Mooncake"]

ext/TensorKitChainRulesCoreExt/linalg.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ function ChainRulesCore.rrule(
7474
)
7575
function transpose_pullback(Δtdst)
7676
invp = TensorKit._canonicalize(TupleTools.invperm(linearize(p)), tsrc)
77-
return NoTangent(), transpose(unthunk(Δtdst), invp; copy = true), NoTangent()
77+
Δtsrc = transpose(unthunk(Δtdst), invp; copy = true)
78+
return NoTangent(), ProjectTo(tsrc)(Δtsrc), NoTangent()
7879
end
7980
return transpose(tsrc, p; copy = true), transpose_pullback
8081
end
@@ -91,18 +92,18 @@ end
9192

9293
function ChainRulesCore.rrule(::typeof(twist), A::AbstractTensorMap, is; inv::Bool = false, kwargs...)
9394
tA = twist(A, is; inv, kwargs...)
94-
twist_pullback(ΔA) = NoTangent(), twist(unthunk(ΔA), is; inv = !inv, kwargs...), NoTangent()
95+
twist_pullback(ΔA) = NoTangent(), ProjectTo(A)(twist(unthunk(ΔA), is; inv = !inv, kwargs...)), NoTangent()
9596
return tA, twist_pullback
9697
end
9798

9899
function ChainRulesCore.rrule(::typeof(flip), A::AbstractTensorMap, is; inv::Bool = false)
99100
tA = flip(A, is; inv)
100-
flip_pullback(ΔA) = NoTangent(), flip(unthunk(ΔA), is; inv = !inv), NoTangent()
101+
flip_pullback(ΔA) = NoTangent(), ProjectTo(A)(flip(unthunk(ΔA), is; inv = !inv)), NoTangent()
101102
return tA, flip_pullback
102103
end
103104

104105
function ChainRulesCore.rrule(::typeof(dot), a::AbstractTensorMap, b::AbstractTensorMap)
105-
dot_pullback(Δd) = NoTangent(), @thunk(b * Δd'), @thunk(a * Δd)
106+
dot_pullback(Δd) = NoTangent(), @thunk(ProjectTo(a)(b * Δd')), @thunk(ProjectTo(b)(a * Δd))
106107
return dot(a, b), dot_pullback
107108
end
108109

src/fusiontrees/braiding_manipulations.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function artin_braid(f::FusionTree{I, N}, i; inv::Bool = false) where {I, N}
6464
a = inner_extended[i - 1]
6565
c = inner_extended[i]
6666
e = inner_extended[i + 1]
67-
c′ = first(a d)
67+
c′ = only(a d)
6868
coeff = oftype(
6969
oneT,
7070
if inv
@@ -223,7 +223,7 @@ function braid(f::FusionTree{I, N}, (p, _)::Index2Tuple{N, 0}, (levels, _)::Inde
223223
for j in 1:(i - 1)
224224
if p[j] > p[i]
225225
a, b = f.uncoupled[p[j]], f.uncoupled[p[i]]
226-
coeff *= Rsymbol(a, b, first(a b))
226+
coeff *= Rsymbol(a, b, only(a b))
227227
end
228228
end
229229
end
@@ -308,7 +308,6 @@ end
308308
f′, coeff2 = braid(f, p, levels)
309309
(f₁′, f₂′), coeff3 = repartition((f′, f0), N₁)
310310
return (f₁′, f₂′) => coeff1 * coeff2 * coeff3
311-
312311
else
313312
src, (p1, p2), (l1, l2) = key
314313

src/spaces/productspace.jl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,7 @@ function insertleftunit(
278278
u = unitspace(spacetype(P))
279279
else
280280
N > 0 || throw(ArgumentError("cannot insert a sensible unit space in the empty product space"))
281-
if i == N + 1
282-
u = rightunitspace(P[N])
283-
else
284-
u = leftunitspace(P[i])
285-
end
281+
u = (i == N + 1) ? rightunitspace(P[N]) : leftunitspace(P[i])
286282
end
287283
if dual
288284
u = TensorKit.dual(u)
@@ -312,7 +308,7 @@ function insertrightunit(
312308
u = unitspace(spacetype(P))
313309
else
314310
N > 0 || throw(ArgumentError("cannot insert a sensible unit space in the empty product space"))
315-
u = rightunitspace(P[i])
311+
u = (i == 0) ? leftunitspace(P[1]) : rightunitspace(P[i])
316312
end
317313
if dual
318314
u = TensorKit.dual(u)

0 commit comments

Comments
 (0)