From 91112240d301bf3653bfdaaf7f5d4763cef9216e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 14 Apr 2025 17:41:04 +0000 Subject: [PATCH 1/5] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/pre-commit/pre-commit-hooks: v4.5.0 → v5.0.0](https://github.com/pre-commit/pre-commit-hooks/compare/v4.5.0...v5.0.0) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f7ecc4ad06..b8ebb6a031 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v5.0.0 hooks: - id: check-merge-conflict - id: check-toml From fcd15ebba741cf2a0784c1a414f7c09679a0bec0 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 14 Apr 2025 17:41:29 +0000 Subject: [PATCH 2/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- jenkins/Dockerfile | 2 +- src/tensor_operations/tensor_algebra.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/jenkins/Dockerfile b/jenkins/Dockerfile index e2367a8c01..c677086f2f 100644 --- a/jenkins/Dockerfile +++ b/jenkins/Dockerfile @@ -13,4 +13,4 @@ RUN apt-get update && \ ARG JULIA=1.6 RUN curl -s -L https://julialang-s3.julialang.org/bin/linux/x64/${JULIA}/julia-${JULIA}-latest-linux-x86_64.tar.gz | \ - tar -C /usr/local -x -z --strip-components=1 -f - \ No newline at end of file + tar -C /usr/local -x -z --strip-components=1 -f - diff --git a/src/tensor_operations/tensor_algebra.jl b/src/tensor_operations/tensor_algebra.jl index 0264240481..1f8f23d323 100644 --- a/src/tensor_operations/tensor_algebra.jl +++ b/src/tensor_operations/tensor_algebra.jl @@ -139,7 +139,7 @@ generally optimal and is found via the optimaltree function in TensorOperations. function optimal_contraction_sequence(As) return throw( ArgumentError( - "Optimal contraction sequence isn't defined. Try loading a backend package like + "Optimal contraction sequence isn't defined. Try loading a backend package like TensorOperations.jl" ), ) From e4a8199dbd3d1c3bb7fab4795692c75db1495813 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Mon, 14 Apr 2025 14:27:52 -0400 Subject: [PATCH 3/5] Format --- NDTensors/src/blocksparse/block.jl | 2 +- NDTensors/src/dense/densetensor.jl | 2 +- NDTensors/src/diag/tensoralgebra/contract.jl | 2 +- .../lib/BackendSelection/src/backend_types.jl | 5 +++-- NDTensors/src/tupletools.jl | 2 +- Project.toml | 2 +- src/itensor.jl | 22 +++++++++++-------- src/symmetrystyle.jl | 5 ++--- src/tensor_operations/tensor_algebra.jl | 14 ++++++------ test/base/test_itensor.jl | 2 +- test/base/test_not.jl | 6 ++--- test/base/test_sitetype.jl | 2 +- .../test_chainrules.jl | 6 ++--- 13 files changed, 38 insertions(+), 34 deletions(-) diff --git a/NDTensors/src/blocksparse/block.jl b/NDTensors/src/blocksparse/block.jl index cdc92302e9..f35eace158 100644 --- a/NDTensors/src/blocksparse/block.jl +++ b/NDTensors/src/blocksparse/block.jl @@ -68,7 +68,7 @@ convert(::Type{Block{N}}, t::Tuple) where {N} = Block{N}(t) gethash(b::Block) = b.hash[] -sethash!(b::Block, h::UInt) = (b.hash[] = h; return b) +sethash!(b::Block, h::UInt) = (b.hash[]=h; return b) # # Basic functions diff --git a/NDTensors/src/dense/densetensor.jl b/NDTensors/src/dense/densetensor.jl index 30106802be..f1aa7b07ff 100644 --- a/NDTensors/src/dense/densetensor.jl +++ b/NDTensors/src/dense/densetensor.jl @@ -134,7 +134,7 @@ end @propagate_inbounds @inline getindex(T::DenseTensor, i::Integer) = storage(T)[i] @propagate_inbounds @inline function setindex!(T::DenseTensor, v, i::Integer) - return (storage(T)[i] = v; T) + return (storage(T)[i]=v; T) end # diff --git a/NDTensors/src/diag/tensoralgebra/contract.jl b/NDTensors/src/diag/tensoralgebra/contract.jl index 085737c890..6244c0dffd 100644 --- a/NDTensors/src/diag/tensoralgebra/contract.jl +++ b/NDTensors/src/diag/tensoralgebra/contract.jl @@ -93,7 +93,7 @@ function contract!( # elements of A and B. # `expose` allows dispatching on the data type # in order to allow scalar indexing on GPU. - expose(R)[] = mapreduce(*, +, diagview(T1), diagview(T2)) + expose(R)[] = mapreduce(*,+,diagview(T1),diagview(T2)) else diagview(R) .= diagview(T1) .* diagview(T2) end diff --git a/NDTensors/src/lib/BackendSelection/src/backend_types.jl b/NDTensors/src/lib/BackendSelection/src/backend_types.jl index a07a46f22c..ed4002f339 100644 --- a/NDTensors/src/lib/BackendSelection/src/backend_types.jl +++ b/NDTensors/src/lib/BackendSelection/src/backend_types.jl @@ -28,8 +28,9 @@ for type in (:Algorithm, :Backend) function Base.show(io::IO, backend::$type) return print(io, "$($type) type ", backend_string(backend), ", ", parameters(backend)) end - Base.print(io::IO, backend::$type) = - print(io, backend_string(backend), ", ", parameters(backend)) + Base.print(io::IO, backend::$type) = print( + io, backend_string(backend), ", ", parameters(backend) + ) end end diff --git a/NDTensors/src/tupletools.jl b/NDTensors/src/tupletools.jl index 132b219af5..ce7dac1168 100644 --- a/NDTensors/src/tupletools.jl +++ b/NDTensors/src/tupletools.jl @@ -60,7 +60,7 @@ permute(s::AbstractVector, perm) = _permute(s, perm) sim(s::NTuple) = s # type stable findfirst -@inline _findfirst(args...) = (i = findfirst(args...); i === nothing ? 0 : i) +@inline _findfirst(args...) = (i=findfirst(args...); i === nothing ? 0 : i) """ getperm(col1,col2) diff --git a/Project.toml b/Project.toml index b3dd696f73..5f110deac9 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.9.2" +version = "0.9.3" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" diff --git a/src/itensor.jl b/src/itensor.jl index 3a0c6c7cf4..f283234d83 100644 --- a/src/itensor.jl +++ b/src/itensor.jl @@ -119,8 +119,9 @@ Constructor for an ITensor from a TensorStorage and a set of indices. The ITensor stores a view of the TensorStorage. """ -ITensor(as::AliasStyle, st::TensorStorage, is)::ITensor = - ITensor(as, Tensor(as, st, Tuple(is))) +ITensor(as::AliasStyle, st::TensorStorage, is)::ITensor = ITensor( + as, Tensor(as, st, Tuple(is)) +) ITensor(as::AliasStyle, is, st::TensorStorage)::ITensor = ITensor(as, st, is) ITensor(st::TensorStorage, is)::ITensor = itensor(Tensor(NeverAlias(), st, Tuple(is))) @@ -137,8 +138,9 @@ of the input data when possible. """ itensor(args...; kwargs...)::ITensor = ITensor(AllowAlias(), args...; kwargs...) -ITensor(::AliasStyle, args...; kwargs...)::ITensor = - error("ITensor constructor with input arguments of types `$(typeof.(args))` not defined.") +ITensor(::AliasStyle, args...; kwargs...)::ITensor = error( + "ITensor constructor with input arguments of types `$(typeof.(args))` not defined." +) """ Tensor(::ITensor) @@ -300,7 +302,7 @@ emptyITensor(is::Indices) = emptyITensor(EmptyNumber, is) emptyITensor(is...) = emptyITensor(EmptyNumber, indices(is...)) -function emptyITensor(::Type{ElT}=EmptyNumber) where {ElT<:Number} +function emptyITensor((::Type{ElT})=EmptyNumber) where {ElT<:Number} return itensor(EmptyTensor(ElT, ())) end @@ -1092,8 +1094,9 @@ A[1, 2] # 2.0, same as: A[i => 1, i' => 2] end # Special case that handles indexing with `end` like `A[i => end, j => 3]` -@propagate_inbounds getindex(T::ITensor, I::Union{Integer,LastVal}...)::Any = - _getindex(tensor(T), I...) +@propagate_inbounds getindex(T::ITensor, I::Union{Integer,LastVal}...)::Any = _getindex( + tensor(T), I... +) # Simple version with just integer indexing, bounds checking gets done by NDTensors @@ -1119,8 +1122,9 @@ A = ITensor(2.0, i, i') A[i => 1, i' => 2] # 2.0, same as: A[i' => 2, i => 1] ``` """ -@propagate_inbounds (getindex(T::ITensor, ivs::Vararg{Any,N})::Any) where {N} = - _getindex(tensor(T), ivs...) +@propagate_inbounds (getindex(T::ITensor, ivs::Vararg{Any,N})::Any) where {N} = _getindex( + tensor(T), ivs... +) ## Allowing one to get the first ITensor element if its an order 0 tensor or an order 1 tensor with a dimension of 1. Also convert GPU back to CPU @propagate_inbounds function getindex(T::ITensor)::Any diff --git a/src/symmetrystyle.jl b/src/symmetrystyle.jl index 319dfe6060..2507d33e04 100644 --- a/src/symmetrystyle.jl +++ b/src/symmetrystyle.jl @@ -7,9 +7,8 @@ function symmetrystyle(T) return error("No SymmetryStyle defined for the specified object $T of type $(typeof(T))") end -symmetrystyle(T, S, U, V...)::SymmetryStyle = ( - Base.@_inline_meta; symmetrystyle(symmetrystyle(T), symmetrystyle(S, U, V...)) -) +symmetrystyle(T, S, U, V...)::SymmetryStyle = + (Base.@_inline_meta; symmetrystyle(symmetrystyle(T), symmetrystyle(S, U, V...))) symmetrystyle(T, S)::SymmetryStyle = symmetrystyle(symmetrystyle(T), symmetrystyle(S)) diff --git a/src/tensor_operations/tensor_algebra.jl b/src/tensor_operations/tensor_algebra.jl index 1f8f23d323..c70623aac9 100644 --- a/src/tensor_operations/tensor_algebra.jl +++ b/src/tensor_operations/tensor_algebra.jl @@ -581,23 +581,23 @@ function product(A::ITensor, B::ITensor; apply_dag::Bool=false) danglings_inds = unioninds(danglings_indsA, danglings_indsB) if hassameinds(common_paired_indsA, common_paired_indsB) # matrix-matrix product - A′ = prime(A; inds=!danglings_inds) - AB = mapprime(A′ * B, 2 => 1; inds=!danglings_inds) + A′ = prime(A; inds=(!danglings_inds)) + AB = mapprime(A′ * B, 2 => 1; inds=(!danglings_inds)) if apply_dag - AB′ = prime(AB; inds=!danglings_inds) - Adag = swapprime(dag(A), 0 => 1; inds=!danglings_inds) - return mapprime(AB′ * Adag, 2 => 1; inds=!danglings_inds) + AB′ = prime(AB; inds=(!danglings_inds)) + Adag = swapprime(dag(A), 0 => 1; inds=(!danglings_inds)) + return mapprime(AB′ * Adag, 2 => 1; inds=(!danglings_inds)) end return AB elseif isempty(common_paired_indsA) && !isempty(common_paired_indsB) # vector-matrix product apply_dag && error("apply_dag not supported for matrix-vector product") - A′ = prime(A; inds=!danglings_inds) + A′ = prime(A; inds=(!danglings_inds)) return A′ * B elseif !isempty(common_paired_indsA) && isempty(common_paired_indsB) # matrix-vector product apply_dag && error("apply_dag not supported for vector-matrix product") - return replaceprime(A * B, 1 => 0; inds=!danglings_inds) + return replaceprime(A * B, 1 => 0; inds=(!danglings_inds)) end end diff --git a/test/base/test_itensor.jl b/test/base/test_itensor.jl index 66ca1abfc7..52efac9fbf 100644 --- a/test/base/test_itensor.jl +++ b/test/base/test_itensor.jl @@ -246,7 +246,7 @@ end @test A[b => end - 1, a => 2] == A[a => 2, b => 2] @test A[b => end, a => 1] == A[a => 1, b => 3] @test A[b => end - 2, a => 1] == A[a => 1, b => 1] - @test A[b => end^2 - 7, a => 1] == A[a => 1, b => 2] + @test A[b => end ^ 2 - 7, a => 1] == A[a => 1, b => 2] i, j, k, l = Index.(2, ("i", "j", "k", "l")) B = random_itensor(i) diff --git a/test/base/test_not.jl b/test/base/test_not.jl index d0c3855d1c..1efa534b04 100644 --- a/test/base/test_not.jl +++ b/test/base/test_not.jl @@ -11,7 +11,7 @@ using ITensors, Test @test hassameinds(Ap, (i', j, k'')) - Ap = prime(A; tags=!ts"j") + Ap = prime(A; tags=(!ts"j")) @test hassameinds(Ap, (i', j, k'')) @@ -23,7 +23,7 @@ using ITensors, Test @test hassameinds(Ap2, (i, j'', k''')) - Ap2 = prime(A, 2; inds=!i) + Ap2 = prime(A, 2; inds=(!i)) @test hassameinds(Ap2, (i, j'', k''')) @@ -39,7 +39,7 @@ using ITensors, Test @test hassameinds(At2, (settags(i, "y"), j, k')) - At2 = settags(A, "y"; inds=!IndexSet(j, k')) + At2 = settags(A, "y"; inds=(!IndexSet(j, k'))) @test hassameinds(At2, (settags(i, "y"), j, k')) diff --git a/test/base/test_sitetype.jl b/test/base/test_sitetype.jl index 12c77734a6..de03b2b4a5 100644 --- a/test/base/test_sitetype.jl +++ b/test/base/test_sitetype.jl @@ -226,7 +226,7 @@ end o = op("$(ot)_op_1", s, 1, 2) @test o ≈ itensor( - [i * j for i in 1:(d^2), j in 1:(d^2)], s[2]', s[1]', dag(s[2]), dag(s[1]) + [i * j for i in 1:(d ^ 2), j in 1:(d ^ 2)], s[2]', s[1]', dag(s[2]), dag(s[1]) ) d = 4 diff --git a/test/ext/ITensorsChainRulesCoreExt/test_chainrules.jl b/test/ext/ITensorsChainRulesCoreExt/test_chainrules.jl index 58e5ad3b23..0bb2b43bbf 100644 --- a/test/ext/ITensorsChainRulesCoreExt/test_chainrules.jl +++ b/test/ext/ITensorsChainRulesCoreExt/test_chainrules.jl @@ -240,11 +240,11 @@ Random.seed!(1234) args = (A,) test_rrule(ZygoteRuleConfig(), f, args...; rrule_f=rrule_via_ad, check_inferred=false) - f = x -> (x^2 * δ((i', i)))[1, 1] + f = x -> (x ^ 2 * δ((i', i)))[1, 1] args = (6.2,) test_rrule(ZygoteRuleConfig(), f, args...; rrule_f=rrule_via_ad, check_inferred=false) - f = x -> (x^2 * δ(i', i))[1, 1] + f = x -> (x ^ 2 * δ(i', i))[1, 1] args = (5.2,) test_rrule(ZygoteRuleConfig(), f, args...; rrule_f=rrule_via_ad, check_inferred=false) end @@ -284,7 +284,7 @@ Random.seed!(1234) #args = (2.8 + 3.1im,) #test_rrule(ZygoteRuleConfig(), f, args...; rrule_f=rrule_via_ad, check_inferred=false) f = function (x) - return real((x^3 * ITensor([sin(x) exp(-2x); 3x^3 x+x^2], j', dag(j)))[1, 1]) + return real((x ^ 3 * ITensor([sin(x) exp(-2x); 3x ^ 3 x + x ^ 2], j', dag(j)))[1, 1]) end args = (3.4 + 2.3im,) test_rrule(ZygoteRuleConfig(), f, args...; rrule_f=rrule_via_ad, check_inferred=false) From 26e20bfa6cfa59f330e74690223e5430078027a8 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Mon, 14 Apr 2025 14:29:56 -0400 Subject: [PATCH 4/5] Update .pre-commit-config.yaml --- .pre-commit-config.yaml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b8ebb6a031..0fe29a8fd0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,3 +1,6 @@ +ci: + skip: [julia-formatter] + repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v5.0.0 @@ -10,7 +13,8 @@ repos: exclude_types: [markdown] # incompatible with Literate.jl - id: trailing-whitespace exclude: '.*references/.*\.txt$' # do not check reference TN images -- repo: https://github.com/qiaojunfeng/pre-commit-julia-format - rev: v0.2.0 + +- repo: "https://github.com/domluna/JuliaFormatter.jl" + rev: v2.1.0 hooks: - - id: julia-format + - id: "julia-formatter" From 0192263bd55a4d9683ddd162445d9a8dbb781e44 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Mon, 14 Apr 2025 14:33:42 -0400 Subject: [PATCH 5/5] Update pre-commit --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0fe29a8fd0..3a7b9a5911 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,6 +15,6 @@ repos: exclude: '.*references/.*\.txt$' # do not check reference TN images - repo: "https://github.com/domluna/JuliaFormatter.jl" - rev: v2.1.0 + rev: v2.1.1 hooks: - id: "julia-formatter"