Skip to content

Commit 58056cb

Browse files
authored
Try again to get things working for all rules on 1.10 (#579)
1 parent 8f7af24 commit 58056cb

6 files changed

Lines changed: 19 additions & 31 deletions

File tree

‎ext/TensorKitEnzymeExt/indexmanipulations.jl‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ for transform in (:permute, :transpose)
1818
# and store that instead of repeating the permutation in the pullback each time.
1919
# effectively, we replace `add_permute` by `add ∘ permute`.
2020
Ap = if !isa(α, Const)
21-
Ap = $transform(A.val, p.val)
21+
# without copy=true, this may just alias A if
22+
# the permutation is an identity or the space
23+
# is Trivial and has_shared_permute is true
24+
Ap = $transform(A.val, p.val; copy = true)
2225
add!(C.val, Ap, α.val, β.val)
2326
Ap
2427
else

‎test/enzyme/inv.jl‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,9 @@ TDs = is_ci ? (Duplicated,) : (Const, Duplicated)
2121
D2 = randn(T, V[1] ⊗ V[2] ← V[1] ⊗ V[2])
2222
EnzymeTestUtils.test_reverse(inv, TD, (D2, TD); atol, rtol)
2323
EnzymeTestUtils.test_forward(inv, TD, (D2, TD); atol, rtol)
24-
# see https://github.com/QuantumKitHub/TensorKit.jl/issues/457
25-
@static if VERSION ≥ v"1.11.0-rc"
26-
D3 = randn(T, V[1] ⊗ V[2] ⊗ V[3] ← V[1] ⊗ V[2] ⊗ V[3])
27-
EnzymeTestUtils.test_reverse(inv, TD, (D3, TD); atol, rtol)
28-
EnzymeTestUtils.test_forward(inv, TD, (D3, TD); atol, rtol)
29-
end
24+
D3 = randn(T, V[1] ⊗ V[2] ⊗ V[3] ← V[1] ⊗ V[2] ⊗ V[3])
25+
EnzymeTestUtils.test_reverse(inv, TD, (D3, TD); atol, rtol)
26+
EnzymeTestUtils.test_forward(inv, TD, (D3, TD); atol, rtol)
3027
end
3128
end
3229
end

‎test/enzyme/norm.jl‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,7 @@ fRTs = is_ci ? (Duplicated,) : (Const, Duplicated)
1414
@timedtestset "$(TensorKit.type_repr(sectortype(eltype(V)))) ($T), TC $TC" for V in spacelist, T in eltypes, TC in (Const, Duplicated)
1515
atol = default_tol(T)
1616
rtol = default_tol(T)
17-
# see https://github.com/QuantumKitHub/TensorKit.jl/issues/457
18-
@static if VERSION < v"1.11.0-rc"
19-
C = randn(T, V[1] ⊗ V[2] ← (V[4] ⊗ V[5])')
20-
else
21-
C = randn(T, V[1] ⊗ V[2] ← (V[3] ⊗ V[4] ⊗ V[5])')
22-
end
17+
C = randn(T, V[1] ⊗ V[2] ← (V[3] ⊗ V[4] ⊗ V[5])')
2318
for RT in rRTs
2419
EnzymeTestUtils.test_reverse(norm, RT, (C, TC), (2, Const); atol, rtol)
2520
EnzymeTestUtils.test_reverse(norm, RT, (C', TC), (2, Const); atol, rtol)

‎test/enzyme/permute.jl‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,11 @@ fTβs = is_ci ? (Duplicated,) : (Duplicated, Const)
2424
β = randn(T)
2525
p = randindextuple(numind(A))
2626
C = randn!(permute(A, p))
27-
@static if VERSION ≥ v"1.11.0-rc"
28-
for Tα in rTαs, Tβ in rTβs
29-
EnzymeTestUtils.test_reverse(TensorKit.permute!, Duplicated, (C, Duplicated), (A, Duplicated), (p, Const), (α, Tα), (β, Tβ); atol, rtol, testset_name = "permute! reverse Tα: $Tα, Tβ: $Tβ")
30-
end
31-
for Tα in fTαs, Tβ in fTβs
32-
EnzymeTestUtils.test_forward(TensorKit.permute!, Duplicated, (C, Duplicated), (A, Duplicated), (p, Const), (α, Tα), (β, Tβ); atol, rtol, testset_name = "permute! forward Tα: $Tα, Tβ: $Tβ")
33-
end
27+
for Tα in rTαs, Tβ in rTβs
28+
EnzymeTestUtils.test_reverse(TensorKit.permute!, Duplicated, (C, Duplicated), (A, Duplicated), (p, Const), (α, Tα), (β, Tβ); atol, rtol, testset_name = "permute! reverse Tα: $Tα, Tβ: $Tβ")
29+
end
30+
for Tα in fTαs, Tβ in fTβs
31+
EnzymeTestUtils.test_forward(TensorKit.permute!, Duplicated, (C, Duplicated), (A, Duplicated), (p, Const), (α, Tα), (β, Tβ); atol, rtol, testset_name = "permute! forward Tα: $Tα, Tβ: $Tβ")
3432
end
3533
end
3634
end

‎test/enzyme/tr.jl‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,12 @@ TDs = is_ci ? (Duplicated,) : (Const, Duplicated)
2222
@testset "tr reverse: RT $RT, TD $TD" for RT in rRTs, TD in TDs
2323
EnzymeTestUtils.test_reverse(tr, RT, (D1, TD); atol, rtol)
2424
EnzymeTestUtils.test_reverse(tr, RT, (D2, TD); atol, rtol)
25-
# see https://github.com/QuantumKitHub/TensorKit.jl/issues/457
26-
@static if VERSION ≥ v"1.11.0-rc"
27-
EnzymeTestUtils.test_reverse(tr, RT, (D3, TD); atol, rtol)
28-
end
25+
EnzymeTestUtils.test_reverse(tr, RT, (D3, TD); atol, rtol)
2926
end
3027
@testset "tr forward: RT $RT, TD $TD" for RT in fRTs, TD in TDs
3128
EnzymeTestUtils.test_forward(tr, RT, (D1, TD); atol, rtol)
3229
EnzymeTestUtils.test_forward(tr, RT, (D2, TD); atol, rtol)
33-
# see https://github.com/QuantumKitHub/TensorKit.jl/issues/457
34-
@static if VERSION ≥ v"1.11.0-rc"
35-
EnzymeTestUtils.test_forward(tr, RT, (D3, TD); atol, rtol)
36-
end
30+
EnzymeTestUtils.test_forward(tr, RT, (D3, TD); atol, rtol)
3731
end
3832
end
3933
end

‎test/runtests.jl‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,14 @@ args = parse_args(ARGS; custom = ["fast"])
4141
# --fast: skip AD tests and inject fast_tests=true into each worker sandbox
4242
fast = !isnothing(args.custom["fast"])
4343

44-
# Enzyme workers end up needing ~4 GB, but the default job count assumes ~2 GB per worker.
45-
# Cap the number of jobs by increasing the per-worker memory budget unless --jobs was given.
44+
# Enzyme workers peak at ~4.5 GB, but the default job count
45+
# assumes ~2 GB per worker. Cap the number of jobs by increasing the per-worker memory budget
46+
# unless --jobs was given; with 4 GB, 16 GB CI runners would run out of memory and be killed.
4647
selected = copy(testsuite)
4748
ParallelTestRunner.filter_tests!(selected, args)
4849
has_enzyme = any(startswith("enzyme"), keys(selected))
4950
if isnothing(args.jobs) && has_enzyme
50-
njobs = clamp(Int(Sys.free_memory() ÷ (4 * Int64(2)^30)), 1, Sys.CPU_THREADS)
51+
njobs = clamp(Int(Sys.free_memory() ÷ (5 * Int64(2)^30)), 1, Sys.CPU_THREADS)
5152
# On Windows with Julia 1.10, memory pressure makes recycled workers too slow to start:
5253
# Malt gives up if a new worker does not connect within 30 s, which aborts the whole run.
5354
Sys.iswindows() && VERSION < v"1.11" && (njobs = min(njobs, 2))

0 commit comments

Comments
 (0)