From d917aa4498f462d47d56a1eb8804ad4d4439ff50 Mon Sep 17 00:00:00 2001 From: Katharine Hyatt Date: Wed, 29 Jul 2026 16:43:43 +0200 Subject: [PATCH 1/3] Consolidate Enzyme TO and VI tests --- test/{enzyme-vectorinterface => enzyme-vi-to}/add.jl | 0 test/{enzyme-tensoroperations => enzyme-vi-to}/contract.jl | 0 test/{enzyme-vectorinterface => enzyme-vi-to}/inner.jl | 0 test/{enzyme-vectorinterface => enzyme-vi-to}/scale.jl | 0 test/{enzyme-tensoroperations => enzyme-vi-to}/trace.jl | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename test/{enzyme-vectorinterface => enzyme-vi-to}/add.jl (100%) rename test/{enzyme-tensoroperations => enzyme-vi-to}/contract.jl (100%) rename test/{enzyme-vectorinterface => enzyme-vi-to}/inner.jl (100%) rename test/{enzyme-vectorinterface => enzyme-vi-to}/scale.jl (100%) rename test/{enzyme-tensoroperations => enzyme-vi-to}/trace.jl (100%) diff --git a/test/enzyme-vectorinterface/add.jl b/test/enzyme-vi-to/add.jl similarity index 100% rename from test/enzyme-vectorinterface/add.jl rename to test/enzyme-vi-to/add.jl diff --git a/test/enzyme-tensoroperations/contract.jl b/test/enzyme-vi-to/contract.jl similarity index 100% rename from test/enzyme-tensoroperations/contract.jl rename to test/enzyme-vi-to/contract.jl diff --git a/test/enzyme-vectorinterface/inner.jl b/test/enzyme-vi-to/inner.jl similarity index 100% rename from test/enzyme-vectorinterface/inner.jl rename to test/enzyme-vi-to/inner.jl diff --git a/test/enzyme-vectorinterface/scale.jl b/test/enzyme-vi-to/scale.jl similarity index 100% rename from test/enzyme-vectorinterface/scale.jl rename to test/enzyme-vi-to/scale.jl diff --git a/test/enzyme-tensoroperations/trace.jl b/test/enzyme-vi-to/trace.jl similarity index 100% rename from test/enzyme-tensoroperations/trace.jl rename to test/enzyme-vi-to/trace.jl From 43ec2147bdac9e6b19e7ee9fa3eea8f3c4da979c Mon Sep 17 00:00:00 2001 From: Katharine Hyatt Date: Wed, 29 Jul 2026 16:48:22 +0200 Subject: [PATCH 2/3] Cut CI burden and retry things on 1.10 --- test/enzyme-vi-to/add.jl | 25 ++-- test/enzyme-vi-to/contract.jl | 242 +++++++++++++++++----------------- test/enzyme-vi-to/inner.jl | 16 +-- test/enzyme-vi-to/scale.jl | 16 +-- test/enzyme-vi-to/trace.jl | 74 +++++------ 5 files changed, 185 insertions(+), 188 deletions(-) diff --git a/test/enzyme-vi-to/add.jl b/test/enzyme-vi-to/add.jl index 5d44b2830..aa4ba4524 100644 --- a/test/enzyme-vi-to/add.jl +++ b/test/enzyme-vi-to/add.jl @@ -3,10 +3,16 @@ using TensorKit, Enzyme, EnzymeTestUtils using TensorOperations using Random -#spacelist = ad_spacelist(fast_tests) -spacelist = [ad_spacelist(fast_tests)[1]] +spacelist = ad_spacelist(fast_tests) eltypes = (Float64, ComplexF64) +is_ci = get(ENV, "CI", "false") == "true" + +rTαs = is_ci ? (Active,) : (Active, Const) +rTβs = is_ci ? (Active,) : (Active, Const) +fTαs = is_ci ? (Duplicated,) : (Duplicated, Const) +fTβs = is_ci ? (Duplicated,) : (Duplicated, Const) + @testset "Enzyme - VectorInterface (add!) $(TensorKit.type_repr(sectortype(eltype(V)))) ($T)" for V in spacelist, T in eltypes atol = default_tol(T) rtol = default_tol(T) @@ -14,12 +20,7 @@ eltypes = (Float64, ComplexF64) α = randn(T) β = randn(T) - # see https://github.com/QuantumKitHub/TensorKit.jl/issues/457 - if VERSION < v"1.11.0-rc" && sectortype(eltype(V)) == Trivial - CV = V[1] ⊗ V[2] ← V[4] ⊗ V[5] - else - CV = V[1] ⊗ V[2] ← V[3] ⊗ V[4] ⊗ V[5] - end + CV = V[1] ⊗ V[2] ← V[3] ⊗ V[4] ⊗ V[5] C = randn(T, CV) A = randn(T, CV) for TC in (Duplicated,), TA in (Duplicated,) @@ -27,21 +28,21 @@ eltypes = (Float64, ComplexF64) A = randn(T, CV) EnzymeTestUtils.test_reverse(add!, TC, (C, TC), (A, TA); atol, rtol, testset_name = "add! reverse TC $TC TA $TA no α no β") EnzymeTestUtils.test_forward(add!, TC, (C, TC), (A, TA); atol, rtol, testset_name = "add! forward TC $TC TA $TA no α no β") - for Tα in (Active, Const) + for Tα in rTαs C = randn(T, CV) A = randn(T, CV) EnzymeTestUtils.test_reverse(add!, TC, (C, TC), (A, TA), (α, Tα); atol, rtol, testset_name = "add! reverse TC $TC TA $TA Tα $Tα no β") - for Tβ in (Active, Const) + for Tβ in rTβs C = randn(T, CV) A = randn(T, CV) EnzymeTestUtils.test_reverse(add!, TC, (C, TC), (A, TA), (α, Tα), (β, Tβ); atol, rtol, testset_name = "add! reverse TC $TC TA $TA Tα $Tα Tβ $Tβ") end end - for Tα in (Duplicated, Const) + for Tα in fTαs C = randn(T, CV) A = randn(T, CV) EnzymeTestUtils.test_forward(add!, TC, (C, TC), (A, TA), (α, Tα); atol, rtol, testset_name = "add! forward TC $TC TA $TA Tα $Tα no β") - for Tβ in (Duplicated, Const) + for Tβ in fTβs C = randn(T, CV) A = randn(T, CV) EnzymeTestUtils.test_forward(add!, TC, (C, TC), (A, TA), (α, Tα), (β, Tβ); atol, rtol, testset_name = "add! forward TC $TC TA $TA Tα $Tα Tβ $Tβ") diff --git a/test/enzyme-vi-to/contract.jl b/test/enzyme-vi-to/contract.jl index 9829a11f3..064bfba74 100644 --- a/test/enzyme-vi-to/contract.jl +++ b/test/enzyme-vi-to/contract.jl @@ -9,131 +9,129 @@ is_ci = get(ENV, "CI", "false") == "true" spacelist = ad_spacelist(fast_tests) eltypes = (Float64, ComplexF64) -if !(is_ci && Sys.iswindows() && VERSION < v"1.11.0-rc") - @timedtestset "Enzyme - TensorOperations" begin - @timedtestset verbose = true "$(TensorKit.type_repr(sectortype(eltype(V)))) ($T)" for V in spacelist, T in eltypes - atol = default_tol(T) - rtol = default_tol(T) - symmetricbraiding = BraidingStyle(sectortype(eltype(V))) isa SymmetricBraiding - symmetricbraiding && @timedtestset "tensorcontract!" begin - d = 0 - local V1, V2, V3 - # retry a couple times to make sure there are at least some nonzero elements - for _ in 1:10 - k1 = rand(0:3) - k2 = rand(0:2) - k3 = rand(0:2) - V1 = prod(v -> rand(Bool) ? v' : v, rand(V, k1); init = one(V[1])) - V2 = prod(v -> rand(Bool) ? v' : v, rand(V, k2); init = one(V[1])) - V3 = prod(v -> rand(Bool) ? v' : v, rand(V, k3); init = one(V[1])) - d = min(dim(V1 ← V2), dim(V1' ← V2), dim(V2 ← V3), dim(V2' ← V3)) - d > 0 && break - end - ipA = randindextuple(length(V1) + length(V2)) - pA = _repartition(invperm(linearize(ipA)), length(V1)) - ipB = randindextuple(length(V2) + length(V3)) - pB = _repartition(invperm(linearize(ipB)), length(V2)) - pAB = randindextuple(length(V1) + length(V3)) +@timedtestset "Enzyme - TensorOperations" begin + @timedtestset verbose = true "$(TensorKit.type_repr(sectortype(eltype(V)))) ($T)" for V in spacelist, T in eltypes + atol = default_tol(T) + rtol = default_tol(T) + symmetricbraiding = BraidingStyle(sectortype(eltype(V))) isa SymmetricBraiding + symmetricbraiding && @timedtestset "tensorcontract!" begin + d = 0 + local V1, V2, V3 + # retry a couple times to make sure there are at least some nonzero elements + for _ in 1:10 + k1 = rand(0:3) + k2 = rand(0:2) + k3 = rand(0:2) + V1 = prod(v -> rand(Bool) ? v' : v, rand(V, k1); init = one(V[1])) + V2 = prod(v -> rand(Bool) ? v' : v, rand(V, k2); init = one(V[1])) + V3 = prod(v -> rand(Bool) ? v' : v, rand(V, k3); init = one(V[1])) + d = min(dim(V1 ← V2), dim(V1' ← V2), dim(V2 ← V3), dim(V2' ← V3)) + d > 0 && break + end + ipA = randindextuple(length(V1) + length(V2)) + pA = _repartition(invperm(linearize(ipA)), length(V1)) + ipB = randindextuple(length(V2) + length(V3)) + pB = _repartition(invperm(linearize(ipB)), length(V2)) + pAB = randindextuple(length(V1) + length(V3)) - α = randn(T) - β = randn(T) - V2_conj = prod(conj, V2; init = one(V[1])) - A = randn(T, permute(V1 ← V2, ipA)) - B = randn(T, permute(V2 ← V3, ipB)) - C = randn!( - TensorOperations.tensoralloc_contract( - T, A, pA, false, B, pB, false, pAB, Val(false) - ) + α = randn(T) + β = randn(T) + V2_conj = prod(conj, V2; init = one(V[1])) + A = randn(T, permute(V1 ← V2, ipA)) + B = randn(T, permute(V2 ← V3, ipB)) + C = randn!( + TensorOperations.tensoralloc_contract( + T, A, pA, false, B, pB, false, pAB, Val(false) ) + ) - αβs = is_ci ? (((α, Active), (β, Active)),) : Iterators.product(((One(), Const), (α, Const), (α, Active)), ((Zero(), Const), (β, Const), (β, Active))) - for (α_, β_) in αβs - EnzymeTestUtils.test_reverse( - TensorKit.blas_contract!, Duplicated, - (copy(C), Duplicated), (A, Duplicated), (pA, Const), - (B, Duplicated), (pB, Const), (pAB, Const), - α_, β_, - (TensorOperations.DefaultBackend(), Const), - (TensorOperations.DefaultAllocator(), Const); - atol, rtol, - testset_name = "blas_contract! reverse α $α_ β $β_", - ) - end - αβs = is_ci ? (((α, Duplicated), (β, Duplicated)),) : Iterators.product(((One(), Const), (α, Const), (α, Duplicated)), ((Zero(), Const), (β, Const), (β, Duplicated))) - for (α_, β_) in αβs - EnzymeTestUtils.test_forward( - TensorKit.blas_contract!, Duplicated, - (copy(C), Duplicated), (A, Duplicated), (pA, Const), - (B, Duplicated), (pB, Const), (pAB, Const), - α_, β_, - (TensorOperations.DefaultBackend(), Const), - (TensorOperations.DefaultAllocator(), Const); - atol, rtol, - testset_name = "blas_contract! forward α $α_ β $β_", - ) - end - if !(T <: Real) && !is_ci - EnzymeTestUtils.test_reverse( - TensorKit.blas_contract!, Duplicated, - (copy(C), Duplicated), (A, Duplicated), (pA, Const), - (B, Duplicated), (pB, Const), (pAB, Const), - (real(α), Active), (real(β), Active), - (TensorOperations.DefaultBackend(), Const), - (TensorOperations.DefaultAllocator(), Const); - atol, rtol, - testset_name = "blas_contract! reverse real(α) real(β)", - ) - EnzymeTestUtils.test_reverse( - TensorKit.blas_contract!, Duplicated, - (copy(C), Duplicated), (real(A), Duplicated), (pA, Const), - (B, Duplicated), (pB, Const), (pAB, Const), - (real(α), Active), (real(β), Active), - (TensorOperations.DefaultBackend(), Const), - (TensorOperations.DefaultAllocator(), Const); - atol, rtol, - testset_name = "blas_contract! reverse real(A) real(α) real(β)", - ) - EnzymeTestUtils.test_reverse( - TensorKit.blas_contract!, Duplicated, - (copy(C), Duplicated), (A, Duplicated), (pA, Const), - (real(B), Duplicated), (pB, Const), (pAB, Const), - (real(α), Active), (real(β), Active), - (TensorOperations.DefaultBackend(), Const), - (TensorOperations.DefaultAllocator(), Const); - atol, rtol, - testset_name = "blas_contract! reverse real(B) real(α) real(β)", - ) - EnzymeTestUtils.test_forward( - TensorKit.blas_contract!, Duplicated, - (copy(C), Duplicated), (A, Duplicated), (pA, Const), - (B, Duplicated), (pB, Const), (pAB, Const), - (real(α), Active), (real(β), Active), - (TensorOperations.DefaultBackend(), Const), - (TensorOperations.DefaultAllocator(), Const); - atol, rtol, - testset_name = "blas_contract! forward real(α) real(β)", - ) - EnzymeTestUtils.test_forward( - TensorKit.blas_contract!, Duplicated, - (copy(C), Duplicated), (real(A), Duplicated), (pA, Const), - (B, Duplicated), (pB, Const), (pAB, Const), - (real(α), Active), (real(β), Active), - (TensorOperations.DefaultBackend(), Const), - (TensorOperations.DefaultAllocator(), Const); - atol, rtol, - testset_name = "blas_contract! forward real(A) real(α) real(β)", - ) - EnzymeTestUtils.test_forward( - TensorKit.blas_contract!, Duplicated, - (copy(C), Duplicated), (A, Duplicated), (pA, Const), - (real(B), Duplicated), (pB, Const), (pAB, Const), - (real(α), Active), (real(β), Active), - (TensorOperations.DefaultBackend(), Const), - (TensorOperations.DefaultAllocator(), Const); - atol, rtol, - testset_name = "blas_contract! forward real(B) real(α) real(β)", - ) - end + αβs = is_ci ? (((α, Active), (β, Active)),) : Iterators.product(((One(), Const), (α, Const), (α, Active)), ((Zero(), Const), (β, Const), (β, Active))) + for (α_, β_) in αβs + EnzymeTestUtils.test_reverse( + TensorKit.blas_contract!, Duplicated, + (copy(C), Duplicated), (A, Duplicated), (pA, Const), + (B, Duplicated), (pB, Const), (pAB, Const), + α_, β_, + (TensorOperations.DefaultBackend(), Const), + (TensorOperations.DefaultAllocator(), Const); + atol, rtol, + testset_name = "blas_contract! reverse α $α_ β $β_", + ) + end + αβs = is_ci ? (((α, Duplicated), (β, Duplicated)),) : Iterators.product(((One(), Const), (α, Const), (α, Duplicated)), ((Zero(), Const), (β, Const), (β, Duplicated))) + for (α_, β_) in αβs + EnzymeTestUtils.test_forward( + TensorKit.blas_contract!, Duplicated, + (copy(C), Duplicated), (A, Duplicated), (pA, Const), + (B, Duplicated), (pB, Const), (pAB, Const), + α_, β_, + (TensorOperations.DefaultBackend(), Const), + (TensorOperations.DefaultAllocator(), Const); + atol, rtol, + testset_name = "blas_contract! forward α $α_ β $β_", + ) + end + if !(T <: Real) && !is_ci + EnzymeTestUtils.test_reverse( + TensorKit.blas_contract!, Duplicated, + (copy(C), Duplicated), (A, Duplicated), (pA, Const), + (B, Duplicated), (pB, Const), (pAB, Const), + (real(α), Active), (real(β), Active), + (TensorOperations.DefaultBackend(), Const), + (TensorOperations.DefaultAllocator(), Const); + atol, rtol, + testset_name = "blas_contract! reverse real(α) real(β)", + ) + EnzymeTestUtils.test_reverse( + TensorKit.blas_contract!, Duplicated, + (copy(C), Duplicated), (real(A), Duplicated), (pA, Const), + (B, Duplicated), (pB, Const), (pAB, Const), + (real(α), Active), (real(β), Active), + (TensorOperations.DefaultBackend(), Const), + (TensorOperations.DefaultAllocator(), Const); + atol, rtol, + testset_name = "blas_contract! reverse real(A) real(α) real(β)", + ) + EnzymeTestUtils.test_reverse( + TensorKit.blas_contract!, Duplicated, + (copy(C), Duplicated), (A, Duplicated), (pA, Const), + (real(B), Duplicated), (pB, Const), (pAB, Const), + (real(α), Active), (real(β), Active), + (TensorOperations.DefaultBackend(), Const), + (TensorOperations.DefaultAllocator(), Const); + atol, rtol, + testset_name = "blas_contract! reverse real(B) real(α) real(β)", + ) + EnzymeTestUtils.test_forward( + TensorKit.blas_contract!, Duplicated, + (copy(C), Duplicated), (A, Duplicated), (pA, Const), + (B, Duplicated), (pB, Const), (pAB, Const), + (real(α), Active), (real(β), Active), + (TensorOperations.DefaultBackend(), Const), + (TensorOperations.DefaultAllocator(), Const); + atol, rtol, + testset_name = "blas_contract! forward real(α) real(β)", + ) + EnzymeTestUtils.test_forward( + TensorKit.blas_contract!, Duplicated, + (copy(C), Duplicated), (real(A), Duplicated), (pA, Const), + (B, Duplicated), (pB, Const), (pAB, Const), + (real(α), Active), (real(β), Active), + (TensorOperations.DefaultBackend(), Const), + (TensorOperations.DefaultAllocator(), Const); + atol, rtol, + testset_name = "blas_contract! forward real(A) real(α) real(β)", + ) + EnzymeTestUtils.test_forward( + TensorKit.blas_contract!, Duplicated, + (copy(C), Duplicated), (A, Duplicated), (pA, Const), + (real(B), Duplicated), (pB, Const), (pAB, Const), + (real(α), Active), (real(β), Active), + (TensorOperations.DefaultBackend(), Const), + (TensorOperations.DefaultAllocator(), Const); + atol, rtol, + testset_name = "blas_contract! forward real(B) real(α) real(β)", + ) end end end diff --git a/test/enzyme-vi-to/inner.jl b/test/enzyme-vi-to/inner.jl index 5df4a8017..d3d43a6eb 100644 --- a/test/enzyme-vi-to/inner.jl +++ b/test/enzyme-vi-to/inner.jl @@ -7,23 +7,23 @@ using Random, FiniteDifferences spacelist = ad_spacelist(fast_tests) eltypes = (Float64, ComplexF64) +is_ci = get(ENV, "CI", "false") == "true" + +rTs = is_ci ? (Active,) : (Active, Const) +fTs = is_ci ? (Duplicated,) : (Duplicated, Const) + @testset "Enzyme - VectorInterface" begin @timedtestset "$(TensorKit.type_repr(sectortype(eltype(V)))) ($T)" for V in spacelist, T in eltypes @testset for TC in (Duplicated,), TA in (Duplicated,), f in (identity, adjoint) atol = default_tol(T) rtol = default_tol(T) - # see https://github.com/QuantumKitHub/TensorKit.jl/issues/457 - if VERSION < v"1.11.0-rc" && sectortype(eltype(V)) == Trivial - CV = V[1] ⊗ V[2] ← V[4] ⊗ V[5] - else - CV = V[1] ⊗ V[2] ← V[3] ⊗ V[4] ⊗ V[5] - end + CV = V[1] ⊗ V[2] ← V[3] ⊗ V[4] ⊗ V[5] C = randn(T, CV) A = randn(T, CV) - for RT in (Active, Const) + for RT in rTs EnzymeTestUtils.test_reverse(inner, RT, (f(C), TC), (f(A), TA); atol, rtol) end - for RT in (Duplicated, Const) + for RT in fTs EnzymeTestUtils.test_forward(inner, RT, (f(C), TC), (f(A), TA); atol, rtol) end end diff --git a/test/enzyme-vi-to/scale.jl b/test/enzyme-vi-to/scale.jl index 8d3f109d5..a11875d92 100644 --- a/test/enzyme-vi-to/scale.jl +++ b/test/enzyme-vi-to/scale.jl @@ -7,19 +7,19 @@ using Random spacelist = ad_spacelist(fast_tests) eltypes = (Float64, ComplexF64) +is_ci = get(ENV, "CI", "false") == "true" + +rTαs = is_ci ? (Active,) : (Active, Const) +fTαs = is_ci ? (Duplicated,) : (Duplicated, Const) + @testset "Enzyme - VectorInterface (scale!)" begin @timedtestset "$(TensorKit.type_repr(sectortype(eltype(V)))) ($T)" for V in spacelist, T in eltypes atol = default_tol(T) rtol = default_tol(T) α = randn(T) - # see https://github.com/QuantumKitHub/TensorKit.jl/issues/457 - if VERSION < v"1.11.0-rc" && sectortype(eltype(V)) == Trivial - CV = V[1] ⊗ V[2] ← V[4] ⊗ V[5] - else - CV = V[1] ⊗ V[2] ← V[3] ⊗ V[4] ⊗ V[5] - end + CV = V[1] ⊗ V[2] ← V[3] ⊗ V[4] ⊗ V[5] @testset for TC in (Duplicated,) - for Tα in (Active, Const) + for Tα in rTαs C = randn(T, CV) EnzymeTestUtils.test_reverse(scale!, TC, (C, TC), (α, Tα); atol, rtol) C = randn(T, CV) @@ -30,7 +30,7 @@ eltypes = (Float64, ComplexF64) EnzymeTestUtils.test_reverse(scale!, TC, (fc(C), TC), (fa(A), TA), (α, Tα); atol, rtol) end end - for Tα in (Duplicated, Const) + for Tα in fTαs C = randn(T, CV) EnzymeTestUtils.test_forward(scale!, TC, (C, TC), (α, Tα); atol, rtol) C = randn(T, CV) diff --git a/test/enzyme-vi-to/trace.jl b/test/enzyme-vi-to/trace.jl index 5a805d1ac..958af2e11 100644 --- a/test/enzyme-vi-to/trace.jl +++ b/test/enzyme-vi-to/trace.jl @@ -15,46 +15,44 @@ fTβs = is_ci ? (Duplicated,) : (Const, Duplicated) TCs = is_ci ? (Duplicated,) : (Const, Duplicated) TAs = is_ci ? (Duplicated,) : (Const, Duplicated) -if !(is_ci && Sys.iswindows() && VERSION < v"1.11.0-rc") - @timedtestset "Enzyme - TensorOperations (trace)" begin - @timedtestset verbose = true "$(TensorKit.type_repr(sectortype(eltype(V)))) ($T)" for V in spacelist, T in eltypes - atol = default_tol(T) - rtol = default_tol(T) - symmetricbraiding = BraidingStyle(sectortype(eltype(V))) isa SymmetricBraiding - symmetricbraiding && @timedtestset "trace_permute!" begin - k1 = rand(0:2) - k2 = rand(1:2) - V1 = map(v -> rand(Bool) ? v' : v, rand(V, k1)) - V2 = map(v -> rand(Bool) ? v' : v, rand(V, k2)) +@timedtestset "Enzyme - TensorOperations (trace)" begin + @timedtestset verbose = true "$(TensorKit.type_repr(sectortype(eltype(V)))) ($T)" for V in spacelist, T in eltypes + atol = default_tol(T) + rtol = default_tol(T) + symmetricbraiding = BraidingStyle(sectortype(eltype(V))) isa SymmetricBraiding + symmetricbraiding && @timedtestset "trace_permute!" begin + k1 = rand(0:2) + k2 = rand(1:2) + V1 = map(v -> rand(Bool) ? v' : v, rand(V, k1)) + V2 = map(v -> rand(Bool) ? v' : v, rand(V, k2)) - (_p, _q) = randindextuple(k1 + 2 * k2, k1) - p = _repartition(_p, rand(0:k1)) - q = _repartition(_q, k2) - ip = _repartition(invperm(linearize((_p, _q))), rand(0:(k1 + 2 * k2))) - A = randn(T, permute(prod(V1) ⊗ prod(V2) ← prod(V2), ip)) + (_p, _q) = randindextuple(k1 + 2 * k2, k1) + p = _repartition(_p, rand(0:k1)) + q = _repartition(_q, k2) + ip = _repartition(invperm(linearize((_p, _q))), rand(0:(k1 + 2 * k2))) + A = randn(T, permute(prod(V1) ⊗ prod(V2) ← prod(V2), ip)) - α = randn(T) - β = randn(T) - C = randn!(TensorOperations.tensoralloc_add(T, A, p, false, Val(false))) - for TC in TCs, TA in TAs - for Tα in rTαs, Tβ in rTβs - EnzymeTestUtils.test_reverse( - TensorKit.trace_permute!, TC, - (copy(C), TC), (A, TA), (p, Const), (q, Const), - (α, Tα), (β, Tβ), (TensorOperations.DefaultBackend(), Const); - atol, rtol, - testset_name = "trace_permute! reverse TC $TC TA $TA Tα $Tα Tβ $Tβ", - ) - end - for Tα in fTαs, Tβ in fTβs - EnzymeTestUtils.test_forward( - TensorKit.trace_permute!, TC, - (copy(C), TC), (A, TA), (p, Const), (q, Const), - (α, Tα), (β, Tβ), (TensorOperations.DefaultBackend(), Const); - atol, rtol, - testset_name = "trace_permute! forward TC $TC TA $TA Tα $Tα Tβ $Tβ", - ) - end + α = randn(T) + β = randn(T) + C = randn!(TensorOperations.tensoralloc_add(T, A, p, false, Val(false))) + for TC in TCs, TA in TAs + for Tα in rTαs, Tβ in rTβs + EnzymeTestUtils.test_reverse( + TensorKit.trace_permute!, TC, + (copy(C), TC), (A, TA), (p, Const), (q, Const), + (α, Tα), (β, Tβ), (TensorOperations.DefaultBackend(), Const); + atol, rtol, + testset_name = "trace_permute! reverse TC $TC TA $TA Tα $Tα Tβ $Tβ", + ) + end + for Tα in fTαs, Tβ in fTβs + EnzymeTestUtils.test_forward( + TensorKit.trace_permute!, TC, + (copy(C), TC), (A, TA), (p, Const), (q, Const), + (α, Tα), (β, Tβ), (TensorOperations.DefaultBackend(), Const); + atol, rtol, + testset_name = "trace_permute! forward TC $TC TA $TA Tα $Tα Tβ $Tβ", + ) end end end From e795f8dcfea27c9f7a00f59b2ad756ea0c232463 Mon Sep 17 00:00:00 2001 From: Katharine Hyatt Date: Thu, 30 Jul 2026 09:00:54 +0200 Subject: [PATCH 3/3] Try trimming scale tests a bit more --- test/enzyme-vi-to/scale.jl | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/test/enzyme-vi-to/scale.jl b/test/enzyme-vi-to/scale.jl index a11875d92..44508612a 100644 --- a/test/enzyme-vi-to/scale.jl +++ b/test/enzyme-vi-to/scale.jl @@ -18,26 +18,20 @@ fTαs = is_ci ? (Duplicated,) : (Duplicated, Const) rtol = default_tol(T) α = randn(T) CV = V[1] ⊗ V[2] ← V[3] ⊗ V[4] ⊗ V[5] + C = randn(T, CV) + A = randn(T, CV) @testset for TC in (Duplicated,) for Tα in rTαs - C = randn(T, CV) EnzymeTestUtils.test_reverse(scale!, TC, (C, TC), (α, Tα); atol, rtol) - C = randn(T, CV) - EnzymeTestUtils.test_reverse(scale!, TC, (C', TC), (α, Tα); atol, rtol) + !is_ci && EnzymeTestUtils.test_reverse(scale!, TC, (C', TC), (α, Tα); atol, rtol) @testset for TA in (Duplicated,), (fc, fa) in ((identity, identity), (adjoint, adjoint)) - C = randn(T, CV) - A = randn(T, CV) EnzymeTestUtils.test_reverse(scale!, TC, (fc(C), TC), (fa(A), TA), (α, Tα); atol, rtol) end end for Tα in fTαs - C = randn(T, CV) EnzymeTestUtils.test_forward(scale!, TC, (C, TC), (α, Tα); atol, rtol) - C = randn(T, CV) - EnzymeTestUtils.test_forward(scale!, TC, (C', TC), (α, Tα); atol, rtol) + !is_ci && EnzymeTestUtils.test_forward(scale!, TC, (C', TC), (α, Tα); atol, rtol) @testset for TA in (Duplicated,), (fc, fa) in ((identity, identity), (adjoint, adjoint)) - C = randn(T, CV) - A = randn(T, CV) EnzymeTestUtils.test_forward(scale!, TC, (fc(C), TC), (fa(A), TA), (α, Tα); atol, rtol) end end