Skip to content

Commit 26e1255

Browse files
joachimbrandmtschchristofbradly
authored
Breaking changes before v1.0 release (#268)
* rename df.steps to df.step * rename :dτ to :time_step in report/DataFrame * rename update_dτ to update_time_step * rename :targetwalkers to :target_walkers * update G2-example.jl * fix benchmarks * skip reporting time step if constant * fix skip reporting time step * doc page on Projector Monte Carlo * removing lomc! references from docstrings * Apply suggestions from code review Co-authored-by: mtsch <matijacufar@gmail.com> * Apply suggestions from code review Co-authored-by: christofbradly <christof.bradly@gmail.com> * deprecate instead of remove `targetwalkers` --------- Co-authored-by: Joachim Brand <joachim.brand@gmail.com> Co-authored-by: mtsch <matijacufar@gmail.com> Co-authored-by: christofbradly <christof.bradly@gmail.com>
1 parent 8be042d commit 26e1255

32 files changed

+337
-233
lines changed

benchmark/benchmarks.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const SUITE = @benchmarkset "Rimu" begin
5858
ham = HubbardMom1D(addr, u=1.0)
5959
dv = PDVec(addr => 1.0; style=IsDynamicSemistochastic(), initiator=true)
6060
post_step = ProjectedEnergy(ham, dv)
61-
s_strat = DoubleLogUpdate(targetwalkers=40_000)
61+
s_strat = DoubleLogUpdate(target_walkers=40_000)
6262

6363
lomc!(ham, dv; s_strat, post_step, dτ=1e-4, laststep=8000)
6464
end seconds=150
@@ -67,7 +67,7 @@ const SUITE = @benchmarkset "Rimu" begin
6767
addr = BoseFS2C(ntuple(i -> ifelse(i == 5, 4, 0), 11), ntuple(==(5), 11))
6868
ham = BoseHubbardMom1D2C(addr, v=0.1)
6969
dv = PDVec(addr => 1.0f0; style=IsDynamicSemistochastic{Float32}())
70-
s_strat = DoubleLogUpdate(targetwalkers=10_000)
70+
s_strat = DoubleLogUpdate(target_walkers=10_000)
7171
replica_strategy = AllOverlaps(2; operator = ntuple(i -> G2Correlator(i - 1), 7))
7272

7373
lomc!(ham, dv; s_strat, replica_strategy, laststep=2000)
@@ -77,7 +77,7 @@ const SUITE = @benchmarkset "Rimu" begin
7777
addr = near_uniform(BoseFS{50,50})
7878
ham = HubbardReal1D(addr, u=6.0)
7979
dv = PDVec(addr => 1.0; style=IsDynamicSemistochastic())
80-
s_strat = DoubleLogUpdate(targetwalkers=50_000)
80+
s_strat = DoubleLogUpdate(target_walkers=50_000)
8181

8282
lomc!(ham, dv; s_strat, dτ=1e-4, laststep=1000)
8383
end seconds=150

docs/make.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ makedocs(;
5454
"Examples" => EXAMPLES_PAIRS[sortperm(EXAMPLES_NUMS)],
5555
"User documentation" => [
5656
"Exact Diagonalization" => "exactdiagonalization.md",
57+
"Projector Monte Carlo" => "projectormontecarlo.md",
5758
"StatsTools" => "statstools.md",
5859
"Using MPI" => "mpi.md",
5960
],

docs/src/projectormontecarlo.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Projector Monte Carlo / FCIQMC
2+
3+
The purpose of Projector Monte Carlo is to stochastically sample the ground state, i.e. the
4+
eigenvector corresponding to the lowest eigenvalue of a quantum Hamiltonian, or more generally,
5+
a very large matrix. Rimu implements a flavor of Projector Monte Carlo called
6+
Full Configuration Interaction Quantum Monte Carlo (FCIQMC).
7+
8+
## `ProjectorMonteCarloProblem`
9+
10+
To run a projector Monte Carlo simulation you set up a problem with `ProjectorMonteCarloProblem`
11+
and solve it with `solve`. Alternatively you can initialize a `PMCSimulation` struct, `step!`
12+
through time steps, and `solve!` it to completion.
13+
14+
```@docs; canonical=false
15+
ProjectorMonteCarloProblem
16+
init
17+
solve
18+
solve!
19+
step!
20+
```
21+
22+
After `solve` or `solve!` have been called the returned `PMCSimulation` contains the results of
23+
the projector Monte Carlo calculation.
24+
25+
### `PMCSimulation` and report as a `DataFrame`
26+
27+
```@docs; canonical=false
28+
Rimu.PMCSimulation
29+
```
30+
31+
The `DataFrame` returned from `DataFrame(::PMCSimulation)` contains the time series data from
32+
the projector Monte Carlo simulation that is of primary interest for analysis. Depending on the
33+
`reporting_strategy` and other options passed as keyword arguments to
34+
`ProjectorMonteCarloProblem` it can have different numbers of rows and columns. The rows
35+
correspond to the reported time steps (Monte Carlo steps). There is at least one column with the name `:step`. Further columns are usually present with additional data reported from the simulation.
36+
37+
For the default option `algorithm = FCIQMC(; shift_strategy, time_step_strategy)` with a single
38+
replica (`n_replicas = 1`) and single spectral state, the fields `:shift`, `:norm`, `:len` will
39+
be present as well as others depending on the `style` argument and the `post_step_strategy`.
40+
41+
If multiple replicas or spectral states are requested, then the relevant field names in the
42+
`DataFrame` will have a suffix identifying the respective replica simulation, e.g. the `shift`s will be reported as `shift_1`, `shift_2`, ...
43+
44+
Many tools for analysing the time series data obtained from a
45+
[`ProjectorMonteCarloProblem`](@ref) are contained in the [Module `StatsTools`](@ref).

scripts/BHM-example-mpi.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ problem = ProjectorMonteCarloProblem(H;
5757
start_at=initial_vector,
5858
reporting_strategy,
5959
post_step_strategy=ProjectedEnergy(H, initial_vector),
60-
targetwalkers=10_000,
60+
target_walkers=10_000,
6161
time_step=1e-4,
6262
last_step=10_000
6363
);

scripts/BHM-example.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ H = HubbardReal1D(initial_address; u = 6.0, t = 1.0)
2929
# use in this Monte Carlo run, which is equivalent to the average one-norm of the
3030
# coefficient vector. Higher values will result in better statistics, but require more
3131
# memory and computing power.
32-
targetwalkers = 1_000;
32+
target_walkers = 1_000;
3333

3434
# FCIQMC takes a certain number of steps to equllibrate, after which the observables will
3535
# fluctuate around a mean value. In this example, we will devote 1000 steps to equilibration
@@ -76,7 +76,7 @@ problem = ProjectorMonteCarloProblem(
7676
start_at = initial_vector,
7777
last_step,
7878
time_step,
79-
targetwalkers,
79+
target_walkers,
8080
post_step_strategy
8181
);
8282

@@ -91,11 +91,11 @@ df = DataFrame(simulation);
9191

9292
# We can plot the norm of the coefficient vector as a function of the number of steps.
9393
hline(
94-
[targetwalkers];
95-
label="targetwalkers", xlabel="steps", ylabel="norm",
94+
[target_walkers];
95+
label="target_walkers", xlabel="step", ylabel="norm",
9696
color=2, linestyle=:dash, margin = 1Plots.cm
9797
)
98-
plot!(df.steps, df.norm, label="norm", color=1)
98+
plot!(df.step, df.norm, label="norm", color=1)
9999

100100
# After an initial equilibriation period, the norm fluctuates around the target number of
101101
# walkers.
@@ -120,11 +120,11 @@ pe = projected_energy(df; skip=steps_equilibrate)
120120
v = val_and_errs(pe; p=0.95)
121121

122122
# Let's visualise these estimators together with the time series of the shift.
123-
plot(df.steps, df.shift, ylabel="energy", xlabel="steps", label="shift", margin = 1Plots.cm)
123+
plot(df.step, df.shift, ylabel="energy", xlabel="step", label="shift", margin = 1Plots.cm)
124124

125-
plot!(x->se.mean, df.steps[steps_equilibrate+1:end], ribbon=se.err, label="shift mean")
125+
plot!(x->se.mean, df.step[steps_equilibrate+1:end], ribbon=se.err, label="shift mean")
126126
plot!(
127-
x -> v.val, df.steps[steps_equilibrate+1:end], ribbon=(v.val_l,v.val_u),
127+
x -> v.val, df.step[steps_equilibrate+1:end], ribbon=(v.val_l,v.val_u),
128128
label="projected energy",
129129
)
130130
lens!([steps_equilibrate, last_step], [-5.1, -2.9]; inset=(1, bbox(0.2, 0.25, 0.6, 0.4)))
@@ -146,7 +146,7 @@ exact_energy = solve(edp).values[1]
146146

147147
println(
148148
"""
149-
Energy from $steps_measure steps with $targetwalkers walkers:
149+
Energy from $steps_measure steps with $target_walkers walkers:
150150
Shift: $(se.mean) ± $(se.err)
151151
Projected Energy: $(v.val) ± ($(v.val_l), $(v.val_u))
152152
Exact Energy: $exact_energy

scripts/G2-example.jl

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,22 @@ replica_strategy = AllOverlaps(num_replicas; operator = G2list)
5353
# Other FCIQMC parameters and strategies can be set in the same way as before.
5454
steps_equilibrate = 1_000
5555
steps_measure = 5_000
56-
targetwalkers = 100;
57-
= 0.001
56+
target_walkers = 100;
57+
time_step = 0.001
5858

5959
Random.seed!(17); #hide
6060

6161
# Now, we run FCIQMC. Note that passing an initial vector is optional - if we only pass the
6262
# style, a vector with the appropriate style is created automatically.
63-
df, state = lomc!(
64-
H; style=IsDynamicSemistochastic(),
65-
,
66-
laststep = steps_equilibrate + steps_measure,
67-
targetwalkers,
63+
problem = ProjectorMonteCarloProblem(H;
64+
style=IsDynamicSemistochastic(),
65+
time_step,
66+
last_step = steps_equilibrate + steps_measure,
67+
target_walkers,
6868
replica_strategy,
69-
);
69+
)
70+
result = solve(problem)
71+
df = DataFrame(result);
7072

7173
# The output `DataFrame` has FCIQMC statistics for each replica (e.g. shift, norm),
7274
println(filter(startswith("shift_"), names(df)))

src/DictVectors/initiatordvec.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""
22
InitiatorDVec{K,V} <: AbstractDVec{K,V}
33
4-
Dictionary-based vector-like data structure for use with [`lomc!`](@ref Main.lomc!) and
4+
Dictionary-based vector-like data structure for use with
5+
[`ProjectorMonteCarloProblem`](@ref Main.ProjectorMonteCarloProblem) and
56
[`KrylovKit.jl`](https://github.com/Jutho/KrylovKit.jl). See [`AbstractDVec`](@ref).
67
Functionally identical to [`DVec`](@ref), but contains [`InitiatorValue`](@ref)s internally
78
in order to facilitate initiator methods. Initiator methods for controlling the Monte Carlo

src/DictVectors/projectors.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ products. Implemented subtypes:
1010
- [`Norm2Projector`](@ref)
1111
- [`Norm1ProjectorPPop`](@ref)
1212
13-
See also [`PostStepStrategy`](@ref Main.PostStepStrategy) for use of projectors in [`lomc!`](@ref Main.lomc!).
13+
See also [`PostStepStrategy`](@ref Main.PostStepStrategy) for use of projectors in [`ProjectorMonteCarloProblem`](@ref Main.ProjectorMonteCarloProblem).
1414
1515
## Interface
1616
@@ -33,7 +33,7 @@ dot(UniformProjector(), LO, v) == sum(LO*v)
3333
```
3434
3535
See also [`PostStepStrategy`](@ref Main.PostStepStrategy), and [`AbstractProjector`](@ref) for use
36-
of projectors in [`lomc!`](@ref Main.lomc!).
36+
of projectors in [`ProjectorMonteCarloProblem`](@ref Main.ProjectorMonteCarloProblem).
3737
"""
3838
struct UniformProjector <: AbstractProjector end
3939

@@ -60,7 +60,7 @@ dot(NormProjector(),x)
6060
`NormProjector()` thus represents the vector `sign.(x)`.
6161
6262
See also [`PostStepStrategy`](@ref Main.PostStepStrategy), and [`AbstractProjector`](@ref) for use
63-
of projectors in [`lomc!`](@ref Main.lomc!).
63+
of projectors in [`ProjectorMonteCarloProblem`](@ref Main.ProjectorMonteCarloProblem).
6464
"""
6565
struct NormProjector <: AbstractProjector end
6666

@@ -75,7 +75,7 @@ dot(NormProjector(),x)
7575
```
7676
7777
See also [`PostStepStrategy`](@ref Main.PostStepStrategy), and [`AbstractProjector`](@ref) for use
78-
of projectors in [`lomc!`](@ref Main.lomc!).
78+
of projectors in [`ProjectorMonteCarloProblem`](@ref Main.ProjectorMonteCarloProblem).
7979
"""
8080
struct Norm2Projector <: AbstractProjector end
8181

@@ -92,7 +92,7 @@ dot(Norm1ProjectorPPop(),x)
9292
```
9393
9494
See also [`PostStepStrategy`](@ref Main.PostStepStrategy), and [`AbstractProjector`](@ref) for use
95-
of projectors in [`lomc!`](@ref Main.lomc!).
95+
of projectors in [`ProjectorMonteCarloProblem`](@ref Main.ProjectorMonteCarloProblem).
9696
"""
9797
struct Norm1ProjectorPPop <: AbstractProjector end
9898

@@ -121,7 +121,7 @@ dot(PopsProjector(),x)
121121
```
122122
123123
See also [`PostStepStrategy`](@ref Main.PostStepStrategy), and [`AbstractProjector`](@ref) for use
124-
of projectors in [`lomc!`](@ref Main.lomc!).
124+
of projectors in [`ProjectorMonteCarloProblem`](@ref Main.ProjectorMonteCarloProblem).
125125
"""
126126
struct PopsProjector <: AbstractProjector end
127127

src/Hamiltonians/MatrixHamiltonian.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
starting_address::Int = starting_address(mat)
55
) <: AbstractHamiltonian{T}
66
Wrap an abstract matrix `mat` as an [`AbstractHamiltonian`](@ref) object.
7-
Works with stochastic methods of [`lomc!()`](@ref) and [`DVec`](@ref).
7+
Works with stochastic methods of [`ProjectorMonteCarloProblem()`](@ref) and [`DVec`](@ref).
88
Optionally, a valid index can be provided as the [`starting_address`](@ref).
99
1010
Specialised methods are implemented for sparse matrices of type `AbstractSparseMatrixCSC`.

src/Hamiltonians/correlation_functions.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ Assumes a one-dimensional lattice with ``M`` sites and periodic boundary conditi
392392
393393
# Usage
394394
Superfluid correlations can be extracted from a Monte Carlo calculation by wrapping `SuperfluidCorrelator` with
395-
[`AllOverlaps`](@ref) and passing into [`lomc!`](@ref) with the `replica` keyword argument. For an example with a
395+
[`AllOverlaps`](@ref) and passing into [`ProjectorMonteCarloProblem`](@ref) with the `replica` keyword argument. For an example with a
396396
similar use of [`G2RealCorrelator`](@ref) see
397397
[G2 Correlator Example](https://joachimbrand.github.io/Rimu.jl/previews/PR227/generated/G2-example.html).
398398

0 commit comments

Comments
 (0)