59 real(real64),
dimension(:),
allocatable :: p_arr
60 real(real64),
dimension(:),
allocatable :: bonds
61 real(real64),
dimension(:),
allocatable :: H2plus_param_c_array
62 real(real64),
dimension(:),
allocatable :: H2_param_a_array
63 real(real64),
dimension(:),
allocatable :: H2_param_beta_array
64 real(real64),
dimension(:),
allocatable :: energies
65 real(real64),
dimension(:),
allocatable :: variances
66 real(real64),
dimension(:),
allocatable :: accept_rates
68 real(real64) :: H2plus_param_c_guess
69 real(real64) :: H2plus_param_c_opt
70 real(real64) :: H2_param_beta_guess
71 real(real64) :: H2_param_beta_opt
72 real(real64) :: H2_param_a
73 real(real64) :: energy
74 real(real64) :: variance
75 real(real64) :: accept_rate
80 character(len=1) :: H2plus_c_converged
81 character(len=1) :: H2_beta_converged
91 call mpi_comm_size(mpi_comm_world,
p,
mpierr)
101 write(*,
"('System: ', A)")
p_system
109 call system(
'mkdir ./equil_out 2>/dev/null')
110 write(*,
"('Dice QMC started in Equilibration Mode')")
114 write(*,
"(A, I7, A)")
'WARNING: The program will be slow at writing equilibration files, &
115 &as the requested number of steps exceeds the recommended &
116 &upper limit of ',
max_chain_len,
' steps. Refer to the user manual for details.'
124 call system(
'mkdir ./chains_out 2>/dev/null')
125 write(*,
"('Dice QMC started in full VQMC mode with additional Markov chain outputting')")
128 write(*,*)
'NOTE: For efficiency, only the first ',
max_chain_len,
' entries of the Markov chain &
129 &(after burning and thinning) will be written out to the chains_out folder.'
132 error stop
"Dice QMC cannot be started with both run_equil and write_chains set &
133 &to TRUE. Check your input params.txt and try again."
142 form=
'formatted', iostat=logiostat)
143 if (logiostat .ne. 0)
write(0, *)
'Error opening log file ',
logfile
146 write(
logid,
"('*** Dice QMC log file ***')")
147 write(
logid,
"('-------------------------------')")
187 per_proc = 1.0_real64 / real(
p,kind=real64)
193 call mpi_bcast(
per_proc,1,mpi_double_precision,0,mpi_comm_world,
mpierr)
206 write(
logid,
"('Initial seed from /dev/urandom: ', I20)")
seed
211 h2plus%auto_params = .false.
212 write(*,
"('WARNING: H2plus%auto_params should not be .TRUE. when in Equilibration Mode, disabling...')")
213 else if (trim(
p_system) .eq.
'H2' .and.
h2%auto_params)
then
214 h2%auto_params = .false.
215 write(*,
"('WARNING: H2plus%auto_params should not be .TRUE. when in Equilibration Mode, disabling...')")
229 write(
logid,
"('Rank ',I2,'. Initial seed from /dev/urandom: ', I20)")
my_rank,
seed
234 write(
logid,
"('Rank ',I2,'. Initial seed from /dev/urandom: ', I20)")
ip,
ip_seed
257 write(*,
"('Doing VQMC runs across ', I3, ' parameter(s).')") int(
qho%alpha(3))
258 write(*,
"('Steps: ', I10, ', Burn Steps: ', I7, ', Thin Every ', I7, ' Steps.')") &
267 write(*,
"('Grid search across linearly spaced parameters enabled.')")
270 write(
logid,
"('Grid search across linearly spaced parameters enabled.')")
271 write(
logid,
"('Array of alpha values: ')")
272 do i = 1, int(
qho%alpha(3))
273 write(
logid,
"(F12.8)") p_arr(i)
287 allocate(energies(int(
qho%alpha(3)))); energies(:) = 0.0_real64
288 allocate(variances(int(
qho%alpha(3)))); variances(:) = 0.0_real64
289 allocate(accept_rates(int(
qho%alpha(3)))); accept_rates(:) = 0.0_real64
298 call grid_qho(p_arr, energies, accept_rates, variances)
308 allocate(energies(int(
h2plus%bond(3))))
309 allocate(variances(int(
h2plus%bond(3))))
310 allocate(accept_rates(int(
h2plus%bond(3))))
311 allocate(h2plus_param_c_array(int(
h2plus%bond(3))))
315 write(*,
"('Doing VQMC runs across ', I7, ' bond lengths.')") int(
h2plus%bond(3))
316 write(*,
"('Steps: ', I10, ', Burn Steps: ', I7, ', Thin Every ', &
324 write(
logid,
"('Array of bond lengths: ')")
325 do i = 1, int(
h2plus%bond(3))
326 write(
logid,
"('Bond length ', I4, ': ', F7.4)") i, bonds(i)
332 if (
h2plus%auto_params .eqv. .false.)
then
338 if (
h2plus%auto_params .eqv. .false.)
then
339 write(*,
"('Grid search across linearly spaced parameters enabled.')")
342 write(
logid,
"('Grid search across linearly spaced parameters enabled.')")
343 write(
logid,
"('Array of c values: ')")
344 do i = 1, int(
h2plus%c_grid(3))
345 write(
logid,
"(F12.8)") p_arr(i)
350 write(*,
"('Automatic search across parameters enabled.')")
353 write(
logid,
"('Automatic search across parameters enabled.')")
368 if (.not.
res%auto) error stop
'Error: Inconsistency in auto_params setting between params.txt and res_nml.txt.'
369 h2plus_param_c_guess =
res%guess
371 h2plus_param_c_guess =
h2plus%c
377 write(*,
"('------------------ Begin VQMC Runs ------------------')")
378 write(*,
"('Bond Length Converged? Optimised c Energy')")
380 write(
logid,
"('------------------ Begin VQMC Runs ------------------')")
391 write(
logid,
"(' ------------- Bond Length = ', F7.4, ' ------------- ')") &
398 if (
h2plus%auto_params)
then
401 call auto_h_2_plus(h2plus_param_c_guess, bonds(b), h2plus_param_c_opt, &
402 energy, variance, accept_rate, h2plus_c_converged)
409 if (h2plus_c_converged .eq.
'Y') h2plus_param_c_guess = h2plus_param_c_opt
414 call grid_h_2_plus(p_arr, bonds(b), h2plus_param_c_opt, energy, &
415 variance, accept_rate)
425 h2plus_param_c_array(b) = h2plus_param_c_opt
427 variances(b) = variance
428 accept_rates(b) = accept_rate
436 if (
h2plus%auto_params)
then
461 write(*,
"('------------------- End VQMC Runs -------------------')")
466 write(*,
"(2A)")
'Calculations finished, writing results to NetCDF output file ', &
469 write(
logid,
"(2A)")
'Calculations finished, writing results to NetCDF &
487 allocate(energies(int(
h2%bond(3))))
488 allocate(variances(int(
h2%bond(3))))
489 allocate(accept_rates(int(
h2%bond(3))))
490 allocate(h2_param_a_array(int(
h2%bond(3))))
491 allocate(h2_param_beta_array(int(
h2%bond(3))))
495 write(*,
"('Doing VQMC runs across ', I7, ' bond lengths.')") int(
h2%bond(3))
496 write(*,
"('Steps: ', I10, ', Burn Steps: ', I7, ', Thin Every ', I7, ' Steps.')") &
497 h2%steps,
h2%burn_step,
h2%thin_step
504 write(
logid,
"('Array of bond lengths: ')")
505 do i = 1, int(
h2%bond(3))
506 write(
logid,
"('Bond length ', I4, ': ', F7.4)") i, bonds(i)
512 if (
h2%auto_params .eqv. .false.)
then
513 p_arr =
linspace(
h2%beta_grid(1),
h2%beta_grid(2),
h2%beta_grid(3))
518 if (
h2%auto_params .eqv. .false.)
then
519 write(*,
"('Grid search across linearly spaced parameters enabled.')")
522 write(
logid,
"('Grid search across linearly spaced parameters enabled.')")
523 write(
logid,
"('Array of beta values: ')")
524 do i = 1, int(
h2%beta_grid(3))
525 write(
logid,
"(F12.8)") p_arr(i)
530 write(*,
"('Automatic search across parameters enabled.')")
533 write(
logid,
"('Automatic search across parameters enabled.')")
548 if (.not.
res%auto) error stop
'Error: Inconsistency in auto_params setting between params.txt and res_nml.txt.'
549 h2_param_beta_guess =
res%guess
551 h2_param_beta_guess =
h2%beta
557 write(*,
"('------------------ Begin VQMC Runs ------------------')")
558 write(*,
"('Bond Length Converged? Optimised Beta Energy')")
560 write(
logid,
"('------------------ Begin VQMC Runs ------------------')")
571 write(
logid,
"(' ------------- Bond Length = ', F7.4, ' ------------- ')") &
582 if (
h2%auto_params)
then
585 call auto_h_2(h2_param_a, h2_param_beta_guess, bonds(b), h2_param_beta_opt, &
586 energy, variance, accept_rate, h2_beta_converged)
590 if (h2_beta_converged .eq.
'Y') h2_param_beta_guess = h2_param_beta_opt
598 call grid_h_2(h2_param_a, p_arr, bonds(b), h2_param_beta_opt, energy, &
599 variance, accept_rate)
606 call write_h2_main(h2_param_a_array, h2_param_beta_array, bonds, &
616 h2_param_a_array(b) = h2_param_a
617 h2_param_beta_array(b) = h2_param_beta_opt
619 variances(b) = variance
620 accept_rates(b) = accept_rate
625 call write_h2_main(h2_param_a_array, h2_param_beta_array, bonds, &
627 if (
h2%auto_params)
then
640 call equil_h_2(h2_param_a, p_arr, bonds(b), b)
653 write(*,
"('------------------- End VQMC Runs -------------------')")
659 write(*,
"(2A)")
'Calculations finished, writing results to NetCDF output file ', &
663 write(
logid,
"(2A)")
'Calculations finished, writing results to NetCDF &
667 call write_h2_main(h2_param_a_array, h2_param_beta_array, bonds, &
668 energies, variances,
outfile, ierr,
h2, accept_rates)
676 error stop
'Unknown case. How did you get here?'
683 call system(
'rm res_etot.nc 2>/dev/null')
684 call system(
'rm res_nml.txt 2>/dev/null')
685 call system(
'rm res_epar.nc 2>/dev/null')
program main
Main program, contains the driver subroutine that runs all other code.
subroutine driver()
Subroutine for running the main code (needed for Doxygen compatability).
Contains routines to read and write restart files.
subroutine write_res_nml(i_qoi, i_par, auto, guess)
Writes the restart file res_nml.txt, using the current states of simulation variables.
subroutine read_energies_h2plus(filename, energies, variances, accept_rates, c_array)
Reads restart files with energies, variances and acceptence arrays. Also reads one extra array of opt...
subroutine read_energies(filename, energies, variances, accept_rates)
Reads restart files with energies, variances and acceptence arrays.
subroutine read_energies_h2(filename, energies, variances, accept_rates, a_array, b_array)
Reads restart files with energies, variances and acceptence arrays. Also reads two extra arrays of op...
Contains derived types, and global variables to store input values of simulation parameters.
integer(int64) seed
Seed for the random number generator.
integer(int32) run_steps
Number of MMC steps after burning (for MPI worksharing)
type(h2_type) h2
To store inputs for H2 molecule system.
type(h2plus_type) h2plus
To store inputs for H2 ion system.
character(len= *), parameter outfile
Default NetCDF output file name.
logical run_restart
Tag for restart runs.
type(restart_type) res
Instance of restart_type for reading restart files.
integer(int32) tstep
Interval of steps for thinning in non-equil runs (for MPI worksharing)
integer(int32) auto_start
Start value for automatic search of parameter c, can be >1 for restarts.
logical write_chains
Tag to write final MMC chains.
integer(int32) ip
Processor rank for MPI communications.
integer(int32) i_bond
Index of bondlength grid value, for restart writing.
real(real64) per_step
Reused multiplicative factor, representing division by total number of MMC steps (tot_size)
real(real64) per_proc2
Reused multiplicative factor, representing division by square of number of processors (p^2)
type(qho_type) qho
To store inputs for QHO system.
real(real64) per_proc
Reused multiplicative factor, representing division by number of processors (p)
logical i_log
Indicates whether the processor needs to write the logfile.
integer(int32) tag_seed
Unique tag for communicating rank seeds.
character(len= *), parameter resfile_etot
Name of restart file storing total energies.
logical run_equil
Tag for equilibration runs.
integer, dimension(mpi_status_size) status
Status of MPI Recv commands.
integer(int32) grid_start
Start value for grid search of parameter c, can be >1 for restarts.
integer(int32) my_size
Length of chain on a processor, after burning & thinning.
integer(int32) p
Number of processors.
integer(int32) bond_start
Start value for bondlength grid, can be >1 for restarts.
character(len=10) p_system
System of interest: QHO, H2plus, H2.
logical write_log
Tag to write logfile.
character(len= *), parameter logfile
Default log name (if write_log is True)
integer max_chain_len
Maximum length of energy chains for writing to netCDF files.
integer(int32) tot_size
Total length of chains across processors, after burning and thinning.
logical write_restart
Tag for writing restart files.
integer(int32) my_steps
Number of steps per processor.
integer(int64) ip_seed
Processor seed for MPI communications.
integer(int32) my_rank
Rank of current processor.
integer(int32) mpierr
MPI error flag.
integer logid
To store logfile unit.
Contains local energy and transition probability solvers for available problems.
real(real64) function h_2_cusp(s)
Calculates a value for a given the bond length s by Newton-Raphson iteration.
Contains unit tests for all major functions in the program.
subroutine unit_tests()
Runs all of the unit tests, reporting successes and failures.
Contains routines for handline random number generation, the main VQMC algorithms and routines for de...
subroutine grid_h_2(a, beta_array, bond_length, beta_out, energy_out, variance_out, accept_out)
Performs a grid search to find the optimal value for the variational parameter in the problem.
subroutine auto_h_2_plus(c_in, bond_length, c_out, energy_out, variance_out, accept_out, converged)
Automatically finds the best variational parameter for the problem at given bond length.
subroutine equil_h_2_plus(c_array, bond_length, bonds_pos)
Performs VQMC on an array of values for the variational parameter , outputting energy traces for each...
subroutine equil_qho(alpha_array)
Performs VQMC on an array of values for the variational parameter , outputting energy traces for each...
real(real64) function, dimension(:), allocatable linspace(start, end, num)
Adaptation of numpy's linspace function.
subroutine grid_h_2_plus(c_array, bond_length, c_out, energy_out, variance_out, accept_out)
Performs a grid search to find the optimal value for the variational parameter in the problem.
subroutine auto_h_2(a, beta_in, bond_length, beta_out, energy_out, variance_out, accept_out, converged)
Automatically finds the best variational parameter for the problem at a given bond length.
subroutine grid_qho(alpha_array, energies, acc_rates, variances)
Performs VQMC on an array of values for the variational parameter .
subroutine equil_h_2(a, beta_array, bond_length, bonds_pos)
Performs VQMC on an array of values for the variational parameter , outputting energy traces for each...
subroutine init_ran1()
Initialiser for the random number generator.
Contains NetCDF output functions for different problem main & equilibration runs.
subroutine write_h2plus_main(param_array, bondlength_array, energy_array, uncertainty_array, filename, ierr, H2plus, accept_rate)
Output results of H2plus MCMC run.
subroutine write_h2_main(param_a_array, param_beta_array, bondlength_array, energy_array, uncertainty_array, filename, ierr, H2, accept_rate)
Output results of H2 MCMC run.