From f52df7b0116511afc90944e37163147dabe44b1f Mon Sep 17 00:00:00 2001 From: Katharine Hyatt Date: Wed, 1 Jul 2026 21:09:24 +0200 Subject: [PATCH 1/7] Fix Enzyme index manipulation spaces to match Mooncake --- test/enzyme-indexmanipulations/braid.jl | 2 +- test/enzyme-indexmanipulations/flip.jl | 2 +- test/enzyme-indexmanipulations/insertunit.jl | 2 +- test/enzyme-indexmanipulations/permute.jl | 2 +- test/enzyme-indexmanipulations/removeunit.jl | 2 +- test/enzyme-indexmanipulations/transpose.jl | 2 +- test/enzyme-indexmanipulations/twist.jl | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/enzyme-indexmanipulations/braid.jl b/test/enzyme-indexmanipulations/braid.jl index 28d1e52ba..6717f0155 100644 --- a/test/enzyme-indexmanipulations/braid.jl +++ b/test/enzyme-indexmanipulations/braid.jl @@ -16,7 +16,7 @@ Tβs = is_ci ? (Active,) : (Active, Const) atol = default_tol(T) rtol = default_tol(T) Vstr = TensorKit.type_repr(sectortype(eltype(V))) - A = randn(T, V[1] ⊗ V[2] ← V[4] ⊗ V[5]) + A = randn(T, V[1] ⊗ V[2] ← (V[3] ⊗ V[4] ⊗ V[5])') α = randn(T) β = randn(T) p = randcircshift(numout(A), numin(A)) diff --git a/test/enzyme-indexmanipulations/flip.jl b/test/enzyme-indexmanipulations/flip.jl index 8afe4e914..37db5189d 100644 --- a/test/enzyme-indexmanipulations/flip.jl +++ b/test/enzyme-indexmanipulations/flip.jl @@ -10,7 +10,7 @@ eltypes = (Float64, ComplexF64) @timedtestset "$(TensorKit.type_repr(sectortype(eltype(V)))) ($T) TA ($TA)" for V in spacelist, T in eltypes, TA in (Duplicated,) atol = default_tol(T) rtol = default_tol(T) - A = randn(T, V[1] ⊗ V[2] ← V[4] ⊗ V[5]) + A = randn(T, V[1] ⊗ V[2] ← (V[3] ⊗ V[4] ⊗ V[5])') EnzymeTestUtils.test_reverse(flip, TA, (A, TA), (1, Const); atol, rtol, fkwargs = (inv = false,)) EnzymeTestUtils.test_reverse(flip, TA, (A, TA), [1, 3]; atol, rtol, fkwargs = (inv = true,)) EnzymeTestUtils.test_reverse(flip, TA, (A, TA), (1, Const); atol, rtol) diff --git a/test/enzyme-indexmanipulations/insertunit.jl b/test/enzyme-indexmanipulations/insertunit.jl index 15e02d22c..69c299b0e 100644 --- a/test/enzyme-indexmanipulations/insertunit.jl +++ b/test/enzyme-indexmanipulations/insertunit.jl @@ -10,7 +10,7 @@ eltypes = (Float64, ComplexF64) @timedtestset verbose = true "$(TensorKit.type_repr(sectortype(eltype(V)))) ($T)" for V in spacelist, T in eltypes, TA in (Duplicated,) atol = default_tol(T) rtol = default_tol(T) - A = randn(T, V[1] ⊗ V[2] ← V[4] ⊗ V[5]) + A = randn(T, V[1] ⊗ V[2] ← (V[3] ⊗ V[4] ⊗ V[5])') @testset for insertunit in (insertleftunit, insertrightunit) EnzymeTestUtils.test_reverse(insertunit, TA, (A, TA), (Val(1), Const); atol, rtol) EnzymeTestUtils.test_reverse(insertunit, TA, (A, TA), (Val(4), Const); atol, rtol) diff --git a/test/enzyme-indexmanipulations/permute.jl b/test/enzyme-indexmanipulations/permute.jl index a7f6126d6..e160c34b3 100644 --- a/test/enzyme-indexmanipulations/permute.jl +++ b/test/enzyme-indexmanipulations/permute.jl @@ -18,7 +18,7 @@ Tβs = is_ci ? (Active,) : (Active, Const) symmetricbraiding = BraidingStyle(sectortype(eltype(V))) isa SymmetricBraiding symmetricbraiding && @timedtestset "permute! Tα $Tα, Tβ $Tβ" for Tα in Tαs, Tβ in Tβs - A = randn(T, V[1] ⊗ V[2] ← V[4] ⊗ V[5]) + A = randn(T, V[1] ⊗ V[2] ← (V[3] ⊗ V[4] ⊗ V[5])') α = randn(T) β = randn(T) p = randindextuple(numind(A)) diff --git a/test/enzyme-indexmanipulations/removeunit.jl b/test/enzyme-indexmanipulations/removeunit.jl index 2249483be..3e64cb2cd 100644 --- a/test/enzyme-indexmanipulations/removeunit.jl +++ b/test/enzyme-indexmanipulations/removeunit.jl @@ -10,7 +10,7 @@ eltypes = (Float64, ComplexF64) @timedtestset verbose = true "$(TensorKit.type_repr(sectortype(eltype(V)))) ($T)" for V in spacelist, T in eltypes, TB in (Duplicated,) atol = default_tol(T) rtol = default_tol(T) - A = randn(T, V[1] ⊗ V[2] ← V[4] ⊗ V[5]) + A = randn(T, V[1] ⊗ V[2] ← (V[3] ⊗ V[4] ⊗ V[5])') for i in 1:2 B = insertleftunit(A, i; dual = rand(Bool)) EnzymeTestUtils.test_reverse(removeunit, TB, (B, TB), (Val(i), Const); atol, rtol, fkwargs = (copy = false,)) diff --git a/test/enzyme-indexmanipulations/transpose.jl b/test/enzyme-indexmanipulations/transpose.jl index bff2cb379..740f19fd9 100644 --- a/test/enzyme-indexmanipulations/transpose.jl +++ b/test/enzyme-indexmanipulations/transpose.jl @@ -17,7 +17,7 @@ Tβs = is_ci ? (Active,) : (Active, Const) @timedtestset "$(TensorKit.type_repr(sectortype(eltype(V)))) ($T)" for V in spacelist, T in eltypes atol = default_tol(T) rtol = default_tol(T) - A = randn(T, V[1] ⊗ V[2] ← V[4] ⊗ V[5]) + A = randn(T, V[1] ⊗ V[2] ← (V[3] ⊗ V[4] ⊗ V[5])') α = randn(T) β = randn(T) diff --git a/test/enzyme-indexmanipulations/twist.jl b/test/enzyme-indexmanipulations/twist.jl index c939c76d2..193a7e50d 100644 --- a/test/enzyme-indexmanipulations/twist.jl +++ b/test/enzyme-indexmanipulations/twist.jl @@ -12,7 +12,7 @@ eltypes = (Float64, ComplexF64) @timedtestset "$(TensorKit.type_repr(sectortype(eltype(V)))) ($T)" for V in spacelist, T in eltypes, TA in (Duplicated,) atol = default_tol(T) rtol = default_tol(T) - A = randn(T, V[1] ⊗ V[2] ← V[4] ⊗ V[5]) + A = randn(T, V[1] ⊗ V[2] ← (V[3] ⊗ V[4] ⊗ V[5])') if !(T <: Real && !(sectorscalartype(sectortype(A)) <: Real)) EnzymeTestUtils.test_reverse(twist!, TA, (A, TA), (1, Const); atol, rtol, fkwargs = (inv = false,)) EnzymeTestUtils.test_reverse(twist!, TA, (A, TA), ([1, 3], Const); atol, rtol, fkwargs = (inv = true,)) From c76930e34dc04e40966bec2d960455dcbfc38a9e Mon Sep 17 00:00:00 2001 From: Katharine Hyatt Date: Thu, 2 Jul 2026 10:12:53 -0400 Subject: [PATCH 2/7] Fix braiding check --- test/enzyme-indexmanipulations/twist.jl | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/test/enzyme-indexmanipulations/twist.jl b/test/enzyme-indexmanipulations/twist.jl index 193a7e50d..ec8f9cb11 100644 --- a/test/enzyme-indexmanipulations/twist.jl +++ b/test/enzyme-indexmanipulations/twist.jl @@ -13,11 +13,12 @@ eltypes = (Float64, ComplexF64) atol = default_tol(T) rtol = default_tol(T) A = randn(T, V[1] ⊗ V[2] ← (V[3] ⊗ V[4] ⊗ V[5])') - if !(T <: Real && !(sectorscalartype(sectortype(A)) <: Real)) - EnzymeTestUtils.test_reverse(twist!, TA, (A, TA), (1, Const); atol, rtol, fkwargs = (inv = false,)) - EnzymeTestUtils.test_reverse(twist!, TA, (A, TA), ([1, 3], Const); atol, rtol, fkwargs = (inv = true,)) - EnzymeTestUtils.test_reverse(twist!, TA, (A, TA), (1, Const); atol, rtol) - EnzymeTestUtils.test_reverse(twist!, TA, (A, TA), ([1, 3], Const); atol, rtol) + has_braiding = BraidingStyle(sectortype(eltype(V))) isa HasBraiding + if has_braiding && !(T <: Real && !(sectorscalartype(sectortype(A)) <: Real)) + EnzymeTestUtils.test_reverse(twist!, TA, (copy(A), TA), (1, Const); atol, rtol, fkwargs = (inv = false,)) + EnzymeTestUtils.test_reverse(twist!, TA, (copy(A), TA), ([1, 3], Const); atol, rtol, fkwargs = (inv = true,)) + EnzymeTestUtils.test_reverse(twist!, TA, (copy(A), TA), (1, Const); atol, rtol) + EnzymeTestUtils.test_reverse(twist!, TA, (copy(A), TA), ([1, 3], Const); atol, rtol) end end end From 3ca16fc141726ed8dfbc915267b218d730dbe071 Mon Sep 17 00:00:00 2001 From: Katharine Hyatt Date: Thu, 2 Jul 2026 10:14:17 -0400 Subject: [PATCH 3/7] And for braid test --- test/enzyme-indexmanipulations/braid.jl | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/test/enzyme-indexmanipulations/braid.jl b/test/enzyme-indexmanipulations/braid.jl index 6717f0155..91172a279 100644 --- a/test/enzyme-indexmanipulations/braid.jl +++ b/test/enzyme-indexmanipulations/braid.jl @@ -16,17 +16,20 @@ Tβs = is_ci ? (Active,) : (Active, Const) atol = default_tol(T) rtol = default_tol(T) Vstr = TensorKit.type_repr(sectortype(eltype(V))) - A = randn(T, V[1] ⊗ V[2] ← (V[3] ⊗ V[4] ⊗ V[5])') - α = randn(T) - β = randn(T) - p = randcircshift(numout(A), numin(A)) - levels = Tuple(randperm(numind(A))) - C = randn!(transpose(A, p)) - EnzymeTestUtils.test_reverse(TensorKit.braid!, Duplicated, (C, Duplicated), (A, Duplicated), (p, Const), (levels, Const), (α, Tα), (β, Tβ); atol, rtol, testset_name = "braid! V $Vstr Tα $Tα Tβ $Tβ") - if !(T <: Real) && !is_ci - EnzymeTestUtils.test_reverse(TensorKit.braid!, Duplicated, (C, Duplicated), (real(A), Duplicated), (p, Const), (levels, Const), (α, Tα), (β, Tβ); atol, rtol, testset_name = "braid! V $Vstr Tα $Tα Tβ $Tβ") - EnzymeTestUtils.test_reverse(TensorKit.braid!, Duplicated, (C, Duplicated), (A, Duplicated), (p, Const), (levels, Const), (real(α), Tα), (β, Tβ); atol, rtol, testset_name = "braid! V $Vstr Tα $Tα Tβ $Tβ") - EnzymeTestUtils.test_reverse(TensorKit.braid!, Duplicated, (C, Duplicated), (A, Duplicated), (p, Const), (levels, Const), (real(α), Tα), (real(β), Tβ); atol, rtol, testset_name = "braid! V $Vstr Tα $Tα Tβ $Tβ") + has_braiding = BraidingStyle(sectortype(eltype(V))) isa HasBraiding + if has_braiding + A = randn(T, V[1] ⊗ V[2] ← (V[3] ⊗ V[4] ⊗ V[5])') + α = randn(T) + β = randn(T) + p = randcircshift(numout(A), numin(A)) + levels = Tuple(randperm(numind(A))) + C = randn!(transpose(A, p)) + EnzymeTestUtils.test_reverse(TensorKit.braid!, Duplicated, (C, Duplicated), (A, Duplicated), (p, Const), (levels, Const), (α, Tα), (β, Tβ); atol, rtol, testset_name = "braid! V $Vstr Tα $Tα Tβ $Tβ") + if !(T <: Real) && !is_ci + EnzymeTestUtils.test_reverse(TensorKit.braid!, Duplicated, (C, Duplicated), (real(A), Duplicated), (p, Const), (levels, Const), (α, Tα), (β, Tβ); atol, rtol, testset_name = "braid! V $Vstr Tα $Tα Tβ $Tβ") + EnzymeTestUtils.test_reverse(TensorKit.braid!, Duplicated, (C, Duplicated), (A, Duplicated), (p, Const), (levels, Const), (real(α), Tα), (β, Tβ); atol, rtol, testset_name = "braid! V $Vstr Tα $Tα Tβ $Tβ") + EnzymeTestUtils.test_reverse(TensorKit.braid!, Duplicated, (C, Duplicated), (A, Duplicated), (p, Const), (levels, Const), (real(α), Tα), (real(β), Tβ); atol, rtol, testset_name = "braid! V $Vstr Tα $Tα Tβ $Tβ") + end end end end From 61ee215871a6f8d87214086e768bcfcd8206229d Mon Sep 17 00:00:00 2001 From: Katharine Hyatt Date: Thu, 2 Jul 2026 12:11:51 -0400 Subject: [PATCH 4/7] Try to help out flip and transpose --- test/enzyme-indexmanipulations/flip.jl | 13 ++++++++----- test/enzyme-indexmanipulations/transpose.jl | 10 +++++----- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/test/enzyme-indexmanipulations/flip.jl b/test/enzyme-indexmanipulations/flip.jl index 37db5189d..1349fbc62 100644 --- a/test/enzyme-indexmanipulations/flip.jl +++ b/test/enzyme-indexmanipulations/flip.jl @@ -10,10 +10,13 @@ eltypes = (Float64, ComplexF64) @timedtestset "$(TensorKit.type_repr(sectortype(eltype(V)))) ($T) TA ($TA)" for V in spacelist, T in eltypes, TA in (Duplicated,) atol = default_tol(T) rtol = default_tol(T) - A = randn(T, V[1] ⊗ V[2] ← (V[3] ⊗ V[4] ⊗ V[5])') - EnzymeTestUtils.test_reverse(flip, TA, (A, TA), (1, Const); atol, rtol, fkwargs = (inv = false,)) - EnzymeTestUtils.test_reverse(flip, TA, (A, TA), [1, 3]; atol, rtol, fkwargs = (inv = true,)) - EnzymeTestUtils.test_reverse(flip, TA, (A, TA), (1, Const); atol, rtol) - EnzymeTestUtils.test_reverse(flip, TA, (A, TA), ([1, 3], Const); atol, rtol) + has_braiding = BraidingStyle(sectortype(eltype(V))) isa HasBraiding + if has_braiding + A = randn(T, V[1] ⊗ V[2] ← (V[3] ⊗ V[4] ⊗ V[5])') + EnzymeTestUtils.test_reverse(flip, TA, (A, TA), (1, Const); atol, rtol, fkwargs = (inv = false,)) + EnzymeTestUtils.test_reverse(flip, TA, (A, TA), [1, 3]; atol, rtol, fkwargs = (inv = true,)) + EnzymeTestUtils.test_reverse(flip, TA, (A, TA), (1, Const); atol, rtol) + EnzymeTestUtils.test_reverse(flip, TA, (A, TA), ([1, 3], Const); atol, rtol) + end end end diff --git a/test/enzyme-indexmanipulations/transpose.jl b/test/enzyme-indexmanipulations/transpose.jl index 740f19fd9..f5e685746 100644 --- a/test/enzyme-indexmanipulations/transpose.jl +++ b/test/enzyme-indexmanipulations/transpose.jl @@ -24,13 +24,13 @@ Tβs = is_ci ? (Active,) : (Active, Const) # repeat a couple times to get some distribution of arrows p = randcircshift(numout(A), numin(A)) C = randn!(transpose(A, p)) - EnzymeTestUtils.test_reverse(TensorKit.transpose!, Duplicated, (C, Duplicated), (A, Duplicated), (p, Const), (One(), Const), (Zero(), Const); atol, rtol) + EnzymeTestUtils.test_reverse(TensorKit.transpose!, Duplicated, (copy(C), Duplicated), (A, Duplicated), (p, Const), (One(), Const), (Zero(), Const); atol, rtol) @testset for Tα in Tαs, Tβ in Tβs - EnzymeTestUtils.test_reverse(TensorKit.transpose!, Duplicated, (C, Duplicated), (A, Duplicated), (p, Const), (α, Tα), (β, Tβ); atol, rtol) + EnzymeTestUtils.test_reverse(TensorKit.transpose!, Duplicated, (copy(C), Duplicated), (A, Duplicated), (p, Const), (α, Tα), (β, Tβ); atol, rtol) if !(T <: Real) && !is_ci - EnzymeTestUtils.test_reverse(TensorKit.transpose!, Duplicated, (C, Duplicated), (real(A), Duplicated), (p, Const), (α, Tα), (β, Tβ); atol, rtol) - EnzymeTestUtils.test_reverse(TensorKit.transpose!, Duplicated, (C, Duplicated), (A, Duplicated), (p, Const), (real(α), Tα), (β, Tβ); atol, rtol) - EnzymeTestUtils.test_reverse(TensorKit.transpose!, Duplicated, (C, Duplicated), (real(A), Duplicated), (p, Const), (real(α), Tα), (β, Tβ); atol, rtol) + EnzymeTestUtils.test_reverse(TensorKit.transpose!, Duplicated, (copy(C), Duplicated), (real(A), Duplicated), (p, Const), (α, Tα), (β, Tβ); atol, rtol) + EnzymeTestUtils.test_reverse(TensorKit.transpose!, Duplicated, (copy(C), Duplicated), (A, Duplicated), (p, Const), (real(α), Tα), (β, Tβ); atol, rtol) + EnzymeTestUtils.test_reverse(TensorKit.transpose!, Duplicated, (copy(C), Duplicated), (real(A), Duplicated), (p, Const), (real(α), Tα), (β, Tβ); atol, rtol) end end end From 9fe6ffa464803c50d657f01cf7dc287f5ebcdf92 Mon Sep 17 00:00:00 2001 From: Katharine Hyatt Date: Thu, 2 Jul 2026 14:29:31 -0400 Subject: [PATCH 5/7] Run less transpose --- test/enzyme-indexmanipulations/transpose.jl | 34 ++++++++++----------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/test/enzyme-indexmanipulations/transpose.jl b/test/enzyme-indexmanipulations/transpose.jl index f5e685746..9e6703eb1 100644 --- a/test/enzyme-indexmanipulations/transpose.jl +++ b/test/enzyme-indexmanipulations/transpose.jl @@ -13,25 +13,23 @@ is_ci = get(ENV, "CI", "false") == "true" Tαs = is_ci ? (Active,) : (Active, Const) Tβs = is_ci ? (Active,) : (Active, Const) -@timedtestset "Enzyme - Index Manipulations (transpose!):" begin - @timedtestset "$(TensorKit.type_repr(sectortype(eltype(V)))) ($T)" for V in spacelist, T in eltypes - atol = default_tol(T) - rtol = default_tol(T) - A = randn(T, V[1] ⊗ V[2] ← (V[3] ⊗ V[4] ⊗ V[5])') - α = randn(T) - β = randn(T) +@timedtestset "Enzyme - Index Manipulations (transpose!) $(TensorKit.type_repr(sectortype(eltype(V)))) ($T)" for V in spacelist, T in eltypes + atol = default_tol(T) + rtol = default_tol(T) + A = randn(T, V[1] ⊗ V[2] ← (V[3] ⊗ V[4] ⊗ V[5])') + α = randn(T) + β = randn(T) - # repeat a couple times to get some distribution of arrows - p = randcircshift(numout(A), numin(A)) - C = randn!(transpose(A, p)) - EnzymeTestUtils.test_reverse(TensorKit.transpose!, Duplicated, (copy(C), Duplicated), (A, Duplicated), (p, Const), (One(), Const), (Zero(), Const); atol, rtol) - @testset for Tα in Tαs, Tβ in Tβs - EnzymeTestUtils.test_reverse(TensorKit.transpose!, Duplicated, (copy(C), Duplicated), (A, Duplicated), (p, Const), (α, Tα), (β, Tβ); atol, rtol) - if !(T <: Real) && !is_ci - EnzymeTestUtils.test_reverse(TensorKit.transpose!, Duplicated, (copy(C), Duplicated), (real(A), Duplicated), (p, Const), (α, Tα), (β, Tβ); atol, rtol) - EnzymeTestUtils.test_reverse(TensorKit.transpose!, Duplicated, (copy(C), Duplicated), (A, Duplicated), (p, Const), (real(α), Tα), (β, Tβ); atol, rtol) - EnzymeTestUtils.test_reverse(TensorKit.transpose!, Duplicated, (copy(C), Duplicated), (real(A), Duplicated), (p, Const), (real(α), Tα), (β, Tβ); atol, rtol) - end + # repeat a couple times to get some distribution of arrows + p = randcircshift(numout(A), numin(A)) + C = randn!(transpose(A, p)) + !is_ci && EnzymeTestUtils.test_reverse(TensorKit.transpose!, Duplicated, (copy(C), Duplicated), (A, Duplicated), (p, Const), (One(), Const), (Zero(), Const); atol, rtol) + @testset for Tα in Tαs, Tβ in Tβs + EnzymeTestUtils.test_reverse(TensorKit.transpose!, Duplicated, (copy(C), Duplicated), (A, Duplicated), (p, Const), (α, Tα), (β, Tβ); atol, rtol) + if !(T <: Real) && !is_ci + EnzymeTestUtils.test_reverse(TensorKit.transpose!, Duplicated, (copy(C), Duplicated), (real(A), Duplicated), (p, Const), (α, Tα), (β, Tβ); atol, rtol) + EnzymeTestUtils.test_reverse(TensorKit.transpose!, Duplicated, (copy(C), Duplicated), (A, Duplicated), (p, Const), (real(α), Tα), (β, Tβ); atol, rtol) + EnzymeTestUtils.test_reverse(TensorKit.transpose!, Duplicated, (copy(C), Duplicated), (real(A), Duplicated), (p, Const), (real(α), Tα), (β, Tβ); atol, rtol) end end end From a542f4246fb1235daa74e72469d8e9ba10eaf81d Mon Sep 17 00:00:00 2001 From: Katharine Hyatt Date: Thu, 2 Jul 2026 17:32:55 -0400 Subject: [PATCH 6/7] Try without permute on 1.10 --- test/enzyme-indexmanipulations/permute.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/enzyme-indexmanipulations/permute.jl b/test/enzyme-indexmanipulations/permute.jl index e160c34b3..d78ec1e41 100644 --- a/test/enzyme-indexmanipulations/permute.jl +++ b/test/enzyme-indexmanipulations/permute.jl @@ -11,8 +11,9 @@ is_ci = get(ENV, "CI", "false") == "true" Tαs = is_ci ? (Active,) : (Active, Const) Tβs = is_ci ? (Active,) : (Active, Const) -@timedtestset "Enzyme - Index Manipulations (permute!):" begin - @timedtestset "$(TensorKit.type_repr(sectortype(eltype(V)))) ($T)" for V in spacelist, T in eltypes +if VERSION >= v"1.11.0-rc" # segfault issues on 1.10 + @timedtestset "Enzyme - Index Manipulations (permute!): $(TensorKit.type_repr(sectortype(eltype(V)))) ($T)" for V in spacelist, T in eltypes + println(TensorKit.type_repr(sectortype(eltype(V)))) atol = default_tol(T) rtol = default_tol(T) symmetricbraiding = BraidingStyle(sectortype(eltype(V))) isa SymmetricBraiding From 885de58dcfda9f35426bf2027865a11ca9403f44 Mon Sep 17 00:00:00 2001 From: Katharine Hyatt Date: Sat, 4 Jul 2026 16:01:53 -0400 Subject: [PATCH 7/7] Try splitting again --- .../flip.jl | 0 .../twist.jl | 0 .../braid.jl | 32 +++++++++++++++++ .../permute.jl | 0 .../transpose.jl | 0 .../insertunit.jl | 0 .../removeunit.jl | 0 test/enzyme-indexmanipulations/braid.jl | 35 ------------------- 8 files changed, 32 insertions(+), 35 deletions(-) rename test/{enzyme-indexmanipulations => enzyme-indexmanipulations-flip-twist}/flip.jl (100%) rename test/{enzyme-indexmanipulations => enzyme-indexmanipulations-flip-twist}/twist.jl (100%) create mode 100644 test/enzyme-indexmanipulations-transform/braid.jl rename test/{enzyme-indexmanipulations => enzyme-indexmanipulations-transform}/permute.jl (100%) rename test/{enzyme-indexmanipulations => enzyme-indexmanipulations-transform}/transpose.jl (100%) rename test/{enzyme-indexmanipulations => enzyme-indexmanipulations-unit}/insertunit.jl (100%) rename test/{enzyme-indexmanipulations => enzyme-indexmanipulations-unit}/removeunit.jl (100%) delete mode 100644 test/enzyme-indexmanipulations/braid.jl diff --git a/test/enzyme-indexmanipulations/flip.jl b/test/enzyme-indexmanipulations-flip-twist/flip.jl similarity index 100% rename from test/enzyme-indexmanipulations/flip.jl rename to test/enzyme-indexmanipulations-flip-twist/flip.jl diff --git a/test/enzyme-indexmanipulations/twist.jl b/test/enzyme-indexmanipulations-flip-twist/twist.jl similarity index 100% rename from test/enzyme-indexmanipulations/twist.jl rename to test/enzyme-indexmanipulations-flip-twist/twist.jl diff --git a/test/enzyme-indexmanipulations-transform/braid.jl b/test/enzyme-indexmanipulations-transform/braid.jl new file mode 100644 index 000000000..ae5f055ad --- /dev/null +++ b/test/enzyme-indexmanipulations-transform/braid.jl @@ -0,0 +1,32 @@ +using Test, TestExtras +using TensorKit +using TensorOperations +using Enzyme, EnzymeTestUtils +using Random + +spacelist = ad_spacelist(fast_tests) +eltypes = (Float64, ComplexF64) + +is_ci = get(ENV, "CI", "false") == "true" +Tαs = is_ci ? (Active,) : (Active, Const) +Tβs = is_ci ? (Active,) : (Active, Const) + +@timedtestset "Enzyme - Index Manipulations (braid!) $(TensorKit.type_repr(sectortype(eltype(V)))) ($T) Tα $Tα Tβ $Tβ" for V in spacelist, T in eltypes, Tα in Tαs, Tβ in Tβs + atol = default_tol(T) + rtol = default_tol(T) + has_braiding = BraidingStyle(sectortype(eltype(V))) isa HasBraiding + if has_braiding + A = randn(T, V[1] ⊗ V[2] ← (V[3] ⊗ V[4] ⊗ V[5])') + α = randn(T) + β = randn(T) + p = randcircshift(numout(A), numin(A)) + levels = Tuple(randperm(numind(A))) + C = randn!(transpose(A, p)) + EnzymeTestUtils.test_reverse(TensorKit.braid!, Duplicated, (C, Duplicated), (A, Duplicated), (p, Const), (levels, Const), (α, Tα), (β, Tβ); atol, rtol, testset_name = "braid! V $Vstr Tα $Tα Tβ $Tβ") + if !(T <: Real) && !is_ci + EnzymeTestUtils.test_reverse(TensorKit.braid!, Duplicated, (C, Duplicated), (real(A), Duplicated), (p, Const), (levels, Const), (α, Tα), (β, Tβ); atol, rtol, testset_name = "braid! V $Vstr Tα $Tα Tβ $Tβ") + EnzymeTestUtils.test_reverse(TensorKit.braid!, Duplicated, (C, Duplicated), (A, Duplicated), (p, Const), (levels, Const), (real(α), Tα), (β, Tβ); atol, rtol, testset_name = "braid! V $Vstr Tα $Tα Tβ $Tβ") + EnzymeTestUtils.test_reverse(TensorKit.braid!, Duplicated, (C, Duplicated), (A, Duplicated), (p, Const), (levels, Const), (real(α), Tα), (real(β), Tβ); atol, rtol, testset_name = "braid! V $Vstr Tα $Tα Tβ $Tβ") + end + end +end diff --git a/test/enzyme-indexmanipulations/permute.jl b/test/enzyme-indexmanipulations-transform/permute.jl similarity index 100% rename from test/enzyme-indexmanipulations/permute.jl rename to test/enzyme-indexmanipulations-transform/permute.jl diff --git a/test/enzyme-indexmanipulations/transpose.jl b/test/enzyme-indexmanipulations-transform/transpose.jl similarity index 100% rename from test/enzyme-indexmanipulations/transpose.jl rename to test/enzyme-indexmanipulations-transform/transpose.jl diff --git a/test/enzyme-indexmanipulations/insertunit.jl b/test/enzyme-indexmanipulations-unit/insertunit.jl similarity index 100% rename from test/enzyme-indexmanipulations/insertunit.jl rename to test/enzyme-indexmanipulations-unit/insertunit.jl diff --git a/test/enzyme-indexmanipulations/removeunit.jl b/test/enzyme-indexmanipulations-unit/removeunit.jl similarity index 100% rename from test/enzyme-indexmanipulations/removeunit.jl rename to test/enzyme-indexmanipulations-unit/removeunit.jl diff --git a/test/enzyme-indexmanipulations/braid.jl b/test/enzyme-indexmanipulations/braid.jl deleted file mode 100644 index 91172a279..000000000 --- a/test/enzyme-indexmanipulations/braid.jl +++ /dev/null @@ -1,35 +0,0 @@ -using Test, TestExtras -using TensorKit -using TensorOperations -using Enzyme, EnzymeTestUtils -using Random - -spacelist = ad_spacelist(fast_tests) -eltypes = (Float64, ComplexF64) - -is_ci = get(ENV, "CI", "false") == "true" -Tαs = is_ci ? (Active,) : (Active, Const) -Tβs = is_ci ? (Active,) : (Active, Const) - -@timedtestset "Enzyme - Index Manipulations (braid!):" begin - @timedtestset "$(TensorKit.type_repr(sectortype(eltype(V)))) ($T) Tα $Tα Tβ $Tβ" for V in spacelist, T in eltypes, Tα in Tαs, Tβ in Tβs - atol = default_tol(T) - rtol = default_tol(T) - Vstr = TensorKit.type_repr(sectortype(eltype(V))) - has_braiding = BraidingStyle(sectortype(eltype(V))) isa HasBraiding - if has_braiding - A = randn(T, V[1] ⊗ V[2] ← (V[3] ⊗ V[4] ⊗ V[5])') - α = randn(T) - β = randn(T) - p = randcircshift(numout(A), numin(A)) - levels = Tuple(randperm(numind(A))) - C = randn!(transpose(A, p)) - EnzymeTestUtils.test_reverse(TensorKit.braid!, Duplicated, (C, Duplicated), (A, Duplicated), (p, Const), (levels, Const), (α, Tα), (β, Tβ); atol, rtol, testset_name = "braid! V $Vstr Tα $Tα Tβ $Tβ") - if !(T <: Real) && !is_ci - EnzymeTestUtils.test_reverse(TensorKit.braid!, Duplicated, (C, Duplicated), (real(A), Duplicated), (p, Const), (levels, Const), (α, Tα), (β, Tβ); atol, rtol, testset_name = "braid! V $Vstr Tα $Tα Tβ $Tβ") - EnzymeTestUtils.test_reverse(TensorKit.braid!, Duplicated, (C, Duplicated), (A, Duplicated), (p, Const), (levels, Const), (real(α), Tα), (β, Tβ); atol, rtol, testset_name = "braid! V $Vstr Tα $Tα Tβ $Tβ") - EnzymeTestUtils.test_reverse(TensorKit.braid!, Duplicated, (C, Duplicated), (A, Duplicated), (p, Const), (levels, Const), (real(α), Tα), (real(β), Tβ); atol, rtol, testset_name = "braid! V $Vstr Tα $Tα Tβ $Tβ") - end - end - end -end