Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
ci:
skip: [julia-formatter]

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
Expand All @@ -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.1
hooks:
- id: julia-format
- id: "julia-formatter"
2 changes: 1 addition & 1 deletion NDTensors/src/blocksparse/block.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion NDTensors/src/dense/densetensor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

#
Expand Down
2 changes: 1 addition & 1 deletion NDTensors/src/diag/tensoralgebra/contract.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions NDTensors/src/lib/BackendSelection/src/backend_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion NDTensors/src/tupletools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ITensors"
uuid = "9136182c-28ba-11e9-034c-db9fb085ebd5"
authors = ["Matthew Fishman <mfishman@flatironinstitute.org>", "Miles Stoudenmire <mstoudenmire@flatironinstitute.org>"]
version = "0.9.2"
version = "0.9.3"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
2 changes: 1 addition & 1 deletion jenkins/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 -
tar -C /usr/local -x -z --strip-components=1 -f -
22 changes: 13 additions & 9 deletions src/itensor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,9 @@
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)))
Expand All @@ -137,8 +138,9 @@
"""
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(

Check warning on line 141 in src/itensor.jl

View check run for this annotation

Codecov / codecov/patch

src/itensor.jl#L141

Added line #L141 was not covered by tests
"ITensor constructor with input arguments of types `$(typeof.(args))` not defined."
)

"""
Tensor(::ITensor)
Expand Down Expand Up @@ -300,7 +302,7 @@

emptyITensor(is...) = emptyITensor(EmptyNumber, indices(is...))

function emptyITensor(::Type{ElT}=EmptyNumber) where {ElT<:Number}
function emptyITensor((::Type{ElT})=EmptyNumber) where {ElT<:Number}

Check warning on line 305 in src/itensor.jl

View check run for this annotation

Codecov / codecov/patch

src/itensor.jl#L305

Added line #L305 was not covered by tests
return itensor(EmptyTensor(ElT, ()))
end

Expand Down Expand Up @@ -1092,8 +1094,9 @@
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

Expand All @@ -1119,8 +1122,9 @@
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
Expand Down
5 changes: 2 additions & 3 deletions src/symmetrystyle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
16 changes: 8 additions & 8 deletions src/tensor_operations/tensor_algebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
),
)
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion test/base/test_itensor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions test/base/test_not.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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''))

Expand All @@ -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'''))

Expand All @@ -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'))

Expand Down
2 changes: 1 addition & 1 deletion test/base/test_sitetype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions test/ext/ITensorsChainRulesCoreExt/test_chainrules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Loading