Dice Fortran Backend Documentation
|
Contains routines for handline random number generation, the main VQMC algorithms and routines for determining ideal parameters. More...
Functions/Subroutines | |
subroutine | init_ran1 () |
Initialiser for the random number generator. More... | |
subroutine | ran1 (sample, dseed) |
Implementation of Press et al's random number generator. More... | |
real(real64) function, dimension(:), allocatable | linspace (start, end, num) |
Adaptation of numpy's linspace function. More... | |
subroutine | random_normal (dim, x) |
Draws a sample from a normal distribution using the Box-Muller transform. More... | |
subroutine | vqmc_qho (sigma, N, burn, thin, alpha_const, X_burnt, accept_rate, energy_chain, energy_mean, energy_variance, x_start) |
Performs VQMC for the QHO system. More... | |
subroutine | grid_qho (alpha_array, energies, acc_rates, variances) |
Performs VQMC on an array of values for the variational parameter \( \alpha \). More... | |
subroutine | equil_qho (alpha_array) |
Performs VQMC on an array of values for the variational parameter \( \alpha \), outputting energy traces for each. More... | |
subroutine | vqmc_h_2_plus (sigma, N, burn, thin, c_const, R_a, R_b, X_burnt, accept_rate, energy_chain, energy_mean, energy_variance, DphiDc_chain, x_start) |
Performs VQMC for the \( H_{2}^{+} \) system. More... | |
subroutine | auto_h_2_plus (c_in, bond_length, c_out, energy_out, variance_out, accept_out, converged) |
Automatically finds the best variational parameter \( c \) for the \( H_{2}^{+} \) problem at given bond length. More... | |
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 \( c \) in the \( H_{2}^{+} \) problem. More... | |
subroutine | equil_h_2_plus (c_array, bond_length, bonds_pos) |
Performs VQMC on an array of values for the variational parameter \( c \), outputting energy traces for each. More... | |
subroutine | vqmc_h_2 (sigma, N, burn, thin, a, beta, R_a, R_b, X_1_burnt, X_2_burnt, accept_rate, energy_chain, energy_mean, energy_variance, DphiDbeta_chain, x_start_1, x_start_2) |
Performs VQMC for the \( H_{2}^{+} \) system. More... | |
subroutine | auto_h_2 (a, beta_in, bond_length, beta_out, energy_out, variance_out, accept_out, converged) |
Automatically finds the best variational parameter \( \beta \) for the \( H_{2}^{+} \) problem at a given bond length. More... | |
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 \( \beta \) in the \( H_{2} \) problem. More... | |
subroutine | equil_h_2 (a, beta_array, bond_length, bonds_pos) |
Performs VQMC on an array of values for the variational parameter \( \beta \), outputting energy traces for each. More... | |
Variables | |
integer, parameter | ntab = 32 |
Variable controlling the RNG sequence. More... | |
integer(int64), dimension(ntab), save | iv = 0 |
Variable controlling the RNG sequence. More... | |
integer(int64), save | iy = 0 |
Variable controlling the RNG sequence. More... | |
integer | logfrac = 10 |
1/logfrac is the fraction of samples to report in the log, if shared_data::write_log is TRUE. More... | |
Contains routines for handline random number generation, the main VQMC algorithms and routines for determining ideal parameters.
This module contains the VQMC solvers for the quantum harmonic oscillator (QHO), hydrogen ion (H_2_plus) and hydrogen molecule (H_2) problems. It also has the subroutine random normal which generates a sample from a normal distribution using the Box-Muller transfrom, which is needed for the Metropolis algorithm used in VQMC. This uses a random number generator which is initially seeded by environmental noise through /dev/urandom, and then propagated by an algorithm from Numerical Recipes by Press et al. (2007)
The VQMC algorithms use the solvers module to obtain the transition probabilities needed for the Metropolis algorithm and to calculate the local energies given the position of the random walker(s).
The module also contains routines for running these VQMC algorithms across a range of parameters. The Grid routines are used to do a search for the best variational parameter on a user-defined grid, while the Auto routines utilise the gradients calculated by the local energy routines to automatically determine the best variational parameter from a suitable guess. Equil routines are also included to run VQMC over a parameter grid, but to output the position and energy traces from VQMC rather than a total energy. These traces can then be used to determine optimal burning/thinning parameters for the Markov chains, using tools in the Python frontend.
subroutine vqmc::init_ran1 |
Initialiser for the random number generator.
Initialises the random number generator by drawing a seed from the environmental noise in /dev/urandom. Cuts down this seed to a smaller integer to prevent overflows in ran1 when the seed is converted to a double-precision float.
Definition at line 68 of file vqmc.f90.
subroutine vqmc::ran1 | ( | real(real64), intent(out) | sample, |
integer(int64), intent(inout) | dseed | ||
) |
Implementation of Press et al's random number generator.
Update to David Quigley's implementation of Press et al's random number generator (originally from Numerical Methods ), as seem in PX425 Assignment 3, to be Fortran 2008 compliant.
[in,out] | dseed | Current value of seed. Must be a negative integer on first call of this routine. |
[out] | sample | Uniform random number. |
Definition at line 118 of file vqmc.f90.
real(real64) function, dimension(:), allocatable vqmc::linspace | ( | real(real64), intent(in) | start, |
real(real64), intent(in) | end, | ||
real(real64), intent(in) | num | ||
) |
Adaptation of numpy's linspace function.
Uses a REAL value for num for compatability with parameter arrays, then converts to int internally. Returns a length 1 array just containing the start value if num is equal to 1.
[in] | start | Starting value of the sequence |
[in] | end | End value of the sequence |
[in] | num | Number of samples to generate between start and end value |
ls_array | An array with evenly specified numbers over an interval |
Definition at line 182 of file vqmc.f90.
subroutine vqmc::random_normal | ( | integer, intent(in) | dim, |
real(real64), dimension(:), intent(out) | x | ||
) |
Draws a sample from a normal distribution using the Box-Muller transform.
Uses the uniform random number generator ran1 to generate an array of normally distributed numbers, by means of the Box-Muller transform.
[in] | dim | The dimension of the random vector to be generated. |
[out] | x | The vector sample from the normal distribution. |
Definition at line 228 of file vqmc.f90.
subroutine vqmc::vqmc_qho | ( | real(real64), intent(in) | sigma, |
integer, intent(in) | N, | ||
integer, intent(in) | burn, | ||
integer, intent(in) | thin, | ||
real(real64), intent(in) | alpha_const, | ||
real(real64), dimension(:), intent(out), allocatable | X_burnt, | ||
real(real64), intent(out) | accept_rate, | ||
real(real64), dimension(:), intent(out), allocatable | energy_chain, | ||
real(real64), intent(out) | energy_mean, | ||
real(real64), intent(out) | energy_variance, | ||
real(real64), optional | x_start | ||
) |
Performs VQMC for the QHO system.
Computes the total energy of a trial wavefunction by averaging over a Markov chain of local energies generated by QHO_Energy, with random move acceptance/rejection probability determined by QHO_Prob.
Allows for modification of total Markov chain length, as well as the number of steps to be 'burned' while the chain is equilibrating and the interval to 'thin' the chain over to reduce correlation of samples. The size of the proposed random moves can be controlled by modifying the sigma parameter to get an ideal move acceptance rate.
[in] | sigma | Step size |
[in] | N | Number of steps to take |
[in] | burn | Number of sample to discard at the beginning |
[in] | thin | The frequency at which we discard the samples from the MCMC chain after burning |
[in] | alpha_const | Parameter |
[in] | x_start | Starting point of MCMC chain (optional, default is randomly generated) |
[out] | X_burnt | The burnt and thinned MCMC chain for the random walker |
[out] | accept_rate | The acceptance rate of the MCMC chain |
[out] | energy_chain | An array with the local energies of the each points in the MCMC chain |
[out] | energy_mean | The average of the local energies recorded in energy_chain |
[out] | energy_variance | The variance of the local energies recorded in energy_chain |
Definition at line 289 of file vqmc.f90.
subroutine vqmc::grid_qho | ( | real(real64), dimension(:), intent(in) | alpha_array, |
real(real64), dimension(:), intent(inout) | energies, | ||
real(real64), dimension(:), intent(inout) | acc_rates, | ||
real(real64), dimension(:), intent(inout) | variances | ||
) |
Performs VQMC on an array of values for the variational parameter \( \alpha \).
Evaluates energy of the QHO trial wavefunction at each value of the parameter \( \alpha \) in alpha_array. Also evaluates variances in these energies as a measure of uncertainty. Writes these results to a NetCDF file.
[in] | alpha_array | The array of alpha values to obtain energies for |
[in,out] | energies | Array of size(alpha_array) to contain total energies |
[in,out] | acc_rates | Array of size(alpha_array) to contain acceptance rates |
[in,out] | variances | Array of size(alpha_array) to contain variances |
Definition at line 579 of file vqmc.f90.
subroutine vqmc::equil_qho | ( | real(real64), dimension(:), intent(in) | alpha_array | ) |
Performs VQMC on an array of values for the variational parameter \( \alpha \), outputting energy traces for each.
Generates VQMC position and energy traces of the QHO trial wavefunction at each value of the parameter \( \alpha \) in alpha_array. Outputs each of these traces to a separate NetCDF file, to be used in determining optimal burning/thinning paramters for an accurate full VQMC run.
[in] | alpha_array | The array of alpha values to obtain energies for |
[in,out] | energies | The energies |
Definition at line 742 of file vqmc.f90.
subroutine vqmc::vqmc_h_2_plus | ( | real(real64), intent(in) | sigma, |
integer, intent(in) | N, | ||
integer, intent(in) | burn, | ||
integer, intent(in) | thin, | ||
real(real64), intent(in) | c_const, | ||
real(real64), dimension(3), intent(in) | R_a, | ||
real(real64), dimension(3), intent(in) | R_b, | ||
real(real64), dimension(:, :), intent(out), allocatable | X_burnt, | ||
real(real64), intent(out) | accept_rate, | ||
real(real64), dimension(:), intent(out), allocatable | energy_chain, | ||
real(real64), intent(out) | energy_mean, | ||
real(real64), intent(out) | energy_variance, | ||
real(real64), dimension(:), intent(out), allocatable | DphiDc_chain, | ||
real(real64), dimension(3), optional | x_start | ||
) |
Performs VQMC for the \( H_{2}^{+} \) system.
Computes the total energy of a trial wavefunction by averaging over a Markov chain of local energies generated by H_2_plus_Energy, with random move acceptance/rejection probability determined by H_2_plus_Prob. The H-H bond length can be changed by modifying the hydrogen atom positions R_a and R_b. Also outputs the gradient with respect to the variational parameter \( c \) at each step in the chain, to be used in Auto_H_2_plus.
Allows for modification of total Markov chain length, as well as the number of steps to be 'burned' while the chain is equilibrating and the interval to 'thin' the chain over to reduce correlation of samples. The size of the proposed random moves can be controlled by modifying the sigma parameter to get an ideal move acceptance rate.
[in] | sigma | Step size |
[in] | N | Number of steps to take |
[in] | burn | Number of sample to discard at the beginning |
[in] | thin | The frequency at which we discard the samples from the MCMC chain after burning |
[in] | c_const | Parameter(s) of trial wavefunction |
[in] | R_a | Position of hydrogen atom A |
[in] | R_b | Position of hydrogen atom B |
[in] | x_start | Starting point of MCMC chain (optional, default is randomly generated) |
[out] | X_burnt | The burnt and thinned MCMC chain for the random walker |
[out] | accept_rate | The acceptance rate of the MCMC chain |
[out] | energy_chain | An array with the local energies of the each points in the MCMC chain |
[out] | energy_mean | The average of the local energies recorded in energy_chain |
[out] | energy_variance | The variance of the local energies recorded in energy_chain |
[out] | DphiDc_chain | Array of the gradients with respect to \( c \) at each point in the MCMC chain |
Definition at line 857 of file vqmc.f90.
subroutine vqmc::auto_h_2_plus | ( | real(real64), intent(in) | c_in, |
real(real64), intent(in) | bond_length, | ||
real(real64), intent(out) | c_out, | ||
real(real64), intent(out) | energy_out, | ||
real(real64), intent(out) | variance_out, | ||
real(real64), intent(out) | accept_out, | ||
character(len=1), intent(out) | converged | ||
) |
Automatically finds the best variational parameter \( c \) for the \( H_{2}^{+} \) problem at given bond length.
Determines the optimum value of \( c \) at a given bond length from a guess value by utilising the gradient with respect to \( c \) (calculated by first order central difference) in a dampened steepest descent optimisation.
[in] | c_in | Guess value for c |
[in] | bond_length | H-H bond length |
[out] | c_out | Optimised value for c at this bond length |
[out] | energy_out | Energy of wavefunction at optimal c |
[out] | variance_out | Variance of energy at optimal c |
[out] | accept_out | Acceptance rate of MCMC chain at optimal c |
[out] | converged | Y/N convergence status |
Definition at line 1188 of file vqmc.f90.
subroutine vqmc::grid_h_2_plus | ( | real(real64), dimension(:), intent(in) | c_array, |
real(real64), intent(in) | bond_length, | ||
real(real64), intent(out) | c_out, | ||
real(real64), intent(out) | energy_out, | ||
real(real64), intent(out) | variance_out, | ||
real(real64), intent(out) | accept_out | ||
) |
Performs a grid search to find the optimal value for the variational parameter \( c \) in the \( H_{2}^{+} \) problem.
Evaluates energy of the \( H_{2}^{+} \) trial wavefunction at each value of the parameter \( c \) in c_array. Determines the best energy, and reports its corresponding \( c \) as the optimal value at this bond length. Also returns the variance of this energy as a measure of uncertainty, as well as the acceptance rate of the MCMC chain.
[in] | c_array | Array of c values to be tested |
[in] | bond_length | H-H bond length |
[out] | c_out | Optimised value for c at this bond length |
[out] | energy_out | Energy of wavefunction at optimal c |
[out] | variance_out | Variance of energy at optimal c |
[out] | accept_out | Acceptance rate of MCMC chain at optimal c |
Definition at line 1359 of file vqmc.f90.
subroutine vqmc::equil_h_2_plus | ( | real(real64), dimension(:), intent(in) | c_array, |
real(real64), intent(in) | bond_length, | ||
integer, intent(in) | bonds_pos | ||
) |
Performs VQMC on an array of values for the variational parameter \( c \), outputting energy traces for each.
Generates VQMC position and energy traces of the \( H_{2}^{+} \) trial wavefunction at each value of the parameter \( c \) in c_array. Outputs each of these traces to a separate NetCDF file, to be used in determining optimal burning/thinning paramters for an accurate full VQMC run.
[in] | c_array | The array of c values to obtain energy traces for |
[in] | bond_length | The current H-H bond length |
[in] | bonds_pos | The position in the array of bond lengths, to be used in designating output files |
Definition at line 1505 of file vqmc.f90.
subroutine vqmc::vqmc_h_2 | ( | real(real64), intent(in) | sigma, |
integer, intent(in) | N, | ||
integer, intent(in) | burn, | ||
integer, intent(in) | thin, | ||
real(real64), intent(in) | a, | ||
real(real64), intent(in) | beta, | ||
real(real64), dimension(3), intent(in) | R_a, | ||
real(real64), dimension(3), intent(in) | R_b, | ||
real(real64), dimension(:, :), intent(out), allocatable | X_1_burnt, | ||
real(real64), dimension(:, :), intent(out), allocatable | X_2_burnt, | ||
real(real64), intent(out) | accept_rate, | ||
real(real64), dimension(:), intent(out), allocatable | energy_chain, | ||
real(real64), intent(out) | energy_mean, | ||
real(real64), intent(out) | energy_variance, | ||
real(real64), dimension(:), intent(out), allocatable | DphiDbeta_chain, | ||
real(real64), dimension(3), optional | x_start_1, | ||
real(real64), dimension(3), optional | x_start_2 | ||
) |
Performs VQMC for the \( H_{2}^{+} \) system.
Computes the total energy of a trial wavefunction by averaging over a Markov chain of local energies generated by H_2_Energy, with random move acceptance/rejection probability determined by H_2_Prob. The H-H bond length can be changed by modifying the hydrogen atom positions R_a and R_b. Also outputs the gradient with respect to the variational parameter \( \beta \) at each step in the chain, to be used in Auto_H_2.
Allows for modification of total Markov chain length, as well as the number of steps to be 'burned' while the chain is equilibrating and the interval to 'thin' the chain over to reduce correlation of samples. The size of the proposed random moves can be controlled by modifying the sigma parameter to get an ideal move acceptance rate.
[in] | sigma | Step size |
[in] | N | Number of steps to take |
[in] | burn | Number of sample to discard at the beginning |
[in] | thin | The frequency at which we discard the samples from the MCMC chain after burning |
[in] | a | Parameter a of trial wavefunction |
[in] | beta | Parameter beta of trial wavefunction |
[in] | R_a | Position of hydrogen atom A |
[in] | R_b | Position of hydrogen atom B |
[in] | x_start_1 | Starting point of 1st MCMC chain (optional, default is randomly generated) |
[in] | x_start_2 | Starting point of 2nd MCMC chain (optional, default is randomly generated) |
[out] | X_1_burnt | The burnt and thinned MCMC chain for random walker 1 |
[out] | X_2_burnt | The burnt and thinned MCMC chain for random walker 2 |
[out] | accept_rate | The acceptance rate of the MCMC chain |
[out] | energy_chain | An array with the local energies of the each points in the MCMC chains |
[out] | energy_mean | The average of the local energies recorded in energy_chain |
[out] | energy_variance | The variance of the local energies recorded in energy_chain |
[out] | DphiDbeta_chain | Array of the gradients with respect to \( \beta \) at each point in the MCMC chain |
Definition at line 1617 of file vqmc.f90.
subroutine vqmc::auto_h_2 | ( | real(real64), intent(in) | a, |
real(real64), intent(in) | beta_in, | ||
real(real64), intent(in) | bond_length, | ||
real(real64), intent(out) | beta_out, | ||
real(real64), intent(out) | energy_out, | ||
real(real64), intent(out) | variance_out, | ||
real(real64), intent(out) | accept_out, | ||
character(len=1), intent(out) | converged | ||
) |
Automatically finds the best variational parameter \( \beta \) for the \( H_{2}^{+} \) problem at a given bond length.
Determines the optimum value of \( \beta \) at a given bond length from a guess value by utilising the gradient with respect to \( \beta \) (calculated by first order central difference) in a dampened steepest descent optimisation.
[in] | a | Value of parameter a at current bond length, calculated by H_2_cusp |
[in] | beta_in | Guess value for beta |
[in] | bond_length | H-H bond length |
[out] | beta_out | Optimised value for beta at this bond length |
[out] | energy_out | Energy of wavefunction at optimal beta |
[out] | variance_out | Variance of energy at optimal beta |
[out] | accept_out | Acceptance rate of MCMC chain at optimal beta |
[out] | converged | Y/N convergence status |
Definition at line 1980 of file vqmc.f90.
subroutine vqmc::grid_h_2 | ( | real(real64), intent(in) | a, |
real(real64), dimension(:), intent(in) | beta_array, | ||
real(real64), intent(in) | bond_length, | ||
real(real64), intent(out) | beta_out, | ||
real(real64), intent(out) | energy_out, | ||
real(real64), intent(out) | variance_out, | ||
real(real64), intent(out) | accept_out | ||
) |
Performs a grid search to find the optimal value for the variational parameter \( \beta \) in the \( H_{2} \) problem.
Evaluates energy of the \( H_{2} \) trial wavefunction at each value of the parameter \( \beta \) in beta_array. Determines the best energy, and reports its corresponding \( \beta \) as the optimal value at this bond length. Also returns the variance of this energy as a measure of uncertainty, as well as the acceptance rate of the MCMC chain.
[in] | a | Value of parameter a at current bond length, calculated by H_2_cusp |
[in] | beta_array | Array of beta values to be tested |
[in] | bond_length | H-H bond length |
[out] | beta_out | Optimised value for beta at this bond length |
[out] | energy_out | Energy of wavefunction at optimal beta |
[out] | variance_out | Variance of energy at optimal beta |
[out] | accept_out | Acceptance rate of MCMC chain at optimal beta |
Definition at line 2153 of file vqmc.f90.
subroutine vqmc::equil_h_2 | ( | real(real64), intent(in) | a, |
real(real64), dimension(:), intent(in) | beta_array, | ||
real(real64), intent(in) | bond_length, | ||
integer, intent(in) | bonds_pos | ||
) |
Performs VQMC on an array of values for the variational parameter \( \beta \), outputting energy traces for each.
Generates VQMC position and energy traces of the \( H_{2} \) trial wavefunction at each value of the parameter \( \beta \) in beta_array. Outputs each of these traces to a separate NetCDF file, to be used in determining optimal burning/thinning paramters for an accurate full VQMC run.
[in] | a | Value of parameter a at current bond length, calculated by H_2_cusp |
[in] | beta_array | The array of beta values to obtain energy traces for |
[in] | bond_length | The current H-H bond length |
[in] | bonds_pos | The position in the array of bond lengths, to be used in designating output files |
Definition at line 2299 of file vqmc.f90.
integer, parameter vqmc::ntab = 32 |
integer(int64), dimension(ntab), save vqmc::iv = 0 |
integer(int64), save vqmc::iy = 0 |
integer vqmc::logfrac = 10 |
1/logfrac is the fraction of samples to report in the log, if shared_data::write_log is TRUE.