Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ITensors] ITensorMPS submodule #1356

Merged
merged 22 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
bad4288
New ITensorMPS module and folder. Moved autompo folder.
emstoudenmire Mar 17, 2024
d67496d
Fixing many imports and exports to get tests passing
emstoudenmire Mar 17, 2024
f372393
More imports and exports fixed, more tests passing
emstoudenmire Mar 17, 2024
e678b10
More import and test fixes
emstoudenmire Mar 17, 2024
1a7772d
Imports and test fixes and adjustments
emstoudenmire Mar 18, 2024
5cef64b
Formatting
emstoudenmire Mar 18, 2024
0d712e2
Move import into imports.jl
emstoudenmire Mar 18, 2024
e5ca03b
Rename ITensorLegacyMPS test folder to ITensorMPS
emstoudenmire Mar 18, 2024
1f57995
Remove `nothing` lines from end of tests
emstoudenmire Mar 19, 2024
a3ef553
Remove AbstractMPS from ITensors exports
emstoudenmire Mar 19, 2024
77e5281
Use Reexport to export ITensorMPS methods
emstoudenmire Mar 19, 2024
80673cd
More import and export cleaning
emstoudenmire Mar 19, 2024
2032c5b
Remove unnecessary exports
emstoudenmire Mar 19, 2024
d9740bb
More cleanup of imports and exports.
emstoudenmire Mar 21, 2024
05fdb11
Remove unused iterativesolvers.jl and related codes
emstoudenmire Mar 21, 2024
5e4c33c
Make HDF5 using more specific
emstoudenmire Mar 21, 2024
556b99e
Remove extra nothing lines for suppressing output
emstoudenmire Mar 21, 2024
0879ecd
Merge branch 'main' into ITensorMPS_module
emstoudenmire Mar 22, 2024
d95cdbd
Change import to using in tests
emstoudenmire Mar 22, 2024
63cbda7
Fix export of contract
emstoudenmire Mar 22, 2024
1c23db7
Remove name of deleted test
emstoudenmire Mar 22, 2024
eb0d0d9
Remove contract from imports and explicitly label in code
emstoudenmire Mar 22, 2024
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
37 changes: 37 additions & 0 deletions src/ITensorMPS/ITensorMPS.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

emstoudenmire marked this conversation as resolved.
Show resolved Hide resolved
module ITensorMPS

using Adapt
using HDF5
using ..ITensors
using IsApprox
using KrylovKit
using Printf
using Random
using TupleTools
emstoudenmire marked this conversation as resolved.
Show resolved Hide resolved

import ..ITensors.Ops: params
emstoudenmire marked this conversation as resolved.
Show resolved Hide resolved

include("imports.jl")
include("exports.jl")
include("abstractmps.jl")
include("mps.jl")
include("mpo.jl")
include("sweeps.jl")
include("abstractprojmpo/abstractprojmpo.jl")
include("abstractprojmpo/projmpo.jl")
include("abstractprojmpo/diskprojmpo.jl")
include("abstractprojmpo/projmposum.jl")
include("abstractprojmpo/projmps.jl")
include("abstractprojmpo/projmpo_mps.jl")
include("observer.jl")
include("dmrg.jl")
include("adapt.jl")
include("autompo/matelem.jl")
include("autompo/qnmatelem.jl")
include("autompo/opsum_to_mpo_generic.jl")
include("autompo/opsum_to_mpo.jl")
include("autompo/opsum_to_mpo_qn.jl")
include("deprecated.jl")

end # module ITensorMPS
8 changes: 4 additions & 4 deletions src/mps/abstractmps.jl → src/ITensorMPS/abstractmps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,7 @@ function deprecate_make_inds_match!(
make_inds_match = false
end
if !hassameinds(siteinds, M1dag, M2) && make_inds_match
warn_once(inner_mps_mpo_mps_deprecation_warning(), :inner_mps_mps)
ITensors.warn_once(inner_mps_mpo_mps_deprecation_warning(), :inner_mps_mps)
replace_siteinds!(M1dag, siteindsM2)
end
return M1dag, M2
Expand Down Expand Up @@ -1776,7 +1776,7 @@ function _fermionic_swap(s1::Index, s2::Index)
if _isodd_fermionic_parity(s1, n1) && _isodd_fermionic_parity(s2, n2)
dval = -1.0
end
Tb = blockview(tensor(T), b)
Tb = ITensors.blockview(tensor(T), b)
mat_dim = prod(dims(Tb)[1:2])
Tbr = reshape(Tb, mat_dim, mat_dim)
for i in diagind(Tbr)
Expand Down Expand Up @@ -1847,9 +1847,9 @@ function setindex!(
sites = sites0[[perm...]]
# Check if the site indices
# are fermionic
if !using_auto_fermion() && any(anyfermionic, sites)
if !using_auto_fermion() && any(ITensors.anyfermionic, sites)
if length(sites) == 2 && ψ isa MPS
if all(allfermionic, sites)
if all(ITensors.allfermionic, sites)
s0 = Index.(sites0)

# TODO: the Fermionic swap is could be diagonal,
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ subtract!(os::OpSum, o::Tuple) = add!(os, -Ops.op_term(o))
function isfermionic(t::Vector{Op}, sites)
p = +1
for op in t
if has_fermion_string(name(op), sites[site(op)])
if has_fermion_string(ITensors.name(op), sites[site(op)])
p *= -1
end
end
Expand Down Expand Up @@ -299,8 +299,8 @@ function MPO(os::OpSum, sites::Vector{<:Index}; splitblocks=true, kwargs...)::MP
return M
end

function MPO(eltype::Type{<:Number}, os::OpSum, sites::Vector{<:Index}; kwargs...)
return NDTensors.convert_scalartype(eltype, MPO(os, sites; kwargs...))
function MPO(elt::Type{<:Number}, os::OpSum, sites::Vector{<:Index}; kwargs...)
mtfishman marked this conversation as resolved.
Show resolved Hide resolved
return NDTensors.convert_scalartype(elt, MPO(os, sites; kwargs...))
end

# Conversion from other formats
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function qn_svdMPO(
llinks = Vector{QNIndex}(undef, N + 1)
# Set dir=In for fermionic ordering, avoid arrow sign
# <fermions>:
linkdir = using_auto_fermion() ? In : Out
linkdir = using_auto_fermion() ? ITensors.In : ITensors.Out
llinks[1] = Index([QN() => 1, Hflux => 1]; tags="Link,l=0", dir=linkdir)
for n in 1:N
qi = Vector{Pair{QN,Int}}()
Expand Down Expand Up @@ -220,7 +220,7 @@ function qn_svdMPO(
end

b = loc(rq, cq)
T = BlockSparseTensor(ValType, [b], (dag(ll), rl))
T = ITensors.NDTensors.BlockSparseTensor(ValType, [b], (dag(ll), rl))
T[b] .= M

H[n] += (itensor(T) * Op)
Expand All @@ -230,13 +230,13 @@ function qn_svdMPO(
# Put in ending identity operator
Id = op("Id", sites[n])
b = Block(1, 1)
T = BlockSparseTensor(ValType, [b], (dag(ll), rl))
T = ITensors.NDTensors.BlockSparseTensor(ValType, [b], (dag(ll), rl))
T[b] = 1
H[n] += (itensor(T) * Id)

# Put in starting identity operator
b = Block(nblocks(ll), nblocks(rl))
T = BlockSparseTensor(ValType, [b], (dag(ll), rl))
T = ITensors.NDTensors.BlockSparseTensor(ValType, [b], (dag(ll), rl))
T[b] = 1
H[n] += (itensor(T) * Id)
end # for n in 1:N
Expand Down
File renamed without changes.
34 changes: 34 additions & 0 deletions src/mps/deprecated.jl → src/ITensorMPS/deprecated.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,37 @@
# mps/abstractmps.jl
@deprecate orthoCenter(args...; kwargs...) orthocenter(args...; kwargs...)
@deprecate store(m::AbstractMPS) data(m)
@deprecate replacesites!(args...; kwargs...) ITensors.replace_siteinds!(args...; kwargs...)
@deprecate applyMPO(args...; kwargs...) contract(args...; kwargs...)
@deprecate applympo(args...; kwargs...) contract(args...; kwargs...)
@deprecate errorMPOprod(args...; kwargs...) error_contract(args...; kwargs...)
@deprecate error_mpoprod(args...; kwargs...) error_contract(args...; kwargs...)
@deprecate error_mul(args...; kwargs...) error_contract(args...; kwargs...)
@deprecate multMPO(args...; kwargs...) contract(args...; kwargs...)
@deprecate sum(A::AbstractMPS, B::AbstractMPS; kwargs...) add(A, B; kwargs...)
@deprecate multmpo(args...; kwargs...) contract(args...; kwargs...)
@deprecate set_leftlim!(args...; kwargs...) ITensors.setleftlim!(args...; kwargs...)
@deprecate set_rightlim!(args...; kwargs...) ITensors.setrightlim!(args...; kwargs...)
@deprecate tensors(args...; kwargs...) ITensors.data(args...; kwargs...)
@deprecate primelinks!(args...; kwargs...) ITensors.prime_linkinds!(args...; kwargs...)
@deprecate simlinks!(args...; kwargs...) ITensors.sim_linkinds!(args...; kwargs...)
@deprecate mul(A::AbstractMPS, B::AbstractMPS; kwargs...) contract(A, B; kwargs...)

# mps/mpo.jl
@deprecate MPO(A::MPS; kwargs...) outer(A', A; kwargs...)

# mps/mps.jl
@deprecate randomMPS(sites::Vector{<:Index}, linkdims::Integer) randomMPS(
sites; linkdims=linkdims
)
@deprecate randomMPS(ElType::Type, sites::Vector{<:Index}, linkdims::Integer) randomMPS(
ElType, sites; linkdims=linkdims
)
@deprecate randomMPS(sites::Vector{<:Index}, state, linkdims::Integer) randomMPS(
sites, state; linkdims=linkdims
)

# Pass throughs of old name to new name:

unique_siteind(A::AbstractMPS, B::AbstractMPS, j::Integer) = siteinds(uniqueind, A, B, j)

Expand Down
File renamed without changes.
134 changes: 134 additions & 0 deletions src/ITensorMPS/exports.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
export
# dmrg.jl
dmrg,

# abstractmps.jl
# Macros
@preserve_ortho,
# Methods
AbstractMPS,
add,
common_siteind,
common_siteinds,
contract,
emstoudenmire marked this conversation as resolved.
Show resolved Hide resolved
convert_eltype,
emstoudenmire marked this conversation as resolved.
Show resolved Hide resolved
convert_leaf_eltype,
emstoudenmire marked this conversation as resolved.
Show resolved Hide resolved
dag!,
emstoudenmire marked this conversation as resolved.
Show resolved Hide resolved
eltype,
emstoudenmire marked this conversation as resolved.
Show resolved Hide resolved
findfirstsiteind,
findfirstsiteinds,
findsite,
findsites,
firstsiteind,
firstsiteinds,
logdot,
loginner,
lognorm,
movesite,
movesites,
ndims,
emstoudenmire marked this conversation as resolved.
Show resolved Hide resolved
normalize,
ortho_lims,
orthocenter,
promote_itensor_eltype,
reset_ortho_lims!,
set_ortho_lims!,
siteinds,
sim!,

# autompo/
AutoMPO,
add!,

# mpo.jl
# Types
MPO,
# Methods
error_contract,
maxlinkdim,
orthogonalize,
orthogonalize!,
outer,
projector,
randomMPO,
truncate,
truncate!,
unique_siteind,
unique_siteinds,

# mps.jl
# Types
MPS,
# Methods
⋅,
correlation_matrix,
expect,
inner,
isortho,
linkdim,
linkdims,
linkind,
linkinds,
productMPS,
randomMPS,
replacebond,
replacebond!,
sample,
sample!,
siteind,
siteinds,
replace_siteinds!,
replace_siteinds,
swapbondsites,
totalqn,

# observer.jl
# Types
AbstractObserver,
DMRGObserver,
DMRGMeasurement,
NoObserver,
# Methods
checkdone!,
energies,
measure!,
measurements,
truncerrors,

# projmpo.jl
checkflux,
disk,
ProjMPO,
lproj,
product,
rproj,
noiseterm,
nsite,
position!,

# projmposum.jl
ProjMPOSum,

# projmpo_mps.jl
ProjMPO_MPS,

# sweeps.jl
Sweeps,
cutoff,
cutoff!,
get_cutoffs,
get_maxdims,
get_mindims,
get_noises,
maxdim,
maxdim!,
mindim,
mindim!,
noise,
noise!,
nsweep,
setmaxdim!,
setmindim!,
setcutoff!,
setnoise!,
sweepnext
Loading
Loading