Skip to content

Commit

Permalink
Merge branch 'develop' into feature/geometry
Browse files Browse the repository at this point in the history
  • Loading branch information
mtsch committed May 6, 2024
2 parents 1ffa7f2 + 0b07115 commit 2c12a1d
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
version: ${{ matrix.julia-version }}
arch: ${{ matrix.julia-arch }}
- name: "Load cache"
uses: julia-actions/cache@v1
uses: julia-actions/cache@v2
- name: "Build"
uses: julia-actions/julia-buildpkg@v1
- name: "Run tests"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/allocations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
with:
version: ${{ matrix.julia-version }}
arch: ${{ matrix.julia-arch }}
- uses: julia-actions/cache@v1
- uses: julia-actions/cache@v2
- name: "Run test"
run: |
julia --project=@. -e "using Pkg; Pkg.instantiate(); Pkg.build()"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: julia-actions/setup-julia@v2
with:
version: 1
- uses: julia-actions/cache@v1
- uses: julia-actions/cache@v2
- uses: julia-actions/julia-buildpkg@v1
- name: Install dependencies
run: julia -e 'using Pkg; pkg"add PkgBenchmark BenchmarkTools BenchmarkCI@0.1"'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ jobs:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
with:
version: '1.7'
- uses: julia-actions/cache@v1
version: '1'
- uses: julia-actions/cache@v2
- name: Install dependencies
run: |
export JULIA_PROJECT=@.
Expand Down
1 change: 1 addition & 0 deletions docs/src/hamiltonians.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ Observables are [`AbstractHamiltonian`](@ref)s that represent a physical
observable. Their ground state expectation values can be sampled by passing
them into [`AllOverlaps`](@ref).
```@docs
ParticleNumberOperator
G2RealCorrelator
G2RealSpace
G2MomCorrelator
Expand Down
11 changes: 10 additions & 1 deletion src/Hamiltonians/HOCartesianContactInteractions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,16 @@ function four_oscillator_integral_general(i, j, k, l; max_level = typemax(Int))
p = sqrt(2 * gamma(i + 1) * gamma(j + 1) * gamma(k + 1) * gamma(l + 1)) * pi^2
q = gamma(a/2) * gamma(b/2) * gamma(c/2) * gamma(k + 1) / gamma(k - l + 1)

f = _₃F₂(float(-l), b/2, c/2, float(1 + k - l), d/2, 1.0)
f1 = _₃F₂(float(-l), b/2, c/2, float(1 + k - l), d/2, 1.0)

if isnan(f1)
# workaround for some issues with large arguments
fp = _₃F₂(float(-l), b/2, c/2, float(1 + k - l), d/2, 1.0 + eps())
fm = _₃F₂(float(-l), b/2, c/2, float(1 + k - l), d/2, 1.0 - eps())
f = (fp + fm)/2
else
f = f1
end

return f * q / p
end
Expand Down
3 changes: 3 additions & 0 deletions src/Hamiltonians/Hamiltonians.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Other
- [`Stoquastic`](@ref)
## [Observables](#Observables)
- [`ParticleNumberOperator`](@ref)
- [`G2MomCorrelator`](@ref)
- [`G2RealCorrelator`](@ref)
- [`DensityMatrixDiagonal`](@ref)
Expand Down Expand Up @@ -83,6 +84,7 @@ export Stoquastic
export Transcorrelated1D
export hubbard_dispersion, continuum_dispersion
export FroehlichPolaron
export ParticleNumberOperator

export G2MomCorrelator, G2RealCorrelator, G2RealSpace, SuperfluidCorrelator, DensityMatrixDiagonal, Momentum
export StringCorrelator
Expand Down Expand Up @@ -124,6 +126,7 @@ include("Transcorrelated1D.jl")
include("correlation_functions.jl")
include("DensityMatrixDiagonal.jl")
include("Momentum.jl")
include("particle_number.jl")

include("HOCartesianContactInteractions.jl")
include("HOCartesianEnergyConservedPerDim.jl")
Expand Down
1 change: 0 additions & 1 deletion src/Hamiltonians/Momentum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ Momentum(component=0; fold=true) = Momentum{component}(fold)
Base.show(io::IO, mom::Momentum{C}) where {C} = print(io, "Momentum($C; fold=$(mom.fold))")

LOStructure(::Type{<:Momentum}) = IsDiagonal()
num_offdiagonals(ham::Momentum, add) = 0

@inline function _momentum(add::SingleComponentFockAddress, fold)
M = num_modes(add)
Expand Down
36 changes: 36 additions & 0 deletions src/Hamiltonians/particle_number.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""
ParticleNumberOperator([address]) <: AbstractHamiltonian
The number operator in Fock space. This operator is diagonal in the Fock basis and
returns the number of particles in the Fock state. Passing an address is optional.
```jldoctest
julia> h = FroehlichPolaron(fs"|0 0⟩{}"; mode_cutoff=5, v=3); bsr = BasisSetRep(h);
julia> gs = DVec(zip(bsr.basis, eigen(Matrix(bsr)).vectors[:,1])); # ground state
julia> dot(gs, ParticleNumberOperator(), gs) # particle number expectation value
2.8823297252925917
```
See also [`AbstractHamiltonian`](@ref).
"""
struct ParticleNumberOperator{A} <: AbstractHamiltonian{Float64}
address::A
end
ParticleNumberOperator() = ParticleNumberOperator(BoseFS(1,))

function Base.show(io::IO, n::ParticleNumberOperator)
io = IOContext(io, :compact => true)
print(io, "ParticleNumberOperator(")
n.address === BoseFS(1,) || show(io, n.address) # suppress if default
print(io, ")")
end

LOStructure(::Type{<:ParticleNumberOperator}) = IsDiagonal()
starting_address(n::ParticleNumberOperator) = n.address

function diagonal_element(::ParticleNumberOperator, addr::AbstractFockAddress)
return float(num_particles(addr))
end
allowed_address_type(::ParticleNumberOperator) = AbstractFockAddress
6 changes: 6 additions & 0 deletions src/Interfaces/hamiltonians.jl
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,12 @@ LOStructure(op) = LOStructure(typeof(op))
LOStructure(::Type) = AdjointUnknown()
LOStructure(::AbstractMatrix) = AdjointKnown()

# diagonal matrices have zero offdiagonal elements
function num_offdiagonals(h::H, addr) where {H<:AbstractHamiltonian}
return num_offdiagonals(LOStructure(H), h, addr)
end
num_offdiagonals(::IsDiagonal, _, _) = 0

"""
has_adjoint(op)
Expand Down
4 changes: 3 additions & 1 deletion test/Hamiltonians.jl
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ end
HOCartesianCentralImpurity(BoseFS((1,0,0,0,0))),

FroehlichPolaron(OccupationNumberFS(1,1,1)),
FroehlichPolaron(OccupationNumberFS(1,1,1); momentum_cutoff = 10.0)
FroehlichPolaron(OccupationNumberFS(1,1,1); momentum_cutoff = 10.0),

ParticleNumberOperator(OccupationNumberFS(1, 1, 1))
)
test_hamiltonian_interface(H)
end
Expand Down

0 comments on commit 2c12a1d

Please sign in to comment.