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
2 changes: 2 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ If practical and applicable, please include a minimal demonstration of the previ
```julia
[YOUR MINIMAL DEMONSTRATION OF PREVIOUS BEHAVIOR]
```

</p></details>

<details><summary>Minimal demonstration of new behavior</summary><p>

```julia
[YOUR MINIMAL DEMONSTRATION OF NEW BEHAVIOR]
```

</p></details>

# How Has This Been Tested?
Expand Down
13 changes: 8 additions & 5 deletions .github/workflows/FormatCheck.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
name: "Format Check"

on:
push:
branches:
- 'main'
tags: '*'
pull_request:
pull_request_target:
paths: ['**/*.jl']
types: [opened, synchronize, reopened, ready_for_review]

permissions:
contents: read
actions: write
pull-requests: write

jobs:
format-check:
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/FormatPullRequest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: "Format Pull Request"

on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
permissions:
contents: write
pull-requests: write

jobs:
format-pull-request:
name: "Format Pull Request"
uses: "ITensor/ITensorActions/.github/workflows/FormatPullRequest.yml@main"
11 changes: 11 additions & 0 deletions .github/workflows/VersionCheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: "Version Check"

on:
pull_request:

jobs:
version-check:
name: "Version Check"
uses: "ITensor/ITensorActions/.github/workflows/VersionCheck.yml@main"
with:
localregistry: https://github.com/ITensor/ITensorRegistry.git
10 changes: 4 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ci:
skip: [julia-formatter]
skip: [runic]

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand All @@ -9,12 +9,10 @@ repos:
- id: check-toml
- id: check-yaml
- id: end-of-file-fixer
exclude: '.*references/.*\.txt$' # do not check reference TN images
exclude_types: [markdown] # incompatible with Literate.jl
- id: trailing-whitespace
exclude: '.*references/.*\.txt$' # do not check reference TN images

- repo: "https://github.com/domluna/JuliaFormatter.jl"
rev: v2.1.6
- repo: https://github.com/fredrikekre/runic-pre-commit
rev: v2.0.1
hooks:
- id: "julia-formatter"
- id: runic
2 changes: 1 addition & 1 deletion NDTensors/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "NDTensors"
uuid = "23ae76d9-e61a-49c4-8f12-3f1a16adf9cf"
authors = ["Matthew Fishman <[email protected]>"]
version = "0.4.11"
version = "0.4.12"

[deps]
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
Expand Down
104 changes: 52 additions & 52 deletions NDTensors/ext/NDTensorsHDF5Ext/blocksparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,66 +3,66 @@ using NDTensors: data, Block, blockoffsets, BlockOffsets, BlockSparse

# Helper function for HDF5 write/read of BlockSparse
function offsets_to_array(boff::BlockOffsets{N}) where {N}
nblocks = length(boff)
asize = (N + 1) * nblocks
n = 1
a = Vector{Int}(undef, asize)
for bo in pairs(boff)
for j in 1:N
a[n] = bo[1][j]
n += 1
nblocks = length(boff)
asize = (N + 1) * nblocks
n = 1
a = Vector{Int}(undef, asize)
for bo in pairs(boff)
for j in 1:N
a[n] = bo[1][j]
n += 1
end
a[n] = bo[2]
n += 1
end
a[n] = bo[2]
n += 1
end
return a
return a
end

# Helper function for HDF5 write/read of BlockSparse
function array_to_offsets(a, N::Int)
asize = length(a)
nblocks = div(asize, N + 1)
boff = BlockOffsets{N}()
j = 0
for b in 1:nblocks
insert!(boff, Block(ntuple(i -> (a[j + i]), N)), a[j + N + 1])
j += (N + 1)
end
return boff
asize = length(a)
nblocks = div(asize, N + 1)
boff = BlockOffsets{N}()
j = 0
for b in 1:nblocks
insert!(boff, Block(ntuple(i -> (a[j + i]), N)), a[j + N + 1])
j += (N + 1)
end
return boff
end

function HDF5.write(parent::Union{HDF5.File,HDF5.Group}, name::String, B::BlockSparse)
g = create_group(parent, name)
attributes(g)["type"] = "BlockSparse{$(eltype(B))}"
attributes(g)["version"] = 1
if eltype(B) != Nothing
write(g, "ndims", ndims(B))
write(g, "data", data(B))
off_array = offsets_to_array(blockoffsets(B))
write(g, "offsets", off_array)
end
function HDF5.write(parent::Union{HDF5.File, HDF5.Group}, name::String, B::BlockSparse)
g = create_group(parent, name)
attributes(g)["type"] = "BlockSparse{$(eltype(B))}"
attributes(g)["version"] = 1
return if eltype(B) != Nothing
write(g, "ndims", ndims(B))
write(g, "data", data(B))
off_array = offsets_to_array(blockoffsets(B))
write(g, "offsets", off_array)
end
end

function HDF5.read(
parent::Union{HDF5.File,HDF5.Group}, name::AbstractString, ::Type{Store}
) where {Store<:BlockSparse}
g = open_group(parent, name)
ElT = eltype(Store)
typestr = "BlockSparse{$ElT}"
if read(attributes(g)["type"]) != typestr
error("HDF5 group or file does not contain $typestr data")
end
N = read(g, "ndims")
off_array = read(g, "offsets")
boff = array_to_offsets(off_array, N)
# Attribute __complex__ is attached to the "data" dataset
# by the h5 library used by C++ version of ITensor:
if haskey(attributes(g["data"]), "__complex__")
M = read(g, "data")
nelt = size(M, 1) * size(M, 2)
data = Vector(reinterpret(ComplexF64, reshape(M, nelt)))
else
data = read(g, "data")
end
return BlockSparse(data, boff)
parent::Union{HDF5.File, HDF5.Group}, name::AbstractString, ::Type{Store}
) where {Store <: BlockSparse}
g = open_group(parent, name)
ElT = eltype(Store)
typestr = "BlockSparse{$ElT}"
if read(attributes(g)["type"]) != typestr
error("HDF5 group or file does not contain $typestr data")
end
N = read(g, "ndims")
off_array = read(g, "offsets")
boff = array_to_offsets(off_array, N)
# Attribute __complex__ is attached to the "data" dataset
# by the h5 library used by C++ version of ITensor:
if haskey(attributes(g["data"]), "__complex__")
M = read(g, "data")
nelt = size(M, 1) * size(M, 2)
data = Vector(reinterpret(ComplexF64, reshape(M, nelt)))
else
data = read(g, "data")
end
return BlockSparse(data, boff)
end
58 changes: 29 additions & 29 deletions NDTensors/ext/NDTensorsHDF5Ext/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,36 @@ using HDF5: HDF5, attributes, create_group, open_group, read, write
using NDTensors: Dense

function HDF5.write(
parent::Union{HDF5.File,HDF5.Group}, name::String, D::Store
) where {Store<:Dense}
g = create_group(parent, name)
attributes(g)["type"] = "Dense{$(eltype(Store))}"
attributes(g)["version"] = 1
if eltype(D) != Nothing
write(g, "data", D.data)
end
parent::Union{HDF5.File, HDF5.Group}, name::String, D::Store
) where {Store <: Dense}
g = create_group(parent, name)
attributes(g)["type"] = "Dense{$(eltype(Store))}"
attributes(g)["version"] = 1
return if eltype(D) != Nothing
write(g, "data", D.data)
end
end

function HDF5.read(
parent::Union{HDF5.File,HDF5.Group}, name::AbstractString, ::Type{Store}
) where {Store<:Dense}
g = open_group(parent, name)
ElT = eltype(Store)
typestr = "Dense{$ElT}"
if read(attributes(g)["type"]) != typestr
error("HDF5 group or file does not contain $typestr data")
end
if ElT == Nothing
return Dense{Nothing}()
end
# Attribute __complex__ is attached to the "data" dataset
# by the h5 library used by C++ version of ITensor:
if haskey(attributes(g["data"]), "__complex__")
M = read(g, "data")
nelt = size(M, 1) * size(M, 2)
data = Vector(reinterpret(ComplexF64, reshape(M, nelt)))
else
data = read(g, "data")
end
return Dense{ElT}(data)
parent::Union{HDF5.File, HDF5.Group}, name::AbstractString, ::Type{Store}
) where {Store <: Dense}
g = open_group(parent, name)
ElT = eltype(Store)
typestr = "Dense{$ElT}"
if read(attributes(g)["type"]) != typestr
error("HDF5 group or file does not contain $typestr data")
end
if ElT == Nothing
return Dense{Nothing}()
end
# Attribute __complex__ is attached to the "data" dataset
# by the h5 library used by C++ version of ITensor:
if haskey(attributes(g["data"]), "__complex__")
M = read(g, "data")
nelt = size(M, 1) * size(M, 2)
data = Vector(reinterpret(ComplexF64, reshape(M, nelt)))
else
data = read(g, "data")
end
return Dense{ElT}(data)
end
60 changes: 30 additions & 30 deletions NDTensors/ext/NDTensorsHDF5Ext/diag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,37 @@ using HDF5: HDF5, attributes, create_group, open_group, read, write
using NDTensors: datatype, Dense, Diag

function HDF5.write(
parent::Union{HDF5.File,HDF5.Group}, name::String, D::Store
) where {Store<:Diag}
g = create_group(parent, name)
attributes(g)["type"] = "Diag{$(eltype(Store)),$(datatype(Store))}"
attributes(g)["version"] = 1
if eltype(D) != Nothing
write(g, "data", D.data)
end
parent::Union{HDF5.File, HDF5.Group}, name::String, D::Store
) where {Store <: Diag}
g = create_group(parent, name)
attributes(g)["type"] = "Diag{$(eltype(Store)),$(datatype(Store))}"
attributes(g)["version"] = 1
return if eltype(D) != Nothing
write(g, "data", D.data)
end
end

function HDF5.read(
parent::Union{HDF5.File,HDF5.Group}, name::AbstractString, ::Type{Store}
) where {Store<:Diag}
g = open_group(parent, name)
ElT = eltype(Store)
DataT = datatype(Store)
typestr = "Diag{$ElT,$DataT}"
if read(attributes(g)["type"]) != typestr
error("HDF5 group or file does not contain $typestr data")
end
if ElT == Nothing
return Dense{Nothing}()
end
# Attribute __complex__ is attached to the "data" dataset
# by the h5 library used by C++ version of ITensor:
if haskey(attributes(g["data"]), "__complex__")
M = read(g, "data")
nelt = size(M, 1) * size(M, 2)
data = Vector(reinterpret(ComplexF64, reshape(M, nelt)))
else
data = read(g, "data")
end
return Diag{ElT,DataT}(data)
parent::Union{HDF5.File, HDF5.Group}, name::AbstractString, ::Type{Store}
) where {Store <: Diag}
g = open_group(parent, name)
ElT = eltype(Store)
DataT = datatype(Store)
typestr = "Diag{$ElT,$DataT}"
if read(attributes(g)["type"]) != typestr
error("HDF5 group or file does not contain $typestr data")
end
if ElT == Nothing
return Dense{Nothing}()
end
# Attribute __complex__ is attached to the "data" dataset
# by the h5 library used by C++ version of ITensor:
if haskey(attributes(g["data"]), "__complex__")
M = read(g, "data")
nelt = size(M, 1) * size(M, 2)
data = Vector(reinterpret(ComplexF64, reshape(M, nelt)))
else
data = read(g, "data")
end
return Diag{ElT, DataT}(data)
end
Loading
Loading