-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Excited states #269
Open
jamie-tay
wants to merge
10
commits into
develop
Choose a base branch
from
feature/excited-states
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Excited states #269
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4a44849
Added ability to calculate excited states with Gram-Schmidt orthogona…
jamie-tay 1a5734f
Apply suggestions from code review
jamie-tay 00ac6a0
Update documentation, add Base.show method for GramSchmidt
jamie-tay 49558e8
Merge branch 'develop' into feature/excited-states
jamie-tay 6ba310d
Add automatic generation of starting vectors
jamie-tay 6b98641
Add tests for excited states
jamie-tay a47a315
fix imports
jamie-tay 522a5fb
Update src/fciqmc.jl
jamie-tay f231362
Update documentation, fix imports
jamie-tay 522260a
Add minimum_size option for build_basis
jamie-tay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,42 +21,57 @@ mutable struct PMCSimulation | |
end | ||
|
||
function _set_up_starting_vectors( | ||
start_at, n_replicas, n_spectral, style, initiator, threading, copy_vectors | ||
ham, start_at, n_replicas, n_spectral, style, initiator, threading, copy_vectors | ||
) | ||
if start_at isa AbstractMatrix && size(start_at) == (n_replicas, n_spectral) | ||
if eltype(start_at) <: Union{AbstractDVec, RMPI.MPIData} # already dvecs | ||
if copy_vectors | ||
return SMatrix{n_spectral, n_replicas}(deepcopy(v) for v in start_at) | ||
return SMatrix{n_replicas, n_spectral}(deepcopy(v) for v in start_at) | ||
else | ||
return SMatrix{n_spectral, n_replicas}(v for v in start_at) | ||
return SMatrix{n_replicas, n_spectral}(v for v in start_at) | ||
end | ||
else | ||
return SMatrix{n_spectral, n_replicas}( | ||
return SMatrix{n_replicas, n_spectral}( | ||
default_starting_vector(sa; style, initiator, threading) for sa in start_at | ||
) | ||
end | ||
elseif n_spectral > 1 | ||
basis = build_basis(ham; minimum_size=n_spectral*5) | ||
basis = sort!(basis; by=x -> diagonal_element(ham, x)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we sorting the basis here? If we later do a full diagonalisation then there is no point, as the eigenvectors returned by |
||
trunc = BasisSetRepresentation(ham, basis; filter=Returns(false), sizelim=Inf) | ||
vecs = eigvecs(Matrix(trunc)) | ||
if threading | ||
eigs = [PDVec(zip(basis, 10*vecs[:,i]); style, initiator) for i in 1:n_spectral] | ||
else | ||
if initiator == NonInitiator() | ||
eigs = [DVec(zip(basis, 10*vecs[:,i]); style) for i in 1:n_spectral] | ||
else | ||
eigs = [InitiatorDVec(zip(basis,10*vecs[:,i]);style,initiator) for i in 1:n_spectral] | ||
end | ||
end | ||
mat = stack([eigs for _ in 1:n_replicas], dims=1) | ||
return SMatrix{n_replicas, n_spectral}(mat) | ||
end | ||
n_spectral == 1 || throw(ArgumentError("The number of spectral states must match the number of starting vectors.")) | ||
if start_at isa AbstractVector && length(start_at) == n_replicas | ||
if eltype(start_at) <: Union{AbstractDVec, RMPI.MPIData} # already dvecs | ||
if copy_vectors | ||
return SMatrix{n_spectral, n_replicas}(deepcopy(v) for v in start_at) | ||
return SMatrix{n_replicas, n_spectral}(deepcopy(v) for v in start_at) | ||
else | ||
return SMatrix{n_spectral, n_replicas}(v for v in start_at) | ||
return SMatrix{n_replicas, n_spectral}(v for v in start_at) | ||
end | ||
else | ||
return SMatrix{n_spectral, n_replicas}( | ||
return SMatrix{n_replicas, n_spectral}( | ||
default_starting_vector(sa; style, initiator, threading) for sa in start_at | ||
) | ||
end | ||
elseif start_at isa Union{AbstractDVec, RMPI.MPIData} | ||
if n_replicas == 1 && !copy_vectors | ||
return SMatrix{n_spectral, n_replicas}(start_at) | ||
return SMatrix{n_replicas, n_spectral}(start_at) | ||
else | ||
return SMatrix{n_spectral, n_replicas}(deepcopy(start_at) for _ in 1:n_replicas) | ||
return SMatrix{n_replicas, n_spectral}(deepcopy(start_at) for _ in 1:n_replicas) | ||
end | ||
end | ||
return SMatrix{n_spectral,n_replicas}( | ||
return SMatrix{n_replicas, n_spectral}( | ||
default_starting_vector(start_at; style, initiator, threading) for _ in 1:n_replicas | ||
) | ||
end | ||
|
@@ -80,10 +95,10 @@ function PMCSimulation(problem::ProjectorMonteCarloProblem; copy_vectors=true) | |
|
||
start_at = isnothing(start_at) ? starting_address(hamiltonian) : start_at | ||
vectors = _set_up_starting_vectors( | ||
start_at, n_replicas, n_spectral, style, initiator, | ||
hamiltonian, start_at, n_replicas, n_spectral, style, initiator, | ||
threading, copy_vectors | ||
) | ||
@assert vectors isa SMatrix{n_spectral,n_replicas} | ||
@assert vectors isa SMatrix{n_replicas, n_spectral} | ||
|
||
# set up initial_shift_parameters | ||
shift, time_step = nothing, nothing | ||
|
@@ -93,17 +108,17 @@ function PMCSimulation(problem::ProjectorMonteCarloProblem; copy_vectors=true) | |
@unpack shift, time_step = initial_shift_parameters | ||
set_up_initial_shift_parameters(algorithm, hamiltonian, vectors, shift, time_step) | ||
else | ||
SMatrix{n_spectral,n_replicas}(initial_shift_parameters...) | ||
SMatrix{n_replicas, n_spectral}(initial_shift_parameters...) | ||
end | ||
@assert shift_parameters isa SMatrix{n_spectral,n_replicas} | ||
@assert shift_parameters isa SMatrix{n_replicas, n_spectral} | ||
|
||
# set up the spectral_states | ||
wm = working_memory(vectors[1, 1]) | ||
spectral_states = ntuple(n_replicas) do i | ||
SpectralState( | ||
ntuple(n_spectral) do j | ||
v = vectors[j, i] | ||
sp = shift_parameters[j, i] | ||
v = vectors[i, j] | ||
sp = shift_parameters[i, j] | ||
id = if n_replicas * n_spectral == 1 | ||
"" | ||
elseif n_spectral == 1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using Rimu | ||
using Test | ||
|
||
|
||
@testset "excited state energies" begin | ||
ham = HubbardReal1D(BoseFS(1,1,1,1,1)) | ||
pr = ExactDiagonalizationProblem(ham) | ||
vals = solve(pr).values | ||
|
||
spectral_strategy = GramSchmidt(3) | ||
last_step=2000 | ||
style = IsDeterministic() | ||
p = ProjectorMonteCarloProblem(ham; spectral_strategy, last_step, style) | ||
s = solve(p) | ||
df = DataFrame(s) | ||
energy1 = shift_estimator(df, shift="shift_s1_1", skip=1000) | ||
energy2 = shift_estimator(df, shift="shift_s2_1", skip=1000) | ||
energy3 = shift_estimator(df, shift="shift_s3_1", skip=1000) | ||
|
||
@test energy1.mean ≈ vals[1] | ||
@test energy2.mean ≈ vals[2] | ||
@test energy3.mean ≈ vals[3] | ||
|
||
n_replicas = 2 | ||
p = ProjectorMonteCarloProblem(ham; spectral_strategy, last_step, style, n_replicas) | ||
s = solve(p) | ||
df = DataFrame(s) | ||
energy1 = shift_estimator(df, shift="shift_s1_1", skip=1000) | ||
energy2 = shift_estimator(df, shift="shift_s2_1", skip=1000) | ||
energy3 = shift_estimator(df, shift="shift_s3_1", skip=1000) | ||
energy4 = shift_estimator(df, shift="shift_s1_2", skip=1000) | ||
energy5 = shift_estimator(df, shift="shift_s2_2", skip=1000) | ||
energy6 = shift_estimator(df, shift="shift_s3_2", skip=1000) | ||
|
||
@test energy1.mean ≈ vals[1] | ||
@test energy2.mean ≈ vals[2] | ||
@test energy3.mean ≈ vals[3] | ||
@test energy4.mean ≈ vals[1] | ||
@test energy5.mean ≈ vals[2] | ||
@test energy6.mean ≈ vals[3] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I'm not sure whether the factor 5 is reasonable here. It seems a large. The larger this matrix, the better the starting vectors will be, but as soon as these numbers become larger, then
eigvecs
can consume a lot of resources. Maybe 2 is more reasonable?We could also think about allowing the user to set the
minimum_size
by making it a keyword argument inProjectorMonteCarloProblem
that is passed through. What do you think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another comment I have here is that the current code ignores the value of
start_at
in this branch. There might be value in allowing to pass anallowed_address_type
, which can then be passed as a second argument intobuild_basis
.