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 21 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
128 changes: 128 additions & 0 deletions src/Hamiltonians/correlation_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,131 @@ function get_offdiagonal(
gd = exp(-im*g.d*Δp*2π/M)*gamma
return new_add, ComplexF64(gd/M)
end

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

Two-body operator for superfluid correlation between sites separated by `d` with `0 ≤ d < m`
rohan-kumar-uoa marked this conversation as resolved.
Show resolved Hide resolved

```math
\\hat{C}_{\\text{SF}}(d) = \\frac{1}{M} \\sum_{i}^{M} a_{i}^{\\dagger} a_{i + d}
```
Assumes a one-dimensional lattice with periodic boundary conditions.
rohan-kumar-uoa marked this conversation as resolved.
Show resolved Hide resolved

SuperfluidCorrelator must be wrapped in 'AllOverlaps'

# Arguments
- `d::Integer`: distance between sites.

# Implementation
Follow below for an example on how 'SuperfluidCorrelator' is used. Implementation is similar to that of 'G2RealCorrelator'
- [G2 Correlator Example](https://joachimbrand.github.io/Rimu.jl/previews/PR227/generated/G2-example.html)
rohan-kumar-uoa marked this conversation as resolved.
Show resolved Hide resolved


# See also

* [`HubbardReal1D`](@ref)
* [`G2RealCorrelator`](@ref)
* [`AbstractHamiltonian`](@ref)
* [`AllOverlaps`](@ref)

rohan-kumar-uoa marked this conversation as resolved.
Show resolved Hide resolved
"""
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}

Two-body operator for string correlation between sites separated by `d` with `0 ≤ d < m`

```math
\\hat{C}_{\\text{string}}(d) = \\frac{1}{M} \\sum_{i}^{M} \\delta n_j (e^{i \\pi \\sum_{j \\leq k < j + d} \\delta n_k}) \\delta n_{j+d}
rohan-kumar-uoa marked this conversation as resolved.
Show resolved Hide resolved
```
where ``\\delta \\hat{n}_j = \\hat{n}_j - \\bar{n}`` is the boson number deviation from the mean filling number.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a definition for the mean particle number, i.e. \\bar{n}=N/M, where ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been altered.


Assumes a one-dimensional lattice with periodic boundary conditions.
rohan-kumar-uoa marked this conversation as resolved.
Show resolved Hide resolved

# Arguments
- `d::Integer`: distance between sites.

# See also

* [`HubbardReal1D`](@ref)
* [`G2RealCorrelator`](@ref)
* [`SuperfluidCorrelator`](@ref)
* [`AbstractHamiltonian`](@ref)
* [`AllOverlaps`](@ref)

rohan-kumar-uoa marked this conversation as resolved.
Show resolved Hide resolved
"""
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
rohan-kumar-uoa marked this conversation as resolved.
Show resolved Hide resolved
for i in eachindex(v)
result += (v[i]- n̄)^2
rohan-kumar-uoa marked this conversation as resolved.
Show resolved Hide resolved
end

return result / M
end

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

result = 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks a bit untidy to initialise result with an Int64 and then add ComplexFloat64s to it. Will this result in a type instability?

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

if M == N
return real(result) /M
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be more efficient to avoid complex numbers altogether for integer filling factor. Probably the best way to do this is to branch at the beginning of the function on

if iszero(N % M) # %, remainder from integer division
    n̄ = N÷M # integer division
    ... # phase sum is always integer; replace exp(pi * im) by (-1)
else
    n̄ = N/M
   ... # complex algebra as you have now
end

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is worth checking whether this will produce type-stable code. It should.


return result / M
end

num_offdiagonals(::StringCorrelator, ::SingleComponentFockAddress) = 0
76 changes: 76 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,81 @@ 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 diagonal_element(SuperfluidCorrelator(0), add1) == n1/m
@test diagonal_element(SuperfluidCorrelator(1), add1) == 0.
rohan-kumar-uoa marked this conversation as resolved.
Show resolved Hide resolved

# 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
joachimbrand marked this conversation as resolved.
Show resolved Hide resolved
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)

rohan-kumar-uoa marked this conversation as resolved.
Show resolved Hide resolved
# non unital localised state
@test diagonal_element(S0, non_unital_localised_state) ≈ 20/9
@test diagonal_element(S1, non_unital_localised_state) ≈ (-4/9)*exp(im * -2pi/3)

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

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

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

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

end

@testset "Momentum" begin
Expand Down
Loading