Skip to content

Commit

Permalink
Merge branch 'master' into hartreefock_2
Browse files Browse the repository at this point in the history
  • Loading branch information
pablosanjose authored Oct 10, 2024
2 parents 4e85219 + 5d2e6ee commit 03feb73
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
14 changes: 10 additions & 4 deletions src/apply.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ sanitize_cells(::Missing, ::Val{L}) where {L} = missing
sanitize_cells(f::Function, ::Val{L}) where {L} = f
sanitize_cells(cells, ::Val{L}) where {L} = sanitize_SVector.(SVector{L,Int}, cells)

applyrange(r::Neighbors, lat) = nrange(Int(r), lat)
applyrange(r::Real, lat) = r

padrange(r::Real, m) = isfinite(r) ? float(r) + m * sqrt(eps(float(r))) : float(r)

applied_region(r, ::Missing) = true
Expand Down Expand Up @@ -128,6 +125,15 @@ end

recursive_push!(v::Vector, f, cells) = recursive_push!(v, f)

applyrange(ss::Tuple, h::AbstractHamiltonian) = applyrange.(ss, Ref(h))
applyrange(s::Modifier, h::AbstractHamiltonian) = s
applyrange(s::AppliedHoppingModifier, h::ParametricHamiltonian) =
AppliedHoppingModifier(s, applyrange(selector(s), lattice(h)))
applyrange(s::HopSelector, lat::Lattice) = hopselector(s; range = sanitize_minmaxrange(hoprange(s), lat))

applyrange(r::Neighbors, lat::Lattice) = nrange(Int(r), lat)
applyrange(r::Real, lat::Lattice) = r

#endregion

############################################################################################
Expand Down Expand Up @@ -248,7 +254,7 @@ function push_pointers!(ptrs, h, har, s::AppliedHopSelector, shifts = missing, b
rrow = site(lat, row, dn)
r, dr = rdr(rcol => rrow)
r = apply_shift(shifts, r, col)
if (scol => srow, (r, dr), dn) in s
if (col => row, scol => srow, (r, dr), dn) in s
ncol = norbs[scol]
nrow = norbs[srow]
sprow, spcol = CellSitePos(dn, row, rrow, B), CellSitePos(dn0, col, rcol, B)
Expand Down
3 changes: 2 additions & 1 deletion src/builders.jl
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,9 @@ function IJVBuilder(lat::Lattice{T}, hams::AbstractHamiltonian...) where {T}
builder = IJVBuilderWithModifiers(lat, bs)
push_ijvharmonics!(builder, hams...)
mss = modifiers.(hams)
mss´ = applyrange.(mss, hams)
bis = blockindices(hams)
unapplied_block_modifiers = ((ms, bi) -> intrablock.(parent.(ms), Ref(bi))).(mss, bis)
unapplied_block_modifiers = ((ms, bi) -> intrablock.(parent.(ms), Ref(bi))).(mss´, bis)
push!(builder, tupleflatten(unapplied_block_modifiers...)...)
return builder
end
Expand Down
4 changes: 2 additions & 2 deletions src/selectors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ end
# return ((j, i), (r, dr), dcell) in sel
# end

function Base.in(((sj, si), (r, dr), dcell)::Tuple{Pair,Tuple,SVector}, sel::AppliedHopSelector)
return !isnull(sel) && (includeonsite(sel) || !isonsite(dr)) &&
function Base.in(((j, i), (sj, si), (r, dr), dcell)::Tuple{Pair, Pair,Tuple,SVector}, sel::AppliedHopSelector)
return !isnull(sel) && (includeonsite(sel) || !isonsite((j, i), dcell)) &&
indcells(dcell, sel) &&
insublats(sj => si, sel) &&
iswithinrange(dr, sel) &&
Expand Down
5 changes: 5 additions & 0 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ lattice(ap::AppliedHopSelector) = ap.lat
cells(ap::AppliedSiteSelector) = ap.cells
dcells(ap::AppliedHopSelector) = ap.dcells

hoprange(s::HopSelector) = s.range

includeonsite(ap::AppliedHopSelector) = ap.includeonsite

# if isempty(s.dcells) or isempty(s.sublats), none were specified, so we must accept any
Expand Down Expand Up @@ -787,6 +789,9 @@ AppliedOnsiteModifier(m::AppliedOnsiteModifier, ptrs) =
AppliedHoppingModifier(m::AppliedHoppingModifier, ptrs) =
AppliedHoppingModifier(m.parentselector, m.blocktype, m.f, ptrs, m.spatial)

AppliedHoppingModifier(m::AppliedHoppingModifier, sel::Selector) =
AppliedHoppingModifier(sel, m.blocktype, m.f, m.ptrs, m.spatial)

#endregion

#region ## API ##
Expand Down
5 changes: 3 additions & 2 deletions test/test_hamiltonian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -439,18 +439,19 @@ end
h = combine(hb, h0, ht; coupling = hopping((r,dr) -> exp(-norm(dr)), range = 2))
@test !iszero(h((0,0))[1:2, 5:6])
# Parametric combine
h1 = LP.linear(dim = 2) |> translate(SA[0,1]) |> hopping(1)
h1 = LP.linear(dim = 2) |> hopping(1)
h2 = LP.linear(dim = 2) |> hamiltonian(@hopping((; p = 1) -> p*I), orbitals = 2)
coupling = @hopping((; p = 1) -> im*p*SA[1 0], range = 3, sublats = :B => :A) |> plusadjoint
@test_throws ArgumentError combine(h1, h2) # non-unique names not allowed with parametric
@test_throws ArgumentError combine(h1, h2(); coupling)
@test combine(h1, h2()) isa Hamiltonian # non-unique names allowed with hamiltonian
h2 = LP.linear(dim = 2, names = :B) |> hamiltonian(@hopping((; p = 1) -> p*I), orbitals = 2)
@test combine(h1, h2) isa ParametricHamiltonian{Float64,2,1,Quantica.SMatrixView{2,2,ComplexF64,4}}
# this `combine` exercises #313, because lattice(h1) + lattice(h2) has smaller neighbor distance than lattice(h2)
h = combine(h1, h2; coupling)
@test h isa ParametricHamiltonian{Float64,2,1,Quantica.SMatrixView{2,2,ComplexF64,4}}
@test ishermitian(h((p = 10)))
@test h(0; p = 10) == SA[2 50im 0; -50im 20 0; 0 0 20]
@test h(0; p = 10) == SA[2 70im 0; -70im 20 0; 0 0 20]
# block filtering
l1 = LP.linear(dim = 2, names = :A) |> supercell(2) |> supercell
l2 = translate(lattice(l1, names = :B), SA[0,1])
Expand Down

0 comments on commit 03feb73

Please sign in to comment.