-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
298 additions
and
240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using HDF5: HDF5, attributes, create_group, open_group, read, write | ||
using ITensors: ITensor | ||
using ITensors.ITensorMPS: MPO | ||
|
||
function HDF5.write(parent::Union{HDF5.File,HDF5.Group}, name::AbstractString, M::MPO) | ||
g = create_group(parent, name) | ||
attributes(g)["type"] = "MPO" | ||
attributes(g)["version"] = 1 | ||
N = length(M) | ||
write(g, "rlim", M.rlim) | ||
write(g, "llim", M.llim) | ||
write(g, "length", N) | ||
for n in 1:N | ||
write(g, "MPO[$(n)]", M[n]) | ||
end | ||
end | ||
|
||
function HDF5.read(parent::Union{HDF5.File,HDF5.Group}, name::AbstractString, ::Type{MPO}) | ||
g = open_group(parent, name) | ||
if read(attributes(g)["type"]) != "MPO" | ||
error("HDF5 group or file does not contain MPO data") | ||
end | ||
N = read(g, "length") | ||
rlim = read(g, "rlim") | ||
llim = read(g, "llim") | ||
v = [read(g, "MPO[$(i)]", ITensor) for i in 1:N] | ||
return MPO(v, llim, rlim) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using HDF5: HDF5, attributes, create_group, open_group, read, write | ||
using ITensors: ITensor | ||
using ITensors.ITensorMPS: MPS | ||
|
||
function HDF5.write(parent::Union{HDF5.File,HDF5.Group}, name::AbstractString, M::MPS) | ||
g = create_group(parent, name) | ||
attributes(g)["type"] = "MPS" | ||
attributes(g)["version"] = 1 | ||
N = length(M) | ||
write(g, "length", N) | ||
write(g, "rlim", M.rlim) | ||
write(g, "llim", M.llim) | ||
for n in 1:N | ||
write(g, "MPS[$(n)]", M[n]) | ||
end | ||
end | ||
|
||
function HDF5.read(parent::Union{HDF5.File,HDF5.Group}, name::AbstractString, ::Type{MPS}) | ||
g = open_group(parent, name) | ||
if read(attributes(g)["type"]) != "MPS" | ||
error("HDF5 group or file does not contain MPS data") | ||
end | ||
N = read(g, "length") | ||
rlim = read(g, "rlim") | ||
llim = read(g, "llim") | ||
v = [read(g, "MPS[$(i)]", ITensor) for i in 1:N] | ||
return MPS(v, llim, rlim) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module ITensorsHDF5Ext | ||
|
||
include("index.jl") | ||
include("itensor.jl") | ||
include("qnindex.jl") | ||
include("indexset.jl") | ||
include("qn.jl") | ||
include("tagset.jl") | ||
include("ITensorMPS/mps.jl") | ||
include("ITensorMPS/mpo.jl") | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using HDF5: HDF5, attributes, create_group, open_group, read, write | ||
using ITensors: Arrow, dim, dir, id, Index, plev, QNBlocks, space, tags, TagSet | ||
|
||
function HDF5.write(parent::Union{HDF5.File,HDF5.Group}, name::AbstractString, I::Index) | ||
g = create_group(parent, name) | ||
attributes(g)["type"] = "Index" | ||
attributes(g)["version"] = 1 | ||
write(g, "id", id(I)) | ||
write(g, "dim", dim(I)) | ||
write(g, "dir", Int(dir(I))) | ||
write(g, "tags", tags(I)) | ||
write(g, "plev", plev(I)) | ||
if typeof(space(I)) == Int | ||
attributes(g)["space_type"] = "Int" | ||
elseif typeof(space(I)) == QNBlocks | ||
attributes(g)["space_type"] = "QNBlocks" | ||
write(g, "space", space(I)) | ||
else | ||
error("Index space type not recognized") | ||
end | ||
end | ||
|
||
function HDF5.read(parent::Union{HDF5.File,HDF5.Group}, name::AbstractString, ::Type{Index}) | ||
g = open_group(parent, name) | ||
if read(attributes(g)["type"]) != "Index" | ||
error("HDF5 group or file does not contain Index data") | ||
end | ||
id = read(g, "id") | ||
dim = read(g, "dim") | ||
dir = Arrow(read(g, "dir")) | ||
tags = read(g, "tags", TagSet) | ||
plev = read(g, "plev") | ||
space_type = "Int" | ||
if haskey(attributes(g), "space_type") | ||
space_type = read(attributes(g)["space_type"]) | ||
end | ||
if space_type == "Int" | ||
space = dim | ||
elseif space_type == "QNBlocks" | ||
space = read(g, "space", QNBlocks) | ||
end | ||
return Index(id, space, dir, tags, plev) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using HDF5: HDF5, attributes, create_group, open_group, read, write | ||
using ITensors: Index, Indices | ||
|
||
function HDF5.write(parent::Union{HDF5.File,HDF5.Group}, name::AbstractString, is::Indices) | ||
g = create_group(parent, name) | ||
attributes(g)["type"] = "IndexSet" | ||
attributes(g)["version"] = 1 | ||
N = length(is) | ||
write(g, "length", N) | ||
for n in 1:N | ||
write(g, "index_$n", is[n]) | ||
end | ||
end | ||
|
||
function HDF5.read( | ||
parent::Union{HDF5.File,HDF5.Group}, name::AbstractString, T::Type{<:Indices} | ||
) | ||
g = open_group(parent, name) | ||
if read(attributes(g)["type"]) != "IndexSet" | ||
error("HDF5 group or file does not contain IndexSet data") | ||
end | ||
n = read(g, "length") | ||
return T(Index[read(g, "index_$j", Index) for j in 1:n]) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using HDF5: HDF5, attributes, create_group, open_group, read, write | ||
using ITensors: inds, itensor, ITensor, storage | ||
using NDTensors: | ||
NDTensors, BlockSparse, Combiner, Dense, Diag, DiagBlockSparse, EmptyStorage | ||
|
||
function HDF5.write(parent::Union{HDF5.File,HDF5.Group}, name::AbstractString, T::ITensor) | ||
g = create_group(parent, name) | ||
attributes(g)["type"] = "ITensor" | ||
attributes(g)["version"] = 1 | ||
write(g, "inds", inds(T)) | ||
return write(g, "storage", storage(T)) | ||
end | ||
|
||
function HDF5.read( | ||
parent::Union{HDF5.File,HDF5.Group}, name::AbstractString, ::Type{ITensor} | ||
) | ||
g = open_group(parent, name) | ||
if read(attributes(g)["type"]) != "ITensor" | ||
error("HDF5 group or file does not contain ITensor data") | ||
end | ||
inds = read(g, "inds", Vector{<:Index}) | ||
|
||
# check input file for key name of ITensor data | ||
# ITensors.jl <= v0.1.x uses `store` as key | ||
# whereas ITensors.jl >= v0.2.x uses `storage` as key | ||
for key in ["storage", "store"] | ||
if haskey(g, key) | ||
stypestr = read(attributes(open_group(g, key))["type"]) | ||
stype = eval(Meta.parse(stypestr)) | ||
storage = read(g, key, stype) | ||
return itensor(storage, inds) | ||
end | ||
end | ||
return error("HDF5 file: $(g) does not contain correct ITensor data.\nNeither key | ||
`store` nor `storage` could be found.") | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using HDF5: HDF5, attributes, create_group, open_group, read, write | ||
using ITensors: maxQNs, modulus, name, QN, QNVal, val | ||
|
||
function HDF5.write(parent::Union{HDF5.File,HDF5.Group}, gname::AbstractString, q::QN) | ||
g = create_group(parent, gname) | ||
attributes(g)["type"] = "QN" | ||
attributes(g)["version"] = 1 | ||
names = [String(name(q[n])) for n in 1:maxQNs] | ||
vals = [val(q[n]) for n in 1:maxQNs] | ||
mods = [modulus(q[n]) for n in 1:maxQNs] | ||
write(g, "names", names) | ||
write(g, "vals", vals) | ||
return write(g, "mods", mods) | ||
end | ||
|
||
function HDF5.read(parent::Union{HDF5.File,HDF5.Group}, name::AbstractString, ::Type{QN}) | ||
g = open_group(parent, name) | ||
if read(attributes(g)["type"]) != "QN" | ||
error("HDF5 group or file does not contain QN data") | ||
end | ||
names = read(g, "names") | ||
vals = read(g, "vals") | ||
mods = read(g, "mods") | ||
mqn = ntuple(n -> QNVal(names[n], vals[n], mods[n]), maxQNs) | ||
return QN(mqn) | ||
end |
Oops, something went wrong.