Skip to content
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

Allow computing estimators directly on a PMCSimulation #257

Merged
merged 12 commits into from
Jul 4, 2024
12 changes: 6 additions & 6 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ julia> using Revise
Rimu offers a number of tools for representing Hamiltonians (see
[`Hamiltonians`](@ref)) and state vectors / wave functions
(see [`DictVectors`](@ref))
as well as algorithms to find the ground state, e.g. [`lomc!`](@ref).
as well as algorithms to find the ground state, e.g. [`ProjectorMonteCarloProblem`](@ref), [`ExactDiagonalizationProblem`](@ref).

## Scripts

Expand All @@ -99,7 +99,7 @@ distribute work by making use of MPI, or "message passing interface". For exampl
```
> julia scripts/BHM-example.jl
```
will run on one processor with the main `lomc!()` computation (i.e. after
will run on one processor with the main computation (i.e. after
package loading and compilation) completing in 2.69 seconds.

Running
Expand All @@ -110,10 +110,10 @@ on the same hardware makes use of 4 cores and the main part completes in 1.04
seconds, a speedup factor of 2.6. This seems reasonable, given that extra work
needs to be done for communicating between different processes.

Using MPI parallelism with `Rimu` is easy. Enabling MPI for use in [`lomc!()`](@ref) is
enabled automatically if [`PDVec`](@ref) is used to store a vector. In that case, data will
be stored in a distributed fashion among the MPI ranks and only communicated between ranks
when necessary. Additional MPI-related functionality is provided by the module [`RMPI`](@ref
Using MPI parallelism with `Rimu` is easy. Enabling MPI enabled automatically if
[`PDVec`](@ref) is used to store a vector. In that case, data will be stored in a
distributed fashion among the MPI ranks and only communicated between ranks when
necessary. Additional MPI-related functionality is provided by the module [`RMPI`](@ref
Rimu.RMPI).

## Compatibility
Expand Down
10 changes: 5 additions & 5 deletions docs/src/statstools.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ sample means is done with [`ratio_of_means`](@ref), where error propagation
of correlated uncertainties is done with the help of the package
[`MonteCarloMeasurements`](https://github.com/baggepinnen/MonteCarloMeasurements.jl).

Many convenience functions are implemented for directly analysing data
obtained from [`lomc!`](@ref) as a `DataFrame`. See, e.g.,
[`shift_estimator`](@ref) and [`projected_energy`](@ref). Asymptotically
unbiased estimators are implemented as [`mixed_estimator`](@ref),
[`growth_estimator`](@ref) and [`rayleigh_replica_estimator`](@ref).
Many convenience functions are implemented for directly analysing data obtained from
[`solve`](@ref CommonSolve.solve(::ProjectorMonteCarloProblem)) as a `DataFrame`. See, e.g.,
[`shift_estimator`](@ref) and [`projected_energy`](@ref). Asymptotically unbiased estimators
are implemented as [`mixed_estimator`](@ref), [`growth_estimator`](@ref) and
[`rayleigh_replica_estimator`](@ref).

## Exported
```@autodocs
Expand Down
2 changes: 1 addition & 1 deletion src/StatsTools/StatsTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Tools for the statistical analysis of Monte Carlo data.
"""
module StatsTools

using DataFrames: DataFrames, DataFrame
using DataFrames: DataFrames, DataFrame, metadata
using Distributions: Distributions, Chisq, Distribution, MvNormal, Normal,
cquantile, var
using LinearAlgebra: LinearAlgebra, diag, norm
Expand Down
15 changes: 8 additions & 7 deletions src/StatsTools/fidelity.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""
replica_fidelity(df::DataFrame; p_field = :hproj, skip = 0)
replica_fidelity(sim::PMCSimulation; kwargs...)

Compute the fidelity of the average coefficient vector and the projector defined in
`p_field` from the result of replica [`lomc!`](@ref Main.lomc!) passed as argument `df`,
using replicas `_1` and `_2`.
Calls [`ratio_of_means()`](@ref) to perform a blocking analysis
on a ratio of the means of separate time series and returns a
[`RatioBlockingResult`](@ref).
The first `skip` steps in the time series are skipped.
`p_field` from the [`PMCSimulation`](@ref Main.Rimu.PMCSimulation) or `DataFrame` returned
by solve, using replicas `_1` and `_2`. Calls [`ratio_of_means`](@ref) to perform a
blocking analysis on a ratio of the means of separate time series and returns a
[`RatioBlockingResult`](@ref). The first `skip` steps in the time series are skipped.

The fidelity of states `|ψ⟩` and `|ϕ⟩` is defined as
```math
Expand All @@ -22,7 +22,8 @@ where `v` is the projector specified by `p_field`, which is assumed to be normal
unity with the two-norm (i.e. `v⋅v == 1`), and ``\\mathbf{c}_1`` and ``\\mathbf{c}_2``
are two replica coefficient vectors.
"""
function replica_fidelity(df::DataFrame; p_field = :hproj, skip = 0, args...)
function replica_fidelity(sim; p_field = :hproj, skip = 0, args...)
df = DataFrame(sim)
p_field_1 = Symbol(p_field, :_1)
p_field_2 = Symbol(p_field, :_2)
fid_num = conj(getproperty(df, p_field_1)) .* getproperty(df, p_field_2)
Expand Down
24 changes: 14 additions & 10 deletions src/StatsTools/growth_witness.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# growth_witness()
# smoothen()

"""
growth_witness(shift::AbstractArray, norm::AbstractArray, dt, [b]; skip=0) -> g
growth_witness(df::DataFrame, [b]; skip=0) -> g
growth_witness(shift::AbstractArray, norm::AbstractArray, dt, [b]; skip=0)

Compute the growth witness
```math
G^{(n)} = S^{(n)} - \\frac{\\vert\\mathbf{c}^{(n+1)}\\vert -
Expand Down Expand Up @@ -36,14 +33,21 @@ function growth_witness(shift::AbstractArray, norm::AbstractArray, dt, b; kwargs
end
"""
growth_witness(df::DataFrame, [b]; shift=:shift, norm=:norm, dτ=df.dτ[end], skip=0)
Calculate the growth witness directly from a `DataFrame` returned by
[`lomc!`](@ref Main.lomc!). The keyword arguments `shift` and `norm`
can be used to change the names of the relevant columns.
growth_witness(sim::PMCSimulation, [b]; kwargs...)

Calculate the growth witness directly from the result (`DataFrame` or
[`PMCSimulation`](@ref Main.Rimu.PMCSimulation)) of
[`solve`](@ref CommonSolve.solve(::ProjectorMonteCarloProblem))ing a
[`ProjectorMonteCarloProblem`](@ref Main.ProjectorMonteCarloProblem). The keyword arguments
`shift` and `norm` can be used to change the names of the relevant columns.
"""
function growth_witness(
df::DataFrame, b=Val(0);
shift=:shift, norm=:norm, dτ=df.dτ[end], kwargs...
sim, b=Val(0);
shift=:shift, norm=:norm, dτ=nothing, kwargs...
)
df = DataFrame(sim)
dτ = determine_constant_time_step(df)

shift_vec = getproperty(df, Symbol(shift))
norm_vec = getproperty(df, Symbol(norm))
return growth_witness(shift_vec, norm_vec, dτ, b; kwargs...)
Expand Down
Loading
Loading