Skip to content

Commit

Permalink
added option to calculate correlations throughout the iterations
Browse files Browse the repository at this point in the history
  • Loading branch information
abhirup-m committed Nov 30, 2024
1 parent 51fd2fa commit 6f03439
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions src/iterDiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ function IterDiag(
silent::Bool,
specFuncNames::Vector{String},
maxMaxSize::Int64,
calculateThroughout::Bool,
)

# ensure each term of the Hamiltonian is sorted in indices
Expand Down Expand Up @@ -459,9 +460,9 @@ function IterDiag(
end
end

resultsDict = Dict{String, Union{Nothing, Float64}}(name => nothing for name in keys(correlationDefDict))
resultsDict = Dict{String, Union{Nothing, Float64}}(name => ifelse(calculateThroughout, FLoat64[], nothing) for name in keys(correlationDefDict))
@assert "energyPerSite" keys(resultsDict)
resultsDict["energyPerSite"] = nothing
resultsDict["energyPerSite"] = calculateThroughout, FLoat64[], nothing)

pbar = Progress(length(hamltFlow); enabled=!silent)
for (step, hamlt) in enumerate(hamltFlow)
Expand All @@ -485,7 +486,11 @@ function IterDiag(
)
)

resultsDict["energyPerSite"] = eigVals[1]/maximum(currentSites)
if calculateThroughout
push!(resultsDict["energyPerSite"], eigVals[1]/maximum(currentSites))
else
resultsDict["energyPerSite"] = eigVals[1]/maximum(currentSites)
end

indices = 1:length(eigVals)
if !isnothing(corrQuantumNoReq) && !isnothing(quantumNos)
Expand All @@ -496,14 +501,35 @@ function IterDiag(
# calculate correlations using the ground state of the final step
for (name, correlationDef) in correlationDefDict
if !isnothing(corrOperatorDict[name])
resultsDict[name] = finalState' * corrOperatorDict[name] * finalState
if calculateThroughout
push!(resultsDict[name], currentState' * corrOperatorDict[name] * currentState)
else
resultsDict[name] = finalState' * corrOperatorDict[name] * finalState
end
end
end

next!(pbar; showvalues=[("Size", size(hamltMatrix))])
break
end

if calculateThroughout
push!(resultsDict["energyPerSite"], eigVals[1]/maximum(currentSites))

indices = 1:length(eigVals)
if !isnothing(corrQuantumNoReq) && !isnothing(quantumNos)
indices = findall(q -> corrQuantumNoReq(q, maximum(currentSites)), quantumNos)
end
currentState = rotation[:, indices[sortperm(eigVals[indices])[1]]]

# calculate correlations using the ground state of the final step
for (name, correlationDef) in correlationDefDict
if !isnothing(corrOperatorDict[name])
push!(resultsDict[name], currentState' * corrOperatorDict[name] * currentState)
end
end
end

# construct a basis and identity matrix for the new sites
newBasis = BasisStates(length(newSitesFlow[step+1]))

Expand Down Expand Up @@ -604,6 +630,7 @@ function IterDiag(
specFuncDefDict::Dict{String, Vector{Tuple{String, Vector{Int64}, Float64}}}=Dict{String, Vector{Tuple{String, Vector{Int64}, Float64}}}(),
silent::Bool=false,
maxMaxSize::Int64=0,
calculateThroughout::Bool=false,
)
@assert maxMaxSize == 0 || maxMaxSize maxSize

Expand Down Expand Up @@ -754,6 +781,7 @@ function IterDiag(
silent,
collect(values(specFuncToCorrMap)),
maxMaxSize,
calculateThroughout,
)

# if specFuncOperators was requested, convert them back to
Expand Down

0 comments on commit 6f03439

Please sign in to comment.