Skip to content

Commit

Permalink
refactoring, timings and corrected updating of quantum numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
abhirup-m committed Sep 18, 2024
1 parent ae29555 commit 8c44630
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions src/iterDiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,26 @@ function IterDiag(
end

operators = CreateProductOperator(create[1], operators, newSitesFlow[1])
totalNumOperator = sum([operators[("n", [site])] for site in currentSites])

energyPerSite = Float64[]
@showprogress for (step, hamlt) in enumerate(hamltFlow)
for (type, members, strength) in hamlt
@time for (type, members, strength) in hamlt
hamltMatrix += strength * operators[(type, members)]
end
println("Hamiltonian size = ", size(hamltMatrix))
rotation = zeros(size(hamltMatrix)...)
eigVals = zeros(size(hamltMatrix)[2])
if !isempty(quantumNos)
for qantumNo in unique(quantumNos)
indices = findall(==(qantumNo), quantumNos)
numCaptured = 0
for quantumNo in unique(quantumNos)
indices = findall(==(quantumNo), quantumNos)
numCaptured += length(indices)
F = eigen(Hermitian(hamltMatrix[indices, indices]))
rotation[indices, indices] .= F.vectors
eigVals[indices] .= F.values
end
@assert numCaptured == length(quantumNos)
sortSequence = sortperm(eigVals)
rotation = rotation[:, sortperm(eigVals)]
quantumNos = quantumNos[sortperm(eigVals)]
Expand All @@ -146,6 +151,18 @@ function IterDiag(
for col in eachcol(rotation)]
end

@time if step == length(hamltFlow)
serialize(savePaths[step], Dict("basis" => rotation,
"eigVals" => eigVals,
"quantumNos" => quantumNos,
"currentSites" => currentSites,
"newSites" => newSitesFlow[step],
"bondAntiSymmzer" => bondAntiSymmzer,
)
)
break
end

if isnothing(quantumNoReq) && length(eigVals) > maxSize
# ensure we aren't truncating in the middle of degenerate states
rotation = rotation[:, eigVals .≤ eigVals[maxSize] + abs(eigVals[maxSize]) * degenTol]
Expand All @@ -169,18 +186,6 @@ function IterDiag(
eigVals = eigVals[retainBasisVectors]
end

if step == length(hamltFlow)
serialize(savePaths[step], Dict("basis" => rotation,
"eigVals" => eigVals,
"quantumNos" => quantumNos,
"currentSites" => currentSites,
"newSites" => newSitesFlow[step],
"bondAntiSymmzer" => bondAntiSymmzer,
)
)
break
end

newBasis = BasisStates(length(newSitesFlow[step+1]))

identityEnv = length(newSitesFlow[step+1]) == 1 ? I(2) : kron(fill(I(2), length(newSitesFlow[step+1]))...)
Expand Down Expand Up @@ -230,12 +235,12 @@ function IterDiag(

# expand new operators
bondAntiSymmzer = rotation' * bondAntiSymmzer * rotation
for site in newSitesFlow[step+1]
@time for site in newSitesFlow[step+1]
operators[("+", [site])] = kron(bondAntiSymmzer, operators[("+", [site])])
operators = CreateDNH(operators, site)
end

operators = CreateProductOperator(create[step+1], operators, newSitesFlow[step+1])
@time operators = CreateProductOperator(create[step+1], operators, newSitesFlow[step+1])

# expand the antisymmetrizer
bondAntiSymmzer = kron(bondAntiSymmzer, fill(sigmaz, length(newSitesFlow[step+1]))...)
Expand Down

0 comments on commit 8c44630

Please sign in to comment.