Skip to content

Commit 57ff978

Browse files
committed
module to calculate the local estimator of any operator
1 parent 8ec3606 commit 57ff978

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

src/MCEstimator.jl

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
module MCEstimator
2+
3+
using TightBindingToolkit, LinearAlgebra, Logging, SparseArrays
4+
5+
using ..VarMonteCarloToolkit.MCConfig: Config, GetFockState, GetOccupancy
6+
7+
8+
##### The estimator of the operator O is given by ∑_{x'} [<x'| O | x>*|x'|/|x|], where |x| is the the Slater determinant of a Fock state |x>.
9+
function LocalEstimator(config::Config, sites::Vector{Int64}, Operators::Vector{SparseMatrixCSC{Float64, Int64}})::ComplexF64
10+
##### sites is a vector of lattice sites on which the operators act.
11+
##### Operators is a vector of local operators acting on the sites. Each operator is a sparse matrix in the full local Fock basis.
12+
13+
FinalFockSubStates = kron(selectdim.(adjoint.(Operators), 2, config.FockState[sites])...) ##### the final Fock state in the subspace where the operators act after the action of the operators. The non-zero indices of this sparse vector tells us the final posisble Fock sub-states |x'> where the operators take the current configuration, |x> to, and the corresponding non-zero values tell us the expectation value <x'| O | x>.
14+
localFockDimensions = Operators[begin].m
15+
localDim = log2(localFockDimensions)
16+
17+
estimator::ComplexF64 = 0.0 + 0.0im
18+
##### TODO : This loop can be broadcasted?
19+
for finalSubState in FinalFockSubStates.nzind
20+
##### The final fock state is the same in all the sites where the operators do not act.
21+
finalFullFockState = copy(config.FockState)
22+
finalFullFockState[sites] = reverse(digits(finalSubState - 1, localFockDimensions, pad = length(sites))) ##### a given final fock sub-state is converted into a vector of ints representing the final fock state on each site where the operators act.
23+
24+
expectation = FinalFockSubStates[finalSubState] ##### the expectation value <x'| O | x> for the final Fock sub-state |x'>.
25+
26+
finalOccupancy = GetOccupancy(finalFullFockState, localDim) ##### the final occupancy vector in the sites sub-space for the final Fock state |x'>.
27+
@assert sum(finalOccupancy) == config.ParticleCount "Operators being measured must conserve the number of particles."
28+
29+
change = finalOccupancy - config.Occupancy ##### the change in the occupancy vector in the sites sub-space.
30+
annihilated = findall(==(-1), change) ##### the orbitals that are annihilated by the operators.
31+
created = findall(==(1), change) ##### the orbitals that are created by the operators.
32+
33+
movedParticles = getindex.(Ref(config.kel), annihilated)
34+
SlaterRatio = det(config.W[movedParticles, created]) ##### the ratio of the Slater determinant matrix elements for the final and initial Fock states.
35+
estimator += expectation * SlaterRatio ##### the expectation value of the operator O.
36+
end
37+
38+
return estimator
39+
40+
end
41+
42+
43+
44+
45+
46+
47+
48+
49+
50+
51+
52+
53+
54+
55+
56+
57+
58+
59+
60+
61+
62+
63+
64+
65+
66+
67+
68+
69+
70+
71+
72+
73+
74+
75+
76+
77+
78+
79+
80+
81+
82+
83+
84+
85+
86+
87+
88+
89+
90+
91+
92+
93+
94+
95+
96+
97+
98+
99+
100+
101+
102+
103+
104+
105+
end

0 commit comments

Comments
 (0)