Tutorial on parallelizing Monte Carlo simulations
Description
As pointed out by @angqvist in this issue, Monte Carlo (MC) simulations can be sped up enormously by using parallel resources. The snippet below illustrates how to do this (copied from here). It would be very useful to have an advanced tutorial section that describes this approach.
Demonstration
- new tutorial section added
- no compilation errors or warnings for user guide (or anything else)
Illustration
from multiprocessing import Pool
#regular code above
calculator = ClusterExpansionCalculator(atoms, ce)
def run_vcmc(args):
temperature = args[0]
phi = args[1]
print(f"running {temperature} and {phi}")
concentration_parameters = {chemical_symbols[0]: phi,
chemical_symbols[1]: -2 - phi}
mc = VCSGCEnsemble(
calculator=calculator,
atoms=atoms,
temperature=temperature,
phis=concentration_parameters,
kappa=10.0,
data_container='data/vcsgc-T{}-phi{:.3f}.dc'.format(temperature, phi))
mc.run(number_of_trial_steps=10000)
pool = Pool(processes=4)
args = []
for temperature in arange(675, 75, -25):
for phi in arange(-2.1, 0.125, 0.025):
args.append([temperature, phi])
pool.map(run_vcmc, args)
Edited by Paul Erhart