-
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
AllOverlaps for Excited States #302
base: develop
Are you sure you want to change the base?
Changes from all commits
e9a1f67
9f3f154
5fafde0
032ff6d
00cf8ff
9bef231
1874997
793f485
96e7406
4bac2e1
33512a1
0c0ae1f
9712ee9
9d8671b
938c5c1
b432eca
d65106d
667fff0
2d9bff2
51527f0
c6bd84b
5811336
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,13 +1,14 @@ | ||||||||||
""" | ||||||||||
variational_energy_estimator(shifts, overlaps; kwargs...) | ||||||||||
variational_energy_estimator(df::DataFrame; max_replicas=:all, kwargs...) | ||||||||||
variational_energy_estimator(df::DataFrame; max_replicas=:all, spectral_state=1, kwargs...) | ||||||||||
variational_energy_estimator(sim::PMCSimulation; kwargs...) | ||||||||||
-> r::RatioBlockingResult | ||||||||||
|
||||||||||
Compute the variational energy estimator from the replica time series of the `shifts` and | ||||||||||
coefficient vector `overlaps` by blocking analysis. | ||||||||||
The keyword argument `max_replicas` can be used to constrain the number of replicas | ||||||||||
processed to be smaller than all available in `df`. | ||||||||||
The keyword argument `spectral_state` determines which spectral state's energy is computed. | ||||||||||
Other keyword arguments are passed on to [`ratio_of_means()`](@ref). | ||||||||||
Returns a [`RatioBlockingResult`](@ref). | ||||||||||
|
||||||||||
|
@@ -50,31 +51,31 @@ function variational_energy_estimator(shifts, overlaps; kwargs...) | |||||||||
return ratio_of_means(numerator, denominator; kwargs...) | ||||||||||
end | ||||||||||
|
||||||||||
function variational_energy_estimator(sim; max_replicas=:all, kwargs...) | ||||||||||
function variational_energy_estimator(sim; max_replicas=:all, spectral_state=1, kwargs...) | ||||||||||
df = DataFrame(sim) | ||||||||||
num_replicas = length(filter(startswith("norm_"), names(df))) # number of replicas | ||||||||||
if iszero(num_replicas) | ||||||||||
num_replicas = parse(Int, metadata(df, "num_replicas")) | ||||||||||
if num_replicas == 1 | ||||||||||
throw(ArgumentError( | ||||||||||
"No replicas found. Use keyword \ | ||||||||||
`replica_strategy=AllOverlaps(n)` with n≥2 in `ProjectorMonteCarloProblem` to set up replicas!" | ||||||||||
)) | ||||||||||
end | ||||||||||
@assert num_replicas ≥ 2 "At least two replicas are needed, found $num_replicas" | ||||||||||
|
||||||||||
num_overlaps = length(filter(startswith(r"c._dot"), names(df))) | ||||||||||
num_overlaps = length(filter(startswith(Regex("r[0-9]+s$(spectral_state)_dot_r[0-9]+s$(spectral_state)")), names(df))) | ||||||||||
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. Does
Suggested change
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. I think it has to be done with 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. Matija probably meant this way of writing it:
Suggested change
I'm not sure whether this would make it more readable (if it works, I haven't tried it), so happy to leave it as it is. 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. Actually, I think I'd prefer to store the number of overlaps in the DataFrame and retrieve it with a function 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. Oh, I misread that! I think it needs to be done this way if you want to do string interpolation, so it's all good! |
||||||||||
@assert num_overlaps == binomial(num_replicas, 2) "Unexpected number of overlaps." | ||||||||||
|
||||||||||
# process at most `max_replicas` but at least 2 replicas | ||||||||||
if max_replicas isa Integer | ||||||||||
num_replicas = max(2, min(max_replicas, num_replicas)) | ||||||||||
end | ||||||||||
|
||||||||||
shiftnames = [Symbol("shift_$i") for i in 1:num_replicas] | ||||||||||
shiftnames = [Symbol("shift_r$(i)s$(spectral_state)") for i in 1:num_replicas] | ||||||||||
shifts = map(name -> getproperty(df, name), shiftnames) | ||||||||||
@assert length(shifts) == num_replicas | ||||||||||
|
||||||||||
overlap_names = [ | ||||||||||
Symbol("c$(i)_dot_c$(j)") for i in 1:num_replicas for j in i+1:num_replicas | ||||||||||
Symbol("r$(i)s$(spectral_state)_dot_r$(j)s$(spectral_state)") for i in 1:num_replicas for j in i+1:num_replicas | ||||||||||
] | ||||||||||
overlaps = map(name -> getproperty(df, name), overlap_names) | ||||||||||
@assert length(overlaps) ≤ num_overlaps | ||||||||||
|
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.
Maybe we should instead have a method for
num_replicas(::DataFrame)
, e.g. defined inpmc_simulation.jl
that could be called here.The method could fall back to the old definition (filtering
names(df)
) for older DataFrames but throw an informative error if the DataFrame was not created by Rimu.jl? We will need that function more often.