Skip to content

Commit

Permalink
Breaking changes before v1.0 release (#268)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* Apply suggestions from code review

Co-authored-by: christofbradly <[email protected]>

* deprecate instead of remove `targetwalkers`

---------

Co-authored-by: Joachim Brand <[email protected]>
Co-authored-by: mtsch <[email protected]>
Co-authored-by: christofbradly <[email protected]>
  • Loading branch information
4 people authored Jul 9, 2024
1 parent 8be042d commit 26e1255
Show file tree
Hide file tree
Showing 32 changed files with 337 additions and 233 deletions.
6 changes: 3 additions & 3 deletions benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const SUITE = @benchmarkset "Rimu" begin
ham = HubbardMom1D(addr, u=1.0)
dv = PDVec(addr => 1.0; style=IsDynamicSemistochastic(), initiator=true)
post_step = ProjectedEnergy(ham, dv)
s_strat = DoubleLogUpdate(targetwalkers=40_000)
s_strat = DoubleLogUpdate(target_walkers=40_000)

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

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

lomc!(ham, dv; s_strat, dτ=1e-4, laststep=1000)
end seconds=150
Expand Down
1 change: 1 addition & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ makedocs(;
"Examples" => EXAMPLES_PAIRS[sortperm(EXAMPLES_NUMS)],
"User documentation" => [
"Exact Diagonalization" => "exactdiagonalization.md",
"Projector Monte Carlo" => "projectormontecarlo.md",
"StatsTools" => "statstools.md",
"Using MPI" => "mpi.md",
],
Expand Down
45 changes: 45 additions & 0 deletions docs/src/projectormontecarlo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Projector Monte Carlo / FCIQMC

The purpose of Projector Monte Carlo is to stochastically sample the ground state, i.e. the
eigenvector corresponding to the lowest eigenvalue of a quantum Hamiltonian, or more generally,
a very large matrix. Rimu implements a flavor of Projector Monte Carlo called
Full Configuration Interaction Quantum Monte Carlo (FCIQMC).

## `ProjectorMonteCarloProblem`

To run a projector Monte Carlo simulation you set up a problem with `ProjectorMonteCarloProblem`
and solve it with `solve`. Alternatively you can initialize a `PMCSimulation` struct, `step!`
through time steps, and `solve!` it to completion.

```@docs; canonical=false
ProjectorMonteCarloProblem
init
solve
solve!
step!
```

After `solve` or `solve!` have been called the returned `PMCSimulation` contains the results of
the projector Monte Carlo calculation.

### `PMCSimulation` and report as a `DataFrame`

```@docs; canonical=false
Rimu.PMCSimulation
```

The `DataFrame` returned from `DataFrame(::PMCSimulation)` contains the time series data from
the projector Monte Carlo simulation that is of primary interest for analysis. Depending on the
`reporting_strategy` and other options passed as keyword arguments to
`ProjectorMonteCarloProblem` it can have different numbers of rows and columns. The rows
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.

For the default option `algorithm = FCIQMC(; shift_strategy, time_step_strategy)` with a single
replica (`n_replicas = 1`) and single spectral state, the fields `:shift`, `:norm`, `:len` will
be present as well as others depending on the `style` argument and the `post_step_strategy`.

If multiple replicas or spectral states are requested, then the relevant field names in the
`DataFrame` will have a suffix identifying the respective replica simulation, e.g. the `shift`s will be reported as `shift_1`, `shift_2`, ...

Many tools for analysing the time series data obtained from a
[`ProjectorMonteCarloProblem`](@ref) are contained in the [Module `StatsTools`](@ref).
2 changes: 1 addition & 1 deletion scripts/BHM-example-mpi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ problem = ProjectorMonteCarloProblem(H;
start_at=initial_vector,
reporting_strategy,
post_step_strategy=ProjectedEnergy(H, initial_vector),
targetwalkers=10_000,
target_walkers=10_000,
time_step=1e-4,
last_step=10_000
);
Expand Down
18 changes: 9 additions & 9 deletions scripts/BHM-example.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ H = HubbardReal1D(initial_address; u = 6.0, t = 1.0)
# use in this Monte Carlo run, which is equivalent to the average one-norm of the
# coefficient vector. Higher values will result in better statistics, but require more
# memory and computing power.
targetwalkers = 1_000;
target_walkers = 1_000;

# FCIQMC takes a certain number of steps to equllibrate, after which the observables will
# fluctuate around a mean value. In this example, we will devote 1000 steps to equilibration
Expand Down Expand Up @@ -76,7 +76,7 @@ problem = ProjectorMonteCarloProblem(
start_at = initial_vector,
last_step,
time_step,
targetwalkers,
target_walkers,
post_step_strategy
);

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

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

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

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

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

println(
"""
Energy from $steps_measure steps with $targetwalkers walkers:
Energy from $steps_measure steps with $target_walkers walkers:
Shift: $(se.mean) ± $(se.err)
Projected Energy: $(v.val) ± ($(v.val_l), $(v.val_u))
Exact Energy: $exact_energy
Expand Down
18 changes: 10 additions & 8 deletions scripts/G2-example.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,22 @@ replica_strategy = AllOverlaps(num_replicas; operator = G2list)
# Other FCIQMC parameters and strategies can be set in the same way as before.
steps_equilibrate = 1_000
steps_measure = 5_000
targetwalkers = 100;
= 0.001
target_walkers = 100;
time_step = 0.001

Random.seed!(17); #hide

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

# The output `DataFrame` has FCIQMC statistics for each replica (e.g. shift, norm),
println(filter(startswith("shift_"), names(df)))
Expand Down
3 changes: 2 additions & 1 deletion src/DictVectors/initiatordvec.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""
InitiatorDVec{K,V} <: AbstractDVec{K,V}
Dictionary-based vector-like data structure for use with [`lomc!`](@ref Main.lomc!) and
Dictionary-based vector-like data structure for use with
[`ProjectorMonteCarloProblem`](@ref Main.ProjectorMonteCarloProblem) and
[`KrylovKit.jl`](https://github.com/Jutho/KrylovKit.jl). See [`AbstractDVec`](@ref).
Functionally identical to [`DVec`](@ref), but contains [`InitiatorValue`](@ref)s internally
in order to facilitate initiator methods. Initiator methods for controlling the Monte Carlo
Expand Down
12 changes: 6 additions & 6 deletions src/DictVectors/projectors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ products. Implemented subtypes:
- [`Norm2Projector`](@ref)
- [`Norm1ProjectorPPop`](@ref)
See also [`PostStepStrategy`](@ref Main.PostStepStrategy) for use of projectors in [`lomc!`](@ref Main.lomc!).
See also [`PostStepStrategy`](@ref Main.PostStepStrategy) for use of projectors in [`ProjectorMonteCarloProblem`](@ref Main.ProjectorMonteCarloProblem).
## Interface
Expand All @@ -33,7 +33,7 @@ dot(UniformProjector(), LO, v) == sum(LO*v)
```
See also [`PostStepStrategy`](@ref Main.PostStepStrategy), and [`AbstractProjector`](@ref) for use
of projectors in [`lomc!`](@ref Main.lomc!).
of projectors in [`ProjectorMonteCarloProblem`](@ref Main.ProjectorMonteCarloProblem).
"""
struct UniformProjector <: AbstractProjector end

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

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

Expand All @@ -92,7 +92,7 @@ dot(Norm1ProjectorPPop(),x)
```
See also [`PostStepStrategy`](@ref Main.PostStepStrategy), and [`AbstractProjector`](@ref) for use
of projectors in [`lomc!`](@ref Main.lomc!).
of projectors in [`ProjectorMonteCarloProblem`](@ref Main.ProjectorMonteCarloProblem).
"""
struct Norm1ProjectorPPop <: AbstractProjector end

Expand Down Expand Up @@ -121,7 +121,7 @@ dot(PopsProjector(),x)
```
See also [`PostStepStrategy`](@ref Main.PostStepStrategy), and [`AbstractProjector`](@ref) for use
of projectors in [`lomc!`](@ref Main.lomc!).
of projectors in [`ProjectorMonteCarloProblem`](@ref Main.ProjectorMonteCarloProblem).
"""
struct PopsProjector <: AbstractProjector end

Expand Down
2 changes: 1 addition & 1 deletion src/Hamiltonians/MatrixHamiltonian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
starting_address::Int = starting_address(mat)
) <: AbstractHamiltonian{T}
Wrap an abstract matrix `mat` as an [`AbstractHamiltonian`](@ref) object.
Works with stochastic methods of [`lomc!()`](@ref) and [`DVec`](@ref).
Works with stochastic methods of [`ProjectorMonteCarloProblem()`](@ref) and [`DVec`](@ref).
Optionally, a valid index can be provided as the [`starting_address`](@ref).
Specialised methods are implemented for sparse matrices of type `AbstractSparseMatrixCSC`.
Expand Down
2 changes: 1 addition & 1 deletion src/Hamiltonians/correlation_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ Assumes a one-dimensional lattice with ``M`` sites and periodic boundary conditi
# Usage
Superfluid correlations can be extracted from a Monte Carlo calculation by wrapping `SuperfluidCorrelator` with
[`AllOverlaps`](@ref) and passing into [`lomc!`](@ref) with the `replica` keyword argument. For an example with a
[`AllOverlaps`](@ref) and passing into [`ProjectorMonteCarloProblem`](@ref) with the `replica` keyword argument. For an example with a
similar use of [`G2RealCorrelator`](@ref) see
[G2 Correlator Example](https://joachimbrand.github.io/Rimu.jl/previews/PR227/generated/G2-example.html).
Expand Down
4 changes: 3 additions & 1 deletion src/Interfaces/Interfaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ This module contains interfaces that can be used to extend and modify the algori
Follow the links for the definitions of the interfaces!
* [`AbstractHamiltonian`](@ref) for defining [`Hamiltonians`](@ref Main.Hamiltonians)
* [`AbstractDVec`](@ref) for defining data structures for `Rimu` as in [`DictVectors`](@ref Main.DictVectors)
* [`StochasticStyle`](@ref) for controlling the stochastic algorithms used by [`lomc!`](@ref Main.lomc!) as implemented in [`StochasticStyles`](@ref Main.StochasticStyles)
* [`StochasticStyle`](@ref) for controlling the stochastic algorithms used by
[`ProjectorMonteCarloProblem`](@ref Main.ProjectorMonteCarloProblem) as implemented in
[`StochasticStyles`](@ref Main.StochasticStyles)
# Additional exports
Expand Down
3 changes: 2 additions & 1 deletion src/Interfaces/dictvectors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Abstract data type for vector-like data structures with sparse storage. While co
`AbstractDVec`s represent elements of a vector space over a scalar type `V`, they are
indexed by an arbitrary type `K` (could be non-integers) similar to dictionaries. They
support the interface from [VectorInterface.jl](https://github.com/Jutho/VectorInterface.jl)
and are designed to work well for quantum Monte Carlo with [`lomc!`](@ref Main.lomc!) and
and are designed to work well for quantum Monte Carlo with
[`ProjectorMonteCarloProblem`](@ref Main.ProjectorMonteCarloProblem) and
for matrix-free linear algebra with [KrylovKit](https://github.com/Jutho/KrylovKit.jl).
Concrete implementations are available as [`PDVec`](@ref Main.DictVectors.PDVec),
Expand Down
3 changes: 2 additions & 1 deletion src/Interfaces/hamiltonians.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
AbstractHamiltonian{T}
Supertype that provides an interface for linear operators over a linear space with scalar
type `T` that are suitable for FCIQMC (with [`lomc!`](@ref Main.lomc!)). Indexing is done
type `T` that are suitable for FCIQMC (with
[`ProjectorMonteCarloProblem`](@ref Main.ProjectorMonteCarloProblem)). Indexing is done
with addresses (typically not integers) from an address space that may be large (and will
not need to be completely generated).
Expand Down
8 changes: 5 additions & 3 deletions src/Interfaces/stochasticstyles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ generalised vector `v` that determines how simulations are to proceed.
# Usage
Concrete `StochasticStyle`s can be used for the `style` keyword argument of
[`lomc!`](@ref Main.lomc!), [`DVec`](@ref Main.DictVectors.DVec) and
[`ProjectorMonteCarloProblem`](@ref Main.ProjectorMonteCarloProblem),
[`DVec`](@ref Main.DictVectors.DVec) and
[`PDVec`](@ref Main.DictVectors.PDVec). The following styles are available:
* [`IsStochasticInteger`](@ref Main.StochasticStyles.IsStochasticInteger)
Expand All @@ -22,7 +23,7 @@ Concrete `StochasticStyle`s can be used for the `style` keyword argument of
When defining a new `StochasticStyle`, subtype it as `MyStyle<:StochasticStyle{T}` where `T`
is the concrete value type the style is designed to work with.
For it to work with [`lomc!`](@ref Main.lomc!), a `StochasticStyle` must define the
For it to work with [`ProjectorMonteCarloProblem`](@ref Main.ProjectorMonteCarloProblem), a `StochasticStyle` must define the
following:
* [`apply_column!(::StochasticStyle, w, H, address, value)`](@ref)
Expand Down Expand Up @@ -123,7 +124,8 @@ end
step_stats(::CompressionStrategy)
Return a tuple of stat names (`Symbol` or `String`) and a tuple of zeros of the same
length. These will be reported as columns in the `DataFrame` returned by [`lomc!`](@ref Main.lomc!).
length. These will be reported as columns in the `DataFrame` returned by
[`ProjectorMonteCarloProblem`](@ref Main.ProjectorMonteCarloProblem).
"""
step_stats(v) = step_stats(StochasticStyle(v))

Expand Down
13 changes: 9 additions & 4 deletions src/StatsTools/growth_witness.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ function growth_witness(shift::AbstractArray, norm::AbstractArray, dt, b; kwargs
return smoothen(g_raw, b)
end
"""
growth_witness(df::DataFrame, [b]; shift=:shift, norm=:norm, dτ=df.dτ[end], skip=0)
growth_witness(df::DataFrame, [b];
shift=:shift,
norm=:norm,
time_step=determine_constant_time_step(df),
skip=0
)
growth_witness(sim::PMCSimulation, [b]; kwargs...)
Calculate the growth witness directly from the result (`DataFrame` or
Expand All @@ -43,14 +48,14 @@ Calculate the growth witness directly from the result (`DataFrame` or
"""
function growth_witness(
sim, b=Val(0);
shift=:shift, norm=:norm, =nothing, kwargs...
shift=:shift, norm=:norm, time_step=nothing, kwargs...
)
df = DataFrame(sim)
= determine_constant_time_step(df)
time_step = determine_constant_time_step(df)

shift_vec = getproperty(df, Symbol(shift))
norm_vec = getproperty(df, Symbol(norm))
return growth_witness(shift_vec, norm_vec, , b; kwargs...)
return growth_witness(shift_vec, norm_vec, time_step, b; kwargs...)
end

"""
Expand Down
Loading

2 comments on commit 26e1255

@joachimbrand
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes:

Breaking release with a major rework of the user interface.
This release is a transition step where a much of the old user interface
is still there an usable but deprecated. If you get warning messages using
your scripts with this release, please follow instructions and update
your script to be ready for the next breaking release.

New user interface

  • CommonSolve.solve is implemented for ProjectorMonteCarloProblem as the main entrance point
    to perform an FCIQMC calculation. Methods for solve, solve!, init are implemented.
    A report in form of a DataFrame can be returned from a simulation but the column names have changed.
  • ExactDiagonalizationProblem together with the relevant solve method is a new access point for
    exact diagonalization of AbstractHamiltonians

See PR#248 for a more detailed description of the changes.

Other new features

  • LatticeGeometry, PeriodicBoundaries, HardwallBoundaries and LadderBoundaries replaced with CubicGrid.
  • Observables with eltype(op) <: AbstractArray are now supported in both dot and for use in AllOverlaps.
  • New G2RealSpace operator, which is aware of the geometry and computes G_2 for all displacement vectors at the same time.

Deprecations

  • lomc!
  • targetwalkers as keyword argument to many ShiftStrategys is deprecated in favor of target_walkers
  • FCIQMCRunStrategy and its subtype RunTillLastStep are deprecated.

Breaking changes

  • LatticeGeometry no longer exists, PeriodicBoundaries, HardwallBoundaries and LadderBoundaries are no longer separate types. All user code should still run without modifications.
  • removed TripleLogUpdate
  • lomc! does not accept AbstractMatrix as argument
  • new default style=IsDynamicSemistochastic() for default_starting_vector

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/110788

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.12.0 -m "<description of version>" 26e1255ffe23fec51f2881bc8809e444025fe988
git push origin v0.12.0

Please sign in to comment.