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

SuperfluidCorrelator and StringCorrelator #227

Merged
merged 41 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
b07894d
implement superfluid correlator
ewan353 Sep 19, 2023
09ecb19
Merge branch 'develop' into feature/superfluid-correlator
rohan-kumar-uoa Nov 27, 2023
6936e53
Completed docstring for SuperfluidCorrelator structure in correlation…
rohan-kumar-uoa Nov 30, 2023
b0f55dc
Defined the StringCorrelator structure, its print behaviour, and note…
rohan-kumar-uoa Nov 30, 2023
24424e4
Defined diagonal elements of the StringCorrelator matrix
rohan-kumar-uoa Nov 30, 2023
f678274
Specified that there are no off-diagonal entries in the StringCorrela…
rohan-kumar-uoa Nov 30, 2023
a41cb7c
Added docstring for string correlator function
rohan-kumar-uoa Nov 30, 2023
b1196e3
Added preliminary test functions for StringCorrelator and export stat…
rohan-kumar-uoa Nov 30, 2023
dee2a97
Fixed StringCorrelator function definition and added support for Stri…
rohan-kumar-uoa Dec 1, 2023
ee64158
Appended StringCorrelator and SuperfluidCorrelator to @docs in hamilt…
rohan-kumar-uoa Dec 1, 2023
250addb
Removed whitespace between StringCorrelator docstring and structure/f…
rohan-kumar-uoa Dec 1, 2023
79cdf9c
Made changes to SuperfluidCorrelator, StringCorrelator and their test…
rohan-kumar-uoa Dec 2, 2023
4228197
Added brackets
rohan-kumar-uoa Dec 3, 2023
a4dfaed
Edited documentation for SuperfluidCorrelator
tpa447 Dec 3, 2023
bb61bf8
Tests added
tpa447 Dec 4, 2023
713077f
Merge branch 'develop' into feature/superfluid-correlator
rohan-kumar-uoa Dec 4, 2023
fc6c6c7
Added test for show function
tpa447 Dec 5, 2023
b868f97
Added tests for show function
tpa447 Dec 5, 2023
83564ea
Added working tests for show methods of StringCorrelator,SuperfluidCo…
rohan-kumar-uoa Dec 6, 2023
332d430
Removed some testing comments and whitespace
rohan-kumar-uoa Dec 6, 2023
6f0c473
Pulled from online repository, handled conflicts, ensured written cor…
rohan-kumar-uoa Dec 6, 2023
582fa0e
Testing StringCorrelator function with alternate function definition
rohan-kumar-uoa Dec 13, 2023
29af492
Altered StringCorrelator definition to check for integer filling prio…
rohan-kumar-uoa Dec 14, 2023
224b5c1
Fixed implementation of the above
rohan-kumar-uoa Dec 14, 2023
ad2abc2
Removed Project.toml accidental edit
rohan-kumar-uoa Dec 14, 2023
b05b669
Removed comments
rohan-kumar-uoa Jan 16, 2024
9577c41
Added StringCorrelator Tests for correct return types
rohan-kumar-uoa Jan 16, 2024
a4a8e80
Update src/Hamiltonians/correlation_functions.jl
rohan-kumar-uoa Jan 17, 2024
c0c8eaa
Updated docstring of StringCorrelator
rohan-kumar-uoa Jan 17, 2024
e4f1076
Merge branch 'feature/superfluid-correlator' of https://github.com/jo…
rohan-kumar-uoa Jan 17, 2024
7cf8ebb
Update src/Hamiltonians/correlation_functions.jl
rohan-kumar-uoa Jan 17, 2024
080dd54
Update src/Hamiltonians/correlation_functions.jl
rohan-kumar-uoa Jan 17, 2024
6e3e49f
Update src/Hamiltonians/correlation_functions.jl. Branched StringCorr…
rohan-kumar-uoa Jan 17, 2024
ca4da60
Merge branch 'feature/superfluid-correlator' of https://github.com/jo…
rohan-kumar-uoa Jan 17, 2024
9ee513a
Added returns to updated StringCorrelator
rohan-kumar-uoa Jan 17, 2024
36ab44c
Update test/Hamiltonians.jl
rohan-kumar-uoa Jan 18, 2024
b42b037
Update test/Hamiltonians.jl for num_offdiagonals check
rohan-kumar-uoa Jan 18, 2024
a29deeb
Update test/Hamiltonians.jl
rohan-kumar-uoa Jan 18, 2024
2a3afca
Updated docstring of SuperfluidCorrelator and StringCorrelator
rohan-kumar-uoa Jan 18, 2024
77c8022
Added support for OccupationNumberFS
rohan-kumar-uoa Jan 18, 2024
9260ed3
Changing incorrect apostrophe used
rohan-kumar-uoa Jan 18, 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
2 changes: 2 additions & 0 deletions docs/src/hamiltonians.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ them into [`AllOverlaps`](@ref).
```@docs
G2MomCorrelator
G2RealCorrelator
SuperfluidCorrelator
StringCorrelator
DensityMatrixDiagonal
Momentum
AxialAngularMomentumHO
Expand Down
3 changes: 2 additions & 1 deletion src/Hamiltonians/Hamiltonians.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ export Stoquastic
export Transcorrelated1D
export hubbard_dispersion, continuum_dispersion

export G2MomCorrelator, G2RealCorrelator, DensityMatrixDiagonal, Momentum
export G2MomCorrelator, G2RealCorrelator, SuperfluidCorrelator, DensityMatrixDiagonal, Momentum
export StringCorrelator

export LatticeGeometry, PeriodicBoundaries, HardwallBoundaries, LadderBoundaries
export num_neighbours, neighbour_site, num_dimensions
Expand Down
137 changes: 137 additions & 0 deletions src/Hamiltonians/correlation_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,140 @@ function get_offdiagonal(
gd = exp(-im*g.d*Δp*2π/M)*gamma
return new_add, ComplexF64(gd/M)
end

"""
SuperfluidCorrelator(d::Int) <: AbstractHamiltonian{Float64}

Operator for extracting superfluid correlation between sites separated by a distance `d` with `0 ≤ d < M`:

```math
\\hat{C}_{\\text{SF}}(d) = \\frac{1}{M} \\sum_{i}^{M} a_{i}^{\\dagger} a_{i + d}
```
Assumes a one-dimensional lattice with ``M`` sites and periodic boundary conditions. ``M`` is also the number of modes in the Fock state address.

# Usage
Superfluid correlations can be extracted from a Monte Carlo calculation by wrapping `SuperfluidCorrelator` with
[`AllOverlaps`](@ref) and passing into [`lomc!`](@ref) with the `replica` keyword argument. For an example with a
similar use of [`G2RealCorrelator`](@ref) see
[G2 Correlator Example](https://joachimbrand.github.io/Rimu.jl/previews/PR227/generated/G2-example.html).


See also [`HubbardReal1D`](@ref), [`G2RealCorrelator`](@ref), [`AbstractHamiltonian`](@ref),
and [`AllOverlaps`](@ref).
"""
struct SuperfluidCorrelator{D} <: AbstractHamiltonian{Float64}
end

SuperfluidCorrelator(d::Int) = SuperfluidCorrelator{d}()

function Base.show(io::IO, ::SuperfluidCorrelator{D}) where {D}
print(io, "SuperfluidCorrelator($D)")
end

function num_offdiagonals(::SuperfluidCorrelator, add::SingleComponentFockAddress)
return num_occupied_modes(add)
end

function get_offdiagonal(::SuperfluidCorrelator{D}, add::SingleComponentFockAddress, chosen) where {D}
src = find_occupied_mode(add, chosen)
dst = find_mode(add, mod1(src.mode + D, num_modes(add)))
address, value = excitation(add, (dst,), (src,))
return address, value / num_modes(add)
end

function diagonal_element(::SuperfluidCorrelator{0}, add::SingleComponentFockAddress)
return num_particles(add) / num_modes(add)
end
function diagonal_element(::SuperfluidCorrelator{D}, add::SingleComponentFockAddress) where {D}
return 0.0
end


"""
StringCorrelator(d::Int) <: AbstractHamiltonian{Float64}

Operator for extracting string correlation between lattice sites on a one-dimensional Hubbard lattice
separated by a distance `d` with `0 ≤ d < M`

```math
\\hat{C}_{\\text{string}}(d) = \\frac{1}{M} \\sum_{j}^{M} \\delta n_j (e^{i \\pi \\sum_{j \\leq k < j + d} \\delta n_k}) \\delta n_{j+d}
```
Here, ``\\delta \\hat{n}_j = \\hat{n}_j - \\bar{n}`` is the boson number deviation from the mean filling
number and ``\\bar{n} = N/M`` is the mean filling number of lattice sites with ``N`` particles and
``M`` lattice sites (or modes).

Assumes a one-dimensional lattice with periodic boundary conditions. For usage
see [`SuperfluidCorrelator`](@ref) and [`AllOverlaps`](@ref).

See also [`HubbardReal1D`](@ref), [`G2RealCorrelator`](@ref), [`SuperfluidCorrelator`](@ref),
[`AbstractHamiltonian`](@ref), and [`AllOverlaps`](@ref).
"""
struct StringCorrelator{D} <: AbstractHamiltonian{Float64}
end

StringCorrelator(d::Int) = StringCorrelator{d}()

function Base.show(io::IO, ::StringCorrelator{D}) where {D}
print(io, "StringCorrelator($D)")
end

LOStructure(::Type{<:StringCorrelator}) = IsDiagonal()

function diagonal_element(::StringCorrelator{0}, add::SingleComponentFockAddress)
M = num_modes(add)
N = num_particles(add)
n̄ = N/M
v = onr(add)

result = 0.0
for i in eachindex(v)
result += (v[i] - n̄)^2
end

return result / M
end

num_offdiagonals(::StringCorrelator, ::SingleComponentFockAddress) = 0

function diagonal_element(::StringCorrelator{D}, add::SingleComponentFockAddress) where {D}
M = num_modes(add)
N = num_particles(add)
d = mod(D, M)

if !ismissing(N) && iszero(N % M)
return _string_diagonal_real(d, add)
else
return _string_diagonal_complex(d, add)
end
end

function _string_diagonal_complex(d, add)
M = num_modes(add)
N = num_particles(add)
n̄ = N/M
v = onr(add)

result = ComplexF64(0)
for i in eachindex(v)
phase_sum = sum((v[mod1(k, M)] - n̄) for k in i:1:(i+d-1))

result += (v[i] - n̄) * exp(pi * im * phase_sum) * (v[mod1(i + d, M)] - n̄)
end

return result / M
end
function _string_diagonal_real(d, add)
M = num_modes(add)
N = num_particles(add)
n̄ = N ÷ M
v = onr(add)

result = 0.0
for i in eachindex(v)
phase_sum = sum((v[mod1(k, M)] - n̄) for k in i:1:(i+d-1))

result += (v[i] - n̄) * (-1)^phase_sum * (v[mod1(i + d, M)] - n̄)
end

return result / M
end
82 changes: 82 additions & 0 deletions test/Hamiltonians.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ using Random
using Rimu
using Test
using DataFrames
using Suppressor

function exact_energy(ham)
dv = DVec(starting_address(ham) => 1.0)
Expand Down Expand Up @@ -837,6 +838,87 @@ end
# offdiagonals
@test num_offdiagonals(G2RealCorrelator(0), add1) == 0
@test num_offdiagonals(G2RealCorrelator(0), comp) == 0

# Test show method
d = 5
output = @capture_out print(G2RealCorrelator(d))
@test output == "G2RealCorrelator($d)"
end

@testset "SuperfluidCorrelator" begin
m = 6
n1 = 4
n2 = m
add1 = BoseFS((n1,0,0,0,0,0))
add2 = near_uniform(BoseFS{n2,m})

# localised state
@test @inferred diagonal_element(SuperfluidCorrelator(0), add1) == n1/m
@test @inferred diagonal_element(SuperfluidCorrelator(1), add1) == 0.

# constant density state
@test diagonal_element(SuperfluidCorrelator(0), add2) == n2/m
@test diagonal_element(SuperfluidCorrelator(1), add2) == 0.

# offdiagonals
@test num_offdiagonals(SuperfluidCorrelator(0), add1) == 1
@test num_offdiagonals(SuperfluidCorrelator(0), add2) == 6

# get_offdiagonal
@test get_offdiagonal(SuperfluidCorrelator(0), add1, 1) == (add1, n1/m)
@test get_offdiagonal(SuperfluidCorrelator(1), add1, 1) == (BoseFS((3,1,0,0,0,0)), sqrt(n1)/m)
@test get_offdiagonal(SuperfluidCorrelator(0), add2, 1) == (add2, 1/m)
@test get_offdiagonal(SuperfluidCorrelator(1), add2, 1) == (BoseFS((0,2,1,1,1,1)), sqrt(2)/m)

# Test show method
d = 5
output = @capture_out print(SuperfluidCorrelator(d))
@test output == "SuperfluidCorrelator($d)"
end

@testset "StringCorrelator" begin
m = 6
n1 = 4
n2 = m

# unital refers to n̄=1
non_unital_localised_state = BoseFS((n1,0,0,0,0,0))
non_unital_uniform_state = near_uniform(non_unital_localised_state)

localised_state = BoseFS((n2,0,0,0,0,0))
uniform_state = near_uniform(BoseFS{n2,m})

S0 = StringCorrelator(0)
S1 = StringCorrelator(1)
S2 = StringCorrelator(2)

@test num_offdiagonals(S0, localised_state) == 0

# non unital localised state
@test @inferred diagonal_element(S0, non_unital_localised_state) ≈ 20/9
@test @inferred diagonal_element(S1, non_unital_localised_state) ≈ (-4/9)*exp(im * -2pi/3)

# non unital near uniform state
@test @inferred diagonal_element(S0, non_unital_uniform_state) ≈ 2/9

# constant density localised state
@test @inferred diagonal_element(S0, localised_state) == 5.
@test @inferred diagonal_element(S1, localised_state) ≈ 1
@test @inferred diagonal_element(S2, localised_state) ≈ -1

# constant density uniform state
@test @inferred diagonal_element(S0, uniform_state) == 0
@test @inferred diagonal_element(S2, uniform_state) == 0

# Test return type for integer, and non-integer filling
@test @inferred diagonal_element(S0, localised_state) isa Float64
@test @inferred diagonal_element(S1, non_unital_localised_state) isa ComplexF64

# Test show method
d = 5
output = @capture_out print(StringCorrelator(d))
@test output == "StringCorrelator($d)"

end

@testset "Momentum" begin
Expand Down