-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBHM-example-mpi.jl
59 lines (40 loc) · 2.54 KB
/
BHM-example-mpi.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# # Example 2: Rimu with MPI
# In this example, we will demonstrate using Rimu with MPI.
# A runnable script for this example is located
# [here](https://github.com/joachimbrand/Rimu.jl/blob/develop/scripts/BHM-example-mpi.jl).
# Run it with `mpirun julia BHM-example-mpi.jl`.
# We start by importing `Rimu` and `Rimu.RMPI`, which contains MPI-related
# functionality.
using Rimu
using Rimu.RMPI
# We will compute the ground-state of a Bose-Hubbard model in momentum space with 10 particles
# in 10 sites.
# First, we define the Hamiltonian. We want to start from an address with zero momentum.
address = BoseFS((0, 0, 0, 0, 10, 0, 0, 0, 0, 0))
# We will set the interaction strength `u` to `6`. The hopping strength `t` defaults to `1.0`.
hamiltonian = HubbardMom1D(address; u=6.0)
# Next, we construct the starting vector. Wrap a vector in `MPIData` to make it MPI
# distributed. We set the vector's style to [`IsDynamicSemistochastic`](@ref), which
# improves statistics and reduces the sign problem.
dvec = MPIData(DVec(address => 1.0; style=IsDynamicSemistochastic()))
# We set a reporting strategy. We will use [`ReportToFile`](@ref), which writes the reports
# directly to a file. This is useful for reducing memory use in long-running jobs, as we
# don't need to keep the results in memory. Setting `save_if=is_mpi_root()` will ensure only
# the root MPI rank will write to the file. The `chunk_size` parameter determines how often
# the data is saved to the file. Progress messages are suppressed with `io=devnull`.
r_strat = ReportToFile(filename="result.arrow", save_if=is_mpi_root(), reporting_interval = 1, chunk_size=1000, io=devnull)
# Now, we can set other parameters as usual. We will perform the computation with 10_000
# walkers. We will also compute the projected energy.
s_strat = DoubleLogUpdate(targetwalkers=10_000)
post_step = ProjectedEnergy(hamiltonian, dvec)
# The `@mpi_root` macro performs an action on the root rank only, which is useful for printing.
@mpi_root println("Running FCIQMC with ", mpi_size(), " rank(s).")
# Finally, we can run the computation.
lomc!(hamiltonian, dvec; r_strat, s_strat, post_step, dτ=1e-4, laststep=10_000);
using Test #hide
@test isfile("result.arrow") #hide
dfr = load_df("result.arrow") #hide
qmcdata = last(dfr, 5000) #hide
(qmcShift,qmcShiftErr) = mean_and_se(qmcdata.shift) #hide
@test qmcShift ≈ -6.5 atol=0.5 #hide
rm("result.arrow", force=true) #hide