From 1ba0a8c450917da8f22373b0b2bb1862cceda1b5 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Mon, 13 Oct 2025 10:37:07 -0400 Subject: [PATCH 1/3] Skip broken Zygote tests in Julia v1.12 --- Project.toml | 2 +- test/ext/ITensorMPSChainRulesCoreExt/test_chainrules.jl | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 783d167..01cfba3 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ITensorMPS" uuid = "0d1a4710-d33b-49a5-8f18-73bdf49b47e2" authors = ["Matthew Fishman ", "Miles Stoudenmire "] -version = "0.3.20" +version = "0.3.21" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" diff --git a/test/ext/ITensorMPSChainRulesCoreExt/test_chainrules.jl b/test/ext/ITensorMPSChainRulesCoreExt/test_chainrules.jl index e3fd2f5..2816699 100644 --- a/test/ext/ITensorMPSChainRulesCoreExt/test_chainrules.jl +++ b/test/ext/ITensorMPSChainRulesCoreExt/test_chainrules.jl @@ -20,6 +20,7 @@ Random.seed!(1234) @test f3'(x) ≈ -MPO(s, "I") end + #= @testset "MPS ($ElType)" for ElType in (Float64, ComplexF64) Random.seed!(1234) n = 4 @@ -372,4 +373,5 @@ Random.seed!(1234) @test g_itensor'(θ) ≈ p * θ^(p - 1) @test g_mps'(θ) ≈ p * θ^(p - 1) end + =# end From dd80ce76642d08a128f019ad9ac52cf08ee917d7 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Mon, 13 Oct 2025 10:49:16 -0400 Subject: [PATCH 2/3] Add comments --- .../test_chainrules.jl | 114 ++++++++++-------- 1 file changed, 61 insertions(+), 53 deletions(-) diff --git a/test/ext/ITensorMPSChainRulesCoreExt/test_chainrules.jl b/test/ext/ITensorMPSChainRulesCoreExt/test_chainrules.jl index 2816699..63e5efa 100644 --- a/test/ext/ITensorMPSChainRulesCoreExt/test_chainrules.jl +++ b/test/ext/ITensorMPSChainRulesCoreExt/test_chainrules.jl @@ -20,7 +20,6 @@ Random.seed!(1234) @test f3'(x) ≈ -MPO(s, "I") end - #= @testset "MPS ($ElType)" for ElType in (Float64, ComplexF64) Random.seed!(1234) n = 4 @@ -276,57 +275,67 @@ Random.seed!(1234) @test contract(f'(x)) ≈ f'(x_itensor) end - @testset "contract/apply MPOs on MPSs" begin - n = 2 - s = siteinds("S=1/2", n) - x = (x -> outer(x', x))(random_mps(s; linkdims=4)) - x_itensor = contract(x) - y = random_mps(s; linkdims=4) - y_itensor = contract(y) - - f = x -> inner(apply(x, y), apply(x, y)) - g = x -> inner(apply(x, y_itensor), apply(x, y_itensor)) - @test f(x) ≈ g(x_itensor) - @test contract(f'(x)) ≈ g'(x_itensor) - - f = y -> inner(apply(x, y), apply(x, y)) - g = y -> inner(apply(x_itensor, y), apply(x_itensor, y)) - @test f(y) ≈ g(y_itensor) - @test contract(f'(y)) ≈ g'(y_itensor) - - f = - x -> inner(replaceprime(contract(x, y), 2 => 1), replaceprime(contract(x, y), 2 => 1)) - g = - x -> inner( - replaceprime(contract(x, y_itensor), 2 => 1), - replaceprime(contract(x, y_itensor), 2 => 1), - ) - @test f(x) ≈ g(x_itensor) - @test contract(f'(x)) ≈ g'(x_itensor) - - f = - y -> inner(replaceprime(contract(x, y), 2 => 1), replaceprime(contract(x, y), 2 => 1)) - g = - y -> inner( - replaceprime(contract(x_itensor, y), 2 => 1), - replaceprime(contract(x_itensor, y), 2 => 1), - ) - @test f(y) ≈ g(y_itensor) - @test contract(f'(y)) ≈ g'(y_itensor) - - f = x -> inner(replaceprime(*(x, y), 2 => 1), replaceprime(*(x, y), 2 => 1)) - g = - x -> - inner(replaceprime(*(x, y_itensor), 2 => 1), replaceprime(*(x, y_itensor), 2 => 1)) - @test f(x) ≈ g(x_itensor) - @test contract(f'(x)) ≈ g'(x_itensor) - - f = y -> inner(replaceprime(*(x, y), 2 => 1), replaceprime(*(x, y), 2 => 1)) - g = - y -> - inner(replaceprime(*(x_itensor, y), 2 => 1), replaceprime(*(x_itensor, y), 2 => 1)) - @test f(y) ≈ g(y_itensor) - @test contract(f'(y)) ≈ g'(y_itensor) + if VERSION ≤ v"1.12-" + # Broken in Julia v1.12. See: + # https://github.com/ITensor/ITensorMPS.jl/pull/161 + # https://github.com/JuliaLang/julia/issues/59138 + # https://github.com/FluxML/Zygote.jl/issues/1580 + @testset "contract/apply MPOs on MPSs" begin + n = 2 + s = siteinds("S=1/2", n) + x = (x -> outer(x', x))(random_mps(s; linkdims=4)) + x_itensor = contract(x) + y = random_mps(s; linkdims=4) + y_itensor = contract(y) + + f = x -> inner(apply(x, y), apply(x, y)) + g = x -> inner(apply(x, y_itensor), apply(x, y_itensor)) + @test f(x) ≈ g(x_itensor) + @test contract(f'(x)) ≈ g'(x_itensor) + + f = y -> inner(apply(x, y), apply(x, y)) + g = y -> inner(apply(x_itensor, y), apply(x_itensor, y)) + @test f(y) ≈ g(y_itensor) + @test contract(f'(y)) ≈ g'(y_itensor) + + f = + x -> + inner(replaceprime(contract(x, y), 2 => 1), replaceprime(contract(x, y), 2 => 1)) + g = + x -> inner( + replaceprime(contract(x, y_itensor), 2 => 1), + replaceprime(contract(x, y_itensor), 2 => 1), + ) + @test f(x) ≈ g(x_itensor) + @test contract(f'(x)) ≈ g'(x_itensor) + + f = + y -> + inner(replaceprime(contract(x, y), 2 => 1), replaceprime(contract(x, y), 2 => 1)) + g = + y -> inner( + replaceprime(contract(x_itensor, y), 2 => 1), + replaceprime(contract(x_itensor, y), 2 => 1), + ) + @test f(y) ≈ g(y_itensor) + @test contract(f'(y)) ≈ g'(y_itensor) + + f = x -> inner(replaceprime(*(x, y), 2 => 1), replaceprime(*(x, y), 2 => 1)) + g = + x -> inner( + replaceprime(*(x, y_itensor), 2 => 1), replaceprime(*(x, y_itensor), 2 => 1) + ) + @test f(x) ≈ g(x_itensor) + @test contract(f'(x)) ≈ g'(x_itensor) + + f = y -> inner(replaceprime(*(x, y), 2 => 1), replaceprime(*(x, y), 2 => 1)) + g = + y -> inner( + replaceprime(*(x_itensor, y), 2 => 1), replaceprime(*(x_itensor, y), 2 => 1) + ) + @test f(y) ≈ g(y_itensor) + @test contract(f'(y)) ≈ g'(y_itensor) + end end @testset "Calling apply multiple times (ITensors #924 regression test)" begin n = 1 @@ -373,5 +382,4 @@ Random.seed!(1234) @test g_itensor'(θ) ≈ p * θ^(p - 1) @test g_mps'(θ) ≈ p * θ^(p - 1) end - =# end From dc8480a0cc03404a67179c16541a9adda4500e9c Mon Sep 17 00:00:00 2001 From: mtfishman Date: Mon, 13 Oct 2025 11:03:06 -0400 Subject: [PATCH 3/3] Skip more tests --- .../test_chainrules.jl | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/test/ext/ITensorMPSChainRulesCoreExt/test_chainrules.jl b/test/ext/ITensorMPSChainRulesCoreExt/test_chainrules.jl index 63e5efa..b563f08 100644 --- a/test/ext/ITensorMPSChainRulesCoreExt/test_chainrules.jl +++ b/test/ext/ITensorMPSChainRulesCoreExt/test_chainrules.jl @@ -275,29 +275,29 @@ Random.seed!(1234) @test contract(f'(x)) ≈ f'(x_itensor) end - if VERSION ≤ v"1.12-" - # Broken in Julia v1.12. See: + @testset "contract/apply MPOs on MPSs" begin + n = 2 + s = siteinds("S=1/2", n) + x = (x -> outer(x', x))(random_mps(s; linkdims=4)) + x_itensor = contract(x) + y = random_mps(s; linkdims=4) + y_itensor = contract(y) + + f = x -> inner(apply(x, y), apply(x, y)) + g = x -> inner(apply(x, y_itensor), apply(x, y_itensor)) + @test f(x) ≈ g(x_itensor) + @test contract(f'(x)) ≈ g'(x_itensor) + + f = y -> inner(apply(x, y), apply(x, y)) + g = y -> inner(apply(x_itensor, y), apply(x_itensor, y)) + @test f(y) ≈ g(y_itensor) + @test contract(f'(y)) ≈ g'(y_itensor) + + # These tests are broken in Julia v1.12. See: # https://github.com/ITensor/ITensorMPS.jl/pull/161 # https://github.com/JuliaLang/julia/issues/59138 # https://github.com/FluxML/Zygote.jl/issues/1580 - @testset "contract/apply MPOs on MPSs" begin - n = 2 - s = siteinds("S=1/2", n) - x = (x -> outer(x', x))(random_mps(s; linkdims=4)) - x_itensor = contract(x) - y = random_mps(s; linkdims=4) - y_itensor = contract(y) - - f = x -> inner(apply(x, y), apply(x, y)) - g = x -> inner(apply(x, y_itensor), apply(x, y_itensor)) - @test f(x) ≈ g(x_itensor) - @test contract(f'(x)) ≈ g'(x_itensor) - - f = y -> inner(apply(x, y), apply(x, y)) - g = y -> inner(apply(x_itensor, y), apply(x_itensor, y)) - @test f(y) ≈ g(y_itensor) - @test contract(f'(y)) ≈ g'(y_itensor) - + if VERSION ≤ v"1.12-" f = x -> inner(replaceprime(contract(x, y), 2 => 1), replaceprime(contract(x, y), 2 => 1))