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

Fermionic OpSum to TTN constructor #122

Merged
merged 41 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
cadd5a0
Initial commit, untested addition of compatibility with fermionic sit…
b-kloss Jan 12, 2024
58defab
Remove debugging output.
b-kloss Jan 12, 2024
b53f59d
Add missing end.
b-kloss Jan 12, 2024
b5b37d4
Autofermion sign working for fermions, but not for electrons yet.
b-kloss Jan 12, 2024
614669e
Fix flux for fermions by daggering Op. Still broken when using QNs an…
b-kloss Jan 12, 2024
9cd226b
Add hubbard and tight-binding Hamiltonian to models.
b-kloss Jan 12, 2024
e47fa91
Code working for fermions and electrons. Prior failure due to bug in …
b-kloss Jan 12, 2024
769f51a
Move most of complicated qn/arrow-dir logic to the beginning of ttn_svd.
b-kloss Jan 12, 2024
d1d731f
Cleanup. Leaving debug asserts in for the time being.
b-kloss Jan 12, 2024
82d05f2
Restore state with regards to auto-fermion after test.
b-kloss Jan 12, 2024
f54d59b
Merge branch 'main' into AutoTTNO-fix-fermion
b-kloss Jan 12, 2024
b933301
Restore usual arrow directions.
b-kloss Jan 12, 2024
beeebfc
Fix tests. Lower threshold in tests and workaround an issue when comp…
b-kloss Jan 12, 2024
d17c7ae
Add DMRG test for QNs + fermions on tree.
b-kloss Jan 14, 2024
68eb46d
Fix typo in hubbard model.
b-kloss Jan 14, 2024
a03b4a7
Add ToDo annotation for randomTTN
b-kloss Jan 14, 2024
4135a4f
Format.
b-kloss Jan 14, 2024
c96bb49
Remove commented out models.
b-kloss Jan 15, 2024
c03b359
Implement suggested improvements to model, including general nth-neig…
b-kloss Jan 21, 2024
0d96aff
Adapt test_dmrg and test_dmrg_x, remove usage of Sweeps.
b-kloss Jan 21, 2024
b5738ad
Merge branch 'main' into AutoTTNO-fix-fermion
b-kloss Jan 21, 2024
93ce636
Change use of nsite to nsites.
b-kloss Jan 21, 2024
c1d0909
Refactor fermionic test and add comparison with single-particle energ…
b-kloss Jan 21, 2024
6822fe5
Add comparison with JW string ITensors.MPO for fermions to DMRG.
b-kloss Jan 21, 2024
4b58afd
ITensorGaussianMPS
b-kloss Jan 21, 2024
f6a43e4
Clean up test_opsum_to_ttn.jl
b-kloss Jan 21, 2024
fe8be5c
Format.
b-kloss Jan 21, 2024
53a7b16
Format models.
b-kloss Jan 21, 2024
0eded4f
Apply suggestions from code review
b-kloss Jan 22, 2024
d64c4c7
Minor edits on models and import LinearAlgebra.eigvals in test.
Jan 22, 2024
69138fa
Switch internal index direction to In regardless of whether autofermi…
Jan 22, 2024
ee0fa95
Have non-fermionic QN test in DMRG run with autofermion-sign enabled.
Jan 22, 2024
5993c58
Remove output from src/models.jl
Jan 22, 2024
e0ea0f4
Improve ITensor to matrix conversion.
Jan 22, 2024
4e76b10
Format.
Jan 22, 2024
46b783c
Simplify ITensor Matrix conversion.
Jan 22, 2024
5a24c2a
Simplify expression for index direction and have a shallow copy of si…
Jan 22, 2024
75ba320
Add comment to remove autofermion enabling/disabling part of test onc…
Jan 22, 2024
872d037
Edit comment for copy os sites in ttn_svd.
Jan 22, 2024
0725a9f
Remove outdated comment
mtfishman Jan 22, 2024
24fc702
Style update
mtfishman Jan 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
9 changes: 3 additions & 6 deletions src/treetensornetworks/opsum_to_ttn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,9 @@ function ttn_svd(
maxdim::Int=typemax(Int),
cutoff=eps(real(coefficient_type)) * 10,
)
# fermionic and non-fermionic QNIndices have opposite default index direction
# which causes problems when using the autofermion sign with non-fermionic QNIndex
# ToDo: remove conditional when this is addressed
linkdir_ref = ITensors.using_auto_fermion() ? ITensors.In : ITensors.In
linkdir_ref = ITensors.In # safe to always use autofermion default here

sites = deepcopy(sites0) # deepcopy because of inplace modification to handle internal indices
sites = copy(sites0) # deepcopy because of inplace modification to handle internal indices
b-kloss marked this conversation as resolved.
Show resolved Hide resolved
edgetype_sites = edgetype(sites)
vertextype_sites = vertextype(sites)
thishasqns = any(v -> hasqns(sites[v]), vertices(sites))
Expand Down Expand Up @@ -99,7 +96,7 @@ function ttn_svd(
for v in vs
is_internal[v] = isempty(sites[v])
if isempty(sites[v])
push!(sites[v], Index(Hflux => 1))
sites[v] = [Index(Hflux => 1)]
end
end
inbond_coefs = Dict(
Expand Down
18 changes: 5 additions & 13 deletions test/test_opsum_to_ttn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,11 @@ using Random
using LinearAlgebra: eigvals
using Test

function _to_matrices_with_same_inds(t::ITensor, s::ITensor)
function to_matrix(t::ITensor)
c = combiner(inds(t; plev=0))
tc = (t * c) * dag(c')
c2 = combiner(inds(s; plev=0))
sc = (s * c2) * dag(c2')

cind = combinedind(c)
cind2 = combinedind(c2)
sc = replaceinds(sc, (cind2, cind2'), (cind, cind'))

tm = matrix(tc, cind', cind)
sm = matrix(sc, cind', cind)
return tm, sm
return matrix(tc, cind', cind)
end

@testset "OpSum to TTN converter" begin
Expand Down Expand Up @@ -186,7 +178,8 @@ end

@test_broken Tmpo ≈ Tttno # ToDo fix comparison for fermionic tensors
# In the meantime: matricize tensors and convert to dense Matrix to compare element by element
dTmm, dTtm = _to_matrices_with_same_inds(Tmpo, Tttno)
dTmm = to_matrix(Tmpo)
dTtm = to_matrix(Tttno)
@test any(>(1e-14), dTmm - dTtm)

# also compare with energies obtained from single-particle Hamiltonian
Expand Down Expand Up @@ -240,13 +233,12 @@ end
Hsvd = TTN(H, is_missing_site; root_vertex=root_vertex, cutoff=1e-10)
# get corresponding MPO Hamiltonian
Hline = MPO(relabel_sites(H, vmap), sites)
# compare resulting sparse Hamiltonians

# compare resulting sparse Hamiltonians
@disable_warn_order begin
Tmpo = prod(Hline)
Tttno = contract(Hsvd)
end

@test Tttno ≈ Tmpo rtol = 1e-6

Hsvd_lr = TTN(
Expand Down
Loading