Skip to content

Commit

Permalink
Fast basis (#287)
Browse files Browse the repository at this point in the history
# New features

* `build_basis` and `build_sparse_matrix_from_LO` are now parallel.
* `build_basis` and `build_sparse_matrix_from_LO` now support an
argument `max_depth` which limits the number of steps of the breadth
first search to perform.
* New method `build_basis(::AbstractFockAddress)` which is much faster.

# Bugfixes

* `OccupationNumberFS` now has the same ordering as `BoseFS`.
* Fix a bug where `MatrixHamiltonian` would not work with sparse
matrices that have implicit zeros on the diagonal.
  • Loading branch information
mtsch authored Dec 6, 2024
1 parent 07a0393 commit 3a99de5
Show file tree
Hide file tree
Showing 10 changed files with 703 additions and 197 deletions.
9 changes: 8 additions & 1 deletion src/BitStringAddresses/occupationnumberfs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,14 @@ end
Base.reverse(ofs::OccupationNumberFS) = OccupationNumberFS(reverse(ofs.onr))

onr(ofs::OccupationNumberFS) = ofs.onr
Base.isless(a::OccupationNumberFS, b::OccupationNumberFS) = isless(b.onr, a.onr)
function Base.isless(a::OccupationNumberFS{M}, b::OccupationNumberFS{M}) where {M}
# equivalent to `isless(reverse(a.onr), reverse(b.onr))`
i = length(a.onr)
while i > 1 && a.onr[i] == b.onr[i]
i -= 1
end
return isless(a.onr[i], b.onr[i])
end
# reversing the order here to make it consistent with BoseFS
Base.:(==)(a::OccupationNumberFS, b::OccupationNumberFS) = a.onr == b.onr
Base.hash(ofs::OccupationNumberFS, h::UInt) = hash(ofs.onr, h)
Expand Down
8 changes: 6 additions & 2 deletions src/ExactDiagonalization/ExactDiagonalization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ using CommonSolve: CommonSolve, solve, init
using VectorInterface: VectorInterface, add
using OrderedCollections: freeze
using NamedTupleTools: delete
using StaticArrays: setindex

using Rimu: Rimu, DictVectors, Hamiltonians, Interfaces, BitStringAddresses, replace_keys,
clean_and_warn_if_others_present
using ..Interfaces: AbstractDVec, AbstractHamiltonian, AdjointUnknown,
diagonal_element, offdiagonals, starting_address, LOStructure, IsHermitian
using ..BitStringAddresses: AbstractFockAddress
using ..BitStringAddresses: AbstractFockAddress, BoseFS, FermiFS, CompositeFS, near_uniform
using ..DictVectors: FrozenDVec, PDVec, DVec
using ..Hamiltonians: check_address_type, dimension, ParitySymmetry, TimeReversalSymmetry
using ..Hamiltonians: allows_address_type, check_address_type, dimension,
ParitySymmetry, TimeReversalSymmetry


export ExactDiagonalizationProblem, KrylovKitSolver, LinearAlgebraSolver
Expand All @@ -42,6 +44,8 @@ export BasisSetRepresentation, build_basis
export sparse # from SparseArrays


include("basis_breadth_first_search.jl")
include("basis_fock.jl")
include("basis_set_representation.jl")
include("algorithms.jl")
include("exact_diagonalization_problem.jl")
Expand Down
Loading

0 comments on commit 3a99de5

Please sign in to comment.