In this example, we will demonstrate using Rimu with MPI. A runnable script is located at here. Run it as mpirun julia BHM-example.jl
.
We start by importing Rimu
and Rimu.RMPI
, which contains MPI-replated 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))
BoseFS{10,10}((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)
HubbardMom1D(BoseFS{10,10}((0, 0, 0, 0, 10, 0, 0, 0, 0, 0)); u=6.0, t=1.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
, which improves statistics and reduces the sign problem.
dvec = MPIData(DVec(address => 1.0; style=IsDynamicSemistochastic()))
MPIData(DVec) with 1 entries, style = IsDynamicSemistochastic{Float64, true}(1.0, Inf, 1.0), strategy = MPIPointToPoint
BoseFS{10,10}((0, 0, 0, 0, 10, 0, 0, 0, 0, 0)) => 1.0
We set a reporting strategy. We will use ReportToFile
, 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.
r_strat = ReportToFile(filename="result.arrow", save_if=is_mpi_root(), chunk_size=1000)
ReportToFile
filename: String "result.arrow"
chunk_size: Int64 1000
save_if: Bool true
return_df: Bool false
io: IOContext{Base.PipeEndpoint}
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)
ProjectedEnergy{HubbardMom1D{Float64, 10, BoseFS{10, 10, BitString{19, 1, UInt32}}, 6.0, 1.0}, Rimu.DictVectors.FrozenDVec{BoseFS{10, 10, BitString{19, 1, UInt32}}, Float64}, Rimu.DictVectors.FrozenDVec{BoseFS{10, 10, BitString{19, 1, UInt32}}, Float64}}(:vproj, :hproj, HubbardMom1D(BoseFS{10,10}((0, 0, 0, 0, 10, 0, 0, 0, 0, 0)); u=6.0, t=1.0), Rimu.DictVectors.FrozenDVec{BoseFS{10, 10, BitString{19, 1, UInt32}}, Float64}(Pair{BoseFS{10, 10, BitString{19, 1, UInt32}}, Float64}[BoseFS{10,10}((0, 0, 0, 0, 10, 0, 0, 0, 0, 0)) => 1.0]), Rimu.DictVectors.FrozenDVec{BoseFS{10, 10, BitString{19, 1, UInt32}}, Float64}(Pair{BoseFS{10, 10, BitString{19, 1, UInt32}}, Float64}[BoseFS{10,10}((1, 0, 0, 0, 8, 0, 0, 0, 1, 0)) => 5.692099788303083, BoseFS{10,10}((0, 0, 0, 0, 8, 0, 0, 0, 0, 2)) => 4.024922359499621, BoseFS{10,10}((0, 0, 0, 0, 10, 0, 0, 0, 0, 0)) => 7.0, BoseFS{10,10}((0, 0, 1, 0, 8, 0, 1, 0, 0, 0)) => 5.692099788303083, BoseFS{10,10}((0, 0, 0, 1, 8, 1, 0, 0, 0, 0)) => 5.692099788303083, BoseFS{10,10}((0, 1, 0, 0, 8, 0, 0, 1, 0, 0)) => 5.692099788303083]))
Finally, we can run the computation. The @mpi_root
macro performs an action on the root rank only, which is useful for printing.
lomc!(hamiltonian, dvec; r_strat, s_strat, post_step, dτ=1e-4, laststep=10_000)
@mpi_root println("Finished!")
This page was generated using Literate.jl.