• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

joachimbrand / Rimu.jl / 11565770445

29 Oct 2024 01:46AM UTC coverage: 94.31% (-0.5%) from 94.852%
11565770445

push

github

web-flow
Feature/ExtendedHubbardMom1D (#286)

* Create ExtendedHubbardMom1D.jl

- New model (i.e. ``ExtendedHubbardMom1D`` is added to Rimu

* Update excitations.jl

- ``extended_momentum_transfer_diagonal`` is added for the nearest neighbour term in ``ExtendedHubbardMom1D``

* Update Hamiltonians.jl

- ``ExtendedHubbardMom1D`` is added to all the necessary test sets.

* Update Hamiltonians.jl

* Update hamiltonians.md

* Update Hamiltonians.jl

* Update src/Hamiltonians/ExtendedHubbardMom1D.jl

Co-authored-by: Joachim Brand <joachim.brand@gmail.com>

* Update src/Hamiltonians/ExtendedHubbardMom1D.jl

Co-authored-by: Joachim Brand <joachim.brand@gmail.com>

* Update src/Hamiltonians/excitations.jl

Co-authored-by: Joachim Brand <joachim.brand@gmail.com>

* Update src/Hamiltonians/ExtendedHubbardMom1D.jl

Co-authored-by: Joachim Brand <joachim.brand@gmail.com>

* Update HubbardMom1D.jl

* Update HubbardMom1D.jl

* Update HubbardMom1D.jl

* Update HubbardMom1D.jl

* Update HubbardMom1D.jl

* Update excitations.jl

* Update ExtendedHubbardMom1D.jl

* Update HubbardMom1D.jl

* Update Hamiltonians.jl

* Update Hamiltonians.jl

* Update HubbardMom1D.jl

* Update Hamiltonians.jl

* Update excitations.jl

* Update ExtendedHubbardMom1D.jl

* Update ExtendedHubbardMom1D.jl

* docstring fix for HubbardMom1DEP

* Update HubbardMom1DEP.jl

* Update excitations.jl

* Update ExtendedHubbardMom1D.jl

* Update ExtendedHubbardMom1D.jl

* Update HubbardMom1D.jl

* Update ExtendedHubbardMom1D.jl

* Update Hamiltonians.jl

- Added test for comparison between energies of ``ExtendedHubbardMom1D`` and ``ExtendedHubbardReal1D``

* Update src/Hamiltonians/ExtendedHubbardMom1D.jl

Co-authored-by: mtsch <matijacufar@gmail.com>

* Update src/Hamiltonians/ExtendedHubbardMom1D.jl

Co-authored-by: mtsch <matijacufar@gmail.com>

* Update Hamiltonians.jl

* Update Hamiltonians.jl

* Update Hamiltonian... (continued)

66 of 73 new or added lines in 3 files covered. (90.41%)

40 existing lines in 18 files now uncovered.

6978 of 7399 relevant lines covered (94.31%)

13438492.29 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.55
/src/BitStringAddresses/multicomponent.jl
1
"""
2
    BoseFS2C{NA,NB,M,AA,AB} <: AbstractFockAddress
3
    BoseFS2C(onr_a, onr_b)
4

5
Address type that constructed with two [`BoseFS{N,M,S}`](@ref). It represents a
6
Fock state with two components, e.g. two different species of bosons with particle
7
number `NA` from species S and particle number `NB` from species B. The number of
8
modes `M` is expected to be the same for both components.
9
"""
10
struct BoseFS2C{NA,NB,M,SA,SB,N} <: AbstractFockAddress{N,M}
11
    bsa::BoseFS{NA,M,SA}
2,263,071✔
12
    bsb::BoseFS{NB,M,SB}
13

14
end
15

16
function BoseFS2C(bsa::BoseFS{NA,M,SA}, bsb::BoseFS{NB,M,SB}) where {NA,NB,M,SA,SB}
2,648✔
17
    N = NA + NB
2,648✔
18
    return BoseFS2C{NA,NB,M,SA,SB,N}(bsa, bsb)
2,648✔
19
end
20
BoseFS2C(onr_a::Tuple, onr_b::Tuple) = BoseFS2C(BoseFS(onr_a),BoseFS(onr_b))
2,461✔
21

22
function print_address(io::IO, b::BoseFS2C; compact)
90✔
23
    if compact
45✔
24
        print_address(io, b.bsa; compact)
14✔
25
        print(io, " ⊗ ")
14✔
26
        print_address(io, b.bsb; compact)
14✔
27
    else
28
        print(io, "BoseFS2C(", b.bsa, ", ", b.bsb, ")")
31✔
29
    end
30
end
31

UNCOV
32
num_components(::Type{<:BoseFS2C}) = 2
×
33
Base.isless(a::T, b::T) where {T<:BoseFS2C} = isless((a.bsa, a.bsb), (b.bsa, b.bsb))
581✔
34
onr(b2::BoseFS2C) = (onr(b2.bsa), onr(b2.bsb))
5✔
35

36

37
function near_uniform(::Type{<:BoseFS2C{NA,NB,M}}) where {NA,NB,M}
2✔
38
    return BoseFS2C(near_uniform(BoseFS{NA,M}), near_uniform(BoseFS{NB,M}))
2✔
39
end
40

41
function time_reverse(c::BoseFS2C{NA,NA,M,S,S,N}) where {NA,M,S,N}
416✔
42
    return  BoseFS2C{NA,NA,M,S,S,N}(c.bsb, c.bsa)
416✔
43
end
44

45
"""
46
    CompositeFS(addresses::SingleComponentFockAddress...) <: AbstractFockAddress
47

48
Used to encode addresses for multi-component models. All component addresses
49
are expected have the same number of modes.
50

51
See also: [`BoseFS`](@ref), [`FermiFS`](@ref), [`SingleComponentFockAddress`](@ref),
52
[`num_modes`](@ref), [`FermiFS2C`](@ref), [`AbstractFockAddress`](@ref).
53
"""
54
struct CompositeFS{C,N,M,T} <: AbstractFockAddress{N,M}
55
    components::T
56
    # C: components, N: total particles, M: modes in each component, T: tuple type with constituent address types
57
    function CompositeFS{C,N,M,T}(adds::T) where {C,N,M,T}
10,190,014✔
58
        return new{C,N,M,T}(adds)
10,190,014✔
59
    end
60
    function CompositeFS{C,N,M,T}(adds...) where {C,N,M,T}
6,267,382✔
61
        return new{C,N,M,T}(adds)
6,267,388✔
62
    end
63
end
64

65
# Slow constructor - not to be used internallly
66
function CompositeFS(adds::Vararg{SingleComponentFockAddress})
588,273✔
67
    N = sum(num_particles, adds)
588,273✔
68
    M1, M2 = extrema(num_modes, adds)
588,277✔
69
    if M1 ≠ M2
588,279✔
70
        throw(ArgumentError("all addresses must have the same number of modes"))
1✔
71
    end
72
    return CompositeFS{length(adds),N,M1,typeof(adds)}(adds)
588,278✔
73
end
74

75
num_components(::Type{<:CompositeFS{C}}) where {C} = C
65,400✔
76
Base.hash(c::CompositeFS, u::UInt) = hash(c.components, u)
101,178,298✔
77

78
function print_address(io::IO, c::CompositeFS{C}; compact=false) where {C}
20✔
79
    if compact
10✔
80
        for add in c.components[1:end-1]
3✔
81
            print_address(io, add; compact)
5✔
82
            print(io, " ⊗ ")
4✔
83
        end
5✔
84
        print_address(io, c.components[end]; compact)
3✔
85
    else
86
        println(io, "CompositeFS(")
7✔
87
        for add in c.components
7✔
88
            println(io, "  ", add, ",")
23✔
89
        end
22✔
90
        print(io, ")")
7✔
91
    end
92
end
93

94
function Base.reverse(c::CompositeFS)
724✔
95
    typeof(c)(map(reverse, c.components))
724✔
96
end
97

98
"""
99
    time_reverse(addr)
100
Apply the time-reversal operation on a two-component Fock address that flips all the spins.
101

102
Requires each component address to have the same type.
103
"""
104
function time_reverse(c::CompositeFS{2,N,M,T}) where {N, M, T <: NTuple{2}}
210✔
105
    return CompositeFS{2,N,M,T}(reverse(c.components))
210✔
106
end
107

108
"""
109
    update_component(c::CompositeFS, new, ::Val{i})
110

111
Replace the `i`-th component in `c` with `new`. Used for updating a single component in the
112
address.
113
"""
114
function update_component(c::CompositeFS, new, ::Val{I}) where {I}
9,600,800✔
115
    return typeof(c)(_update_component(c.components, new, Val(I)))
9,600,800✔
116
end
117

118
@inline _update_component((a, as...), new, ::Val{1}) = (new, as...)
9,600,800✔
119
@inline function _update_component((a, as...), new, ::Val{I}) where {I}
3,983,024✔
120
    return (a, _update_component(as, new, Val(I - 1))...)
3,983,024✔
121
end
122

123
Base.isless(a::T, b::T) where {T<:CompositeFS} = isless(a.components, b.components)
1,253✔
124

125
function onr(a::CompositeFS)
17✔
126
    map(onr, a.components)
17✔
127
end
128

129
# Convenience
130
"""
131
    FermiFS2C <: AbstractFockAddress
132
    FermiFS2C(onr_a, onr_b)
133

134
Fock state address with two fermionic (spin) components. Alias for [`CompositeFS`](@ref)
135
with two [`FermiFS`](@ref) components. Construct by specifying either two compatible
136
[`FermiFS`](@ref)s, two [`onr`](@ref)s, or the number of modes followed by `mode =>
137
occupation_number` pairs, where `occupation_number=1` will put a particle in the first
138
component and `occupation_number=-1` will put a particle in the second component.
139
See examples below.
140

141
# Examples
142

143
```jldoctest
144
julia> FermiFS2C(FermiFS(1,0,0), FermiFS(0,1,1))
145
CompositeFS(
146
  FermiFS{1,3}(1, 0, 0),
147
  FermiFS{2,3}(0, 1, 1),
148
)
149

150
julia> FermiFS2C((1,0,0), (0,1,1))
151
CompositeFS(
152
  FermiFS{1,3}(1, 0, 0),
153
  FermiFS{2,3}(0, 1, 1),
154
)
155

156
julia> FermiFS2C(3, 1 => 1, 2 => -1, 3 => -1)
157
CompositeFS(
158
  FermiFS{1,3}(1, 0, 0),
159
  FermiFS{2,3}(0, 1, 1),
160
)
161

162
julia> fs"|↑↓↓⟩"
163
CompositeFS(
164
  FermiFS{1,3}(1, 0, 0),
165
  FermiFS{2,3}(0, 1, 1),
166
)
167
```
168
"""
169
const FermiFS2C{N1,N2,M,N,F1,F2} =
170
    CompositeFS{2,N,M,Tuple{F1,F2}} where {F1<:FermiFS{N1,M},F2<:FermiFS{N2,M}}
171

172
FermiFS2C(f1::FermiFS{<:Any,M}, f2::FermiFS{<:Any,M}) where {M} = CompositeFS(f1, f2)
21✔
173
FermiFS2C(onr_a, onr_b) = FermiFS2C(FermiFS(onr_a), FermiFS(onr_b))
16✔
174
FermiFS2C(M::Integer, pairs::Pair...) = FermiFS2C(M, pairs)
3✔
175
function FermiFS2C(M::Integer, pairs)
3✔
176
    up_pairs = filter(p -> p[2] > 0, pairs)
9✔
177
    down_pairs = map(p -> p[1] => -p[2], filter(p -> p[2] < 0, pairs))
13✔
178
    return FermiFS2C(FermiFS(M, up_pairs), FermiFS(M, down_pairs))
3✔
179
end
180

181
function print_address(io::IO, f::FermiFS2C; compact=false)
26✔
182
    if compact
13✔
183
        o1, o2 = onr(f)
8✔
184
        str = join(
41✔
185
            [i && j ? '⇅' : i ? '↑' : j ? '↓' : '⋅' for (i, j) in zip(Bool.(o1), Bool.(o2))]
186
        )
187
        print(io, "|", str, "⟩")
8✔
188
    else
189
        # Show as normal CompositeFS
190
        invoke(print_address, Tuple{typeof(io),CompositeFS}, io, f)
5✔
191
    end
192
end
193

194
BoseFS2C(fs::CompositeFS{2}) = BoseFS2C(fs.components...)
2✔
195
CompositeFS(fs::BoseFS2C) = CompositeFS(fs.bsa, fs.bsb)
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc