diff --git a/NDTensors/Project.toml b/NDTensors/Project.toml index 3148db3c4c..85e8c1bc08 100644 --- a/NDTensors/Project.toml +++ b/NDTensors/Project.toml @@ -1,7 +1,7 @@ name = "NDTensors" uuid = "23ae76d9-e61a-49c4-8f12-3f1a16adf9cf" authors = ["Matthew Fishman "] -version = "0.3.39" +version = "0.3.42" [deps] Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697" @@ -56,7 +56,7 @@ NDTensorsTBLISExt = "TBLIS" NDTensorscuTENSORExt = "cuTENSOR" [compat] -AMDGPU = "0.9" +AMDGPU = "0.9, 1" Accessors = "0.1.33" Adapt = "3.7, 4" ArrayLayouts = "1.4" diff --git a/NDTensors/src/diag/diagtensor.jl b/NDTensors/src/diag/diagtensor.jl index af0c294a0a..852fefa466 100644 --- a/NDTensors/src/diag/diagtensor.jl +++ b/NDTensors/src/diag/diagtensor.jl @@ -82,7 +82,8 @@ setdiag(T::UniformDiagTensor, val) = tensor(Diag(val), inds(T)) end end @propagate_inbounds getindex(T::DiagTensor{<:Number,1}, ind::Int) = storage(T)[ind] -@propagate_inbounds getindex(T::DiagTensor{<:Number,0}) = storage(T)[1] +using NDTensors.Expose: expose +@propagate_inbounds getindex(T::DiagTensor{<:Number,0}) = getindex(expose(storage(T))) # Set diagonal elements # Throw error for off-diagonal diff --git a/NDTensors/src/lib/TensorAlgebra/test/test_basics.jl b/NDTensors/src/lib/TensorAlgebra/test/test_basics.jl index bafabdf0b9..95576a8bf5 100644 --- a/NDTensors/src/lib/TensorAlgebra/test/test_basics.jl +++ b/NDTensors/src/lib/TensorAlgebra/test/test_basics.jl @@ -122,83 +122,78 @@ end @test eltype(a_split) === elt @test a_split ≈ reshape(a, (2, 3, 20)) end - ## Right now TensorOperations version is downgraded when using cuTENSOR to `v0.7` we - ## are waiting for TensorOperations to support the breaking changes in cuTENSOR 2.x - if !("cutensor" ∈ ARGS) - using TensorOperations: TensorOperations - @testset "contract (eltype1=$elt1, eltype2=$elt2)" for elt1 in elts, elt2 in elts - dims = (2, 3, 4, 5, 6, 7, 8, 9, 10) - labels = (:a, :b, :c, :d, :e, :f, :g, :h, :i) - for (d1s, d2s, d_dests) in ( - ((1, 2), (1, 2), ()), - ((1, 2), (2, 1), ()), - ((1, 2), (2, 1, 3), (3,)), - ((1, 2, 3), (2, 1), (3,)), - ((1, 2), (2, 3), (1, 3)), - ((1, 2), (2, 3), (3, 1)), - ((2, 1), (2, 3), (3, 1)), - ((1, 2, 3), (2, 3, 4), (1, 4)), - ((1, 2, 3), (2, 3, 4), (4, 1)), - ((3, 2, 1), (4, 2, 3), (4, 1)), - ((1, 2, 3), (3, 4), (1, 2, 4)), - ((1, 2, 3), (3, 4), (4, 1, 2)), - ((1, 2, 3), (3, 4), (2, 4, 1)), - ((3, 1, 2), (3, 4), (2, 4, 1)), - ((3, 2, 1), (4, 3), (2, 4, 1)), - ((1, 2, 3, 4, 5, 6), (4, 5, 6, 7, 8, 9), (1, 2, 3, 7, 8, 9)), - ((2, 4, 5, 1, 6, 3), (6, 4, 9, 8, 5, 7), (1, 7, 2, 8, 3, 9)), - ) - a1 = randn(elt1, map(i -> dims[i], d1s)) - labels1 = map(i -> labels[i], d1s) - a2 = randn(elt2, map(i -> dims[i], d2s)) - labels2 = map(i -> labels[i], d2s) - labels_dest = map(i -> labels[i], d_dests) + using TensorOperations: TensorOperations + @testset "contract (eltype1=$elt1, eltype2=$elt2)" for elt1 in elts, elt2 in elts + dims = (2, 3, 4, 5, 6, 7, 8, 9, 10) + labels = (:a, :b, :c, :d, :e, :f, :g, :h, :i) + for (d1s, d2s, d_dests) in ( + ((1, 2), (1, 2), ()), + ((1, 2), (2, 1), ()), + ((1, 2), (2, 1, 3), (3,)), + ((1, 2, 3), (2, 1), (3,)), + ((1, 2), (2, 3), (1, 3)), + ((1, 2), (2, 3), (3, 1)), + ((2, 1), (2, 3), (3, 1)), + ((1, 2, 3), (2, 3, 4), (1, 4)), + ((1, 2, 3), (2, 3, 4), (4, 1)), + ((3, 2, 1), (4, 2, 3), (4, 1)), + ((1, 2, 3), (3, 4), (1, 2, 4)), + ((1, 2, 3), (3, 4), (4, 1, 2)), + ((1, 2, 3), (3, 4), (2, 4, 1)), + ((3, 1, 2), (3, 4), (2, 4, 1)), + ((3, 2, 1), (4, 3), (2, 4, 1)), + ((1, 2, 3, 4, 5, 6), (4, 5, 6, 7, 8, 9), (1, 2, 3, 7, 8, 9)), + ((2, 4, 5, 1, 6, 3), (6, 4, 9, 8, 5, 7), (1, 7, 2, 8, 3, 9)), + ) + a1 = randn(elt1, map(i -> dims[i], d1s)) + labels1 = map(i -> labels[i], d1s) + a2 = randn(elt2, map(i -> dims[i], d2s)) + labels2 = map(i -> labels[i], d2s) + labels_dest = map(i -> labels[i], d_dests) - # Don't specify destination labels - a_dest, labels_dest′ = TensorAlgebra.contract(a1, labels1, a2, labels2) - a_dest_tensoroperations = TensorOperations.tensorcontract( - labels_dest′, a1, labels1, a2, labels2 - ) - @test a_dest ≈ a_dest_tensoroperations + # Don't specify destination labels + a_dest, labels_dest′ = TensorAlgebra.contract(a1, labels1, a2, labels2) + a_dest_tensoroperations = TensorOperations.tensorcontract( + labels_dest′, a1, labels1, a2, labels2 + ) + @test a_dest ≈ a_dest_tensoroperations - # Specify destination labels - a_dest = TensorAlgebra.contract(labels_dest, a1, labels1, a2, labels2) - a_dest_tensoroperations = TensorOperations.tensorcontract( - labels_dest, a1, labels1, a2, labels2 - ) - @test a_dest ≈ a_dest_tensoroperations + # Specify destination labels + a_dest = TensorAlgebra.contract(labels_dest, a1, labels1, a2, labels2) + a_dest_tensoroperations = TensorOperations.tensorcontract( + labels_dest, a1, labels1, a2, labels2 + ) + @test a_dest ≈ a_dest_tensoroperations - # Specify α and β - elt_dest = promote_type(elt1, elt2) - # TODO: Using random `α`, `β` causing - # random test failures, investigate why. - α = elt_dest(1.2) # randn(elt_dest) - β = elt_dest(2.4) # randn(elt_dest) - a_dest_init = randn(elt_dest, map(i -> dims[i], d_dests)) - a_dest = copy(a_dest_init) - TensorAlgebra.contract!(a_dest, labels_dest, a1, labels1, a2, labels2, α, β) - a_dest_tensoroperations = TensorOperations.tensorcontract( - labels_dest, a1, labels1, a2, labels2 - ) - ## Here we loosened the tolerance because of some floating point roundoff issue. - ## with Float32 numbers - @test a_dest ≈ α * a_dest_tensoroperations + β * a_dest_init rtol = - 50 * default_rtol(elt_dest) - end + # Specify α and β + elt_dest = promote_type(elt1, elt2) + # TODO: Using random `α`, `β` causing + # random test failures, investigate why. + α = elt_dest(1.2) # randn(elt_dest) + β = elt_dest(2.4) # randn(elt_dest) + a_dest_init = randn(elt_dest, map(i -> dims[i], d_dests)) + a_dest = copy(a_dest_init) + TensorAlgebra.contract!(a_dest, labels_dest, a1, labels1, a2, labels2, α, β) + a_dest_tensoroperations = TensorOperations.tensorcontract( + labels_dest, a1, labels1, a2, labels2 + ) + ## Here we loosened the tolerance because of some floating point roundoff issue. + ## with Float32 numbers + @test a_dest ≈ α * a_dest_tensoroperations + β * a_dest_init rtol = + 50 * default_rtol(elt_dest) end end - @testset "qr (eltype=$elt)" for elt in elts - a = randn(elt, 5, 4, 3, 2) - labels_a = (:a, :b, :c, :d) - labels_q = (:b, :a) - labels_r = (:d, :c) - q, r = qr(a, labels_a, labels_q, labels_r) - label_qr = :qr - a′ = TensorAlgebra.contract( - labels_a, q, (labels_q..., label_qr), r, (label_qr, labels_r...) - ) - @test a ≈ a′ - end end - +@testset "qr (eltype=$elt)" for elt in elts + a = randn(elt, 5, 4, 3, 2) + labels_a = (:a, :b, :c, :d) + labels_q = (:b, :a) + labels_r = (:d, :c) + q, r = qr(a, labels_a, labels_q, labels_r) + label_qr = :qr + a′ = TensorAlgebra.contract( + labels_a, q, (labels_q..., label_qr), r, (label_qr, labels_r...) + ) + @test a ≈ a′ +end end diff --git a/NDTensors/test/NDTensorsTestUtils/device_list.jl b/NDTensors/test/NDTensorsTestUtils/device_list.jl index d0cda58b16..53b78c99a0 100644 --- a/NDTensors/test/NDTensorsTestUtils/device_list.jl +++ b/NDTensors/test/NDTensorsTestUtils/device_list.jl @@ -18,9 +18,6 @@ if "metal" in ARGS || "all" in ARGS using Metal end if "cutensor" in ARGS || "all" in ARGS - if in("TensorOperations", map(v -> v.name, values(Pkg.dependencies()))) - Pkg.rm("TensorOperations") - end Pkg.add("cuTENSOR") Pkg.add("CUDA") using CUDA, cuTENSOR diff --git a/NDTensors/test/test_diag.jl b/NDTensors/test/test_diag.jl index 997ca497dd..cb8adc367a 100644 --- a/NDTensors/test/test_diag.jl +++ b/NDTensors/test/test_diag.jl @@ -63,7 +63,7 @@ using .NDTensorsTestUtils: devices_list, is_supported_eltype @test x == dev(diagm(0 => vr)) @test x == D end - + @test sqrt(contract(D, (-1, -2), conj(D), (-1, -2))[]) ≈ norm(D) # This if statement corresponds to the reported bug: # https://github.com/JuliaGPU/Metal.jl/issues/364 if !(dev == NDTensors.mtl && elt === ComplexF32) diff --git a/Project.toml b/Project.toml index 4710d75ddf..02b13bdf91 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ITensors" uuid = "9136182c-28ba-11e9-034c-db9fb085ebd5" authors = ["Matthew Fishman ", "Miles Stoudenmire "] -version = "0.6.16" +version = "0.6.17" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" diff --git a/src/lib/ITensorMPS/src/mpo.jl b/src/lib/ITensorMPS/src/mpo.jl index cd4b076fc8..647ca1bad6 100644 --- a/src/lib/ITensorMPS/src/mpo.jl +++ b/src/lib/ITensorMPS/src/mpo.jl @@ -561,7 +561,7 @@ end """ error_contract(y::MPS, A::MPO, x::MPS; make_inds_match::Bool = true) - error_contract(y::MPS, x::MPS, x::MPO; + error_contract(y::MPS, x::MPS, A::MPO; make_inds_match::Bool = true) Compute the distance between A|x> and an approximation MPS y: