Skip to content

Commit 7e1cdeb

Browse files
committed
Unified ModeMap Type (#330)
1. Resolve unoccupied_modes method test failed when FermiFS is constructed with SortedParticleList
1 parent a3604f8 commit 7e1cdeb

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

src/BitStringAddresses/fermifs.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@ num_occupied_modes(::FermiFS{N}) where {N} = N
132132
occupied_modes(a::FermiFS{N,<:Any,S}) where {N,S} = FermiOccupiedModes{N,S}(a.bs)
133133

134134
num_unoccupied_modes(::FermiFS{N,M}) where {N,M} = M - N
135-
unoccupied_modes(a::FermiFS{N,M,S}) where {N,M,S} = FermiUnoccupiedModes{M - N,S}(~a.bs)
135+
function unoccupied_modes(a::FermiFS{N,M,S}) where {N,M,S}
136+
s = ~a.bs
137+
FermiUnoccupiedModes{M - N,typeof(s)}(s)
138+
end
136139

137140
"""
138141
unoccupied_mode_map(addr::FermiFS) <: AbstractVector

src/BitStringAddresses/fockaddress.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ Base.eltype(::FermiOccupiedModes) = FermiFSIndex
694694
"""
695695
FermiUnoccupiedModes{N,S<:BitString}
696696
697-
Iterator over unoccupied modes in address. `N` is the number of fermions. See [`unoccupied_modes`](@ref).
697+
Iterator over unoccupied modes in address. `N` is the number of unoccupied orbitals. See [`unoccupied_modes`](@ref).
698698
"""
699699
struct FermiUnoccupiedModes{N,S} <: ModeIterator
700700
storage::S

src/BitStringAddresses/sortedparticlelist.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,3 +277,23 @@ function Base.iterate(fom::FermiOccupiedModes{<:Any,<:SortedParticleList}, i=1)
277277
return FermiFSIndex(res...), i
278278
end
279279
end
280+
281+
import Base.:~
282+
function ~(ss::SortedParticleList{N,M,T}) where {N,M,T}
283+
ss
284+
end
285+
Base.length(::FermiUnoccupiedModes{N,<:SortedParticleList}) where {N} = N
286+
function Base.iterate(fum::FermiUnoccupiedModes{<:Any,<:SortedParticleList{N,M}}, state=(1, 1)) where {N,M}
287+
if isnothing(state)
288+
return nothing
289+
else
290+
i, j = state
291+
while i fum.storage.storage
292+
i += 1
293+
end
294+
if i > M
295+
return nothing
296+
end
297+
return FermiFSIndex(0, i, i - 1), (i + 1, j + 1)
298+
end
299+
end

0 commit comments

Comments
 (0)