def vmc_iterate(tf, num_iters=100): opt = optim.SGD(tf.parameters(), lr=1e-2, momentum=0.9) for i in range(num_iters): results = metropolis_symmetric(tf, normal_proposal, num_walkers=1000, num_steps=5000) energy_minimize_step(tf, results, opt) print(tf.alpha)
def harmonic_energy_alpha_values(): vals = np.arange(0.2, 1.5, 0.1) means = [] for alpha_val in vals: print(alpha_val) tf = HarmonicTrialFunction(alpha_val) samples = metropolis_symmetric(tf, normal_proposal, num_walkers=100, num_steps=20000) means.append(torch.mean(tf.local_energy(samples)).item()) return vals, means
def harmonic_energy_alpha_values(): vals = np.arange(0.2, 1.5, 0.1) means = [] for alpha_val in vals: print(alpha_val) tf = HarmonicTrialFunction(torch.tensor(alpha_val)) init_config = 0.5 * torch.ones(100, 1) samples = metropolis_symmetric(tf, init_config, normal_proposal, num_steps=20000) means.append(torch.mean(tf.local_energy(samples)).item()) return vals, means
def vmc_iterate(tf, init_config, num_iters=100): opt = optim.SGD(tf.parameters(), lr=5e-2, momentum=0.3) # propdist = NormalProposal(0.3) propdist = ClipNormalProposal(0.1) for i in range(num_iters): print(i) results = metropolis_symmetric(tf, init_config, propdist, num_steps=1000) energy_minimize_step(tf, results, opt) print(tf.alpha) print(results)
def hydrogen_energy_alpha_values(): vals = np.arange(0.2, 1.5, 0.1) means = [] for alpha_val in vals: print(alpha_val) tf = HydrogenTrialWavefunction(alpha_val) samples = metropolis_symmetric(tf, clip_normal_proposal, num_walkers=100, num_steps=20000, init_val=0.5) means.append(torch.mean(tf.local_energy(samples)).item()) return vals, means
def hydrogen_energy_alpha_values(): vals = np.arange(0.2, 1.5, 0.1) means = [] propdist = ClipNormalProposal(0.3, min_val=0.0) for alpha_val in vals: print(alpha_val) tf = HydrogenTrialWavefunction(torch.tensor(alpha_val)) init_config = 0.5 * torch.ones(100, 1) samples = metropolis_symmetric(tf, init_config, propdist, num_steps=20000) means.append(torch.mean(tf.local_energy(samples)).item()) return vals, means
def helium_energy_alpha_values(): vals = np.arange(1.2, 2.5, 0.1) means = [] propdist = ClipNormalProposal(0.05, min_val=0.0) for alpha_val in vals: print(alpha_val) tf = HeliumTrialWavefunction(torch.ones(1) * alpha_val) init_config = 0.5 * torch.ones(100, 3) samples = metropolis_symmetric(tf, init_config, propdist, num_steps=20000) means.append(torch.mean(tf.local_energy(samples)).item()) print(means[-1]) return vals, means
# %% import torch import matplotlib.pyplot as plt from qmc.mcmc import metropolis_symmetric, clip_mvnormal_proposal from qmc.wavefunction import HeliumTrialWavefunction # %% d = 3 tf = HeliumTrialWavefunction(torch.ones(1)) # n_walkers = 5 init_config = torch.rand(n_walkers, 3) results = metropolis_symmetric(tf, init_config, clip_mvnormal_proposal, num_walkers=n_walkers, num_steps=10000) # %% #results_numpy = results.view(-1,3).numpy() # %% #plt.scatter(results_numpy[:,0],results_numpy[:,1], s=1) #plt.savefig("box.png") # %% print(torch.mean(tf.local_energy(results)))
a = torch.tensor(Tdat) # a = torch.ones(2) tf = twvan(a) # n_walkers = 10 #init_config = torch.ones(n_walkers,2)*0.5 #results = metropolis_symmetric(tf, init_config, ClipNormalProposal(sigma=0.001, min_val=0.1, max_val=0.45), num_walkers=n_walkers, num_steps=10000) init_config = 0.1 * torch.ones(n_walkers, 2) results = metropolis_symmetric(tf, init_config, ClipNormalProposal(sigma=0.01, min_val=-1, max_val=1), num_walkers=n_walkers, num_steps=10000) #init_config = torch.rand(n_walkers,2) #results = metropolis_symmetric(tf, init_config, ClipNormalProposal(sigma=0.05, num_walkers=n_walkers, num_steps=10000) # %% #results_numpy = results.view(-1,3).numpy() # %% # %% #plt.scatter(results_numpy[:,0],results_numpy[:,1], s=1) #plt.savefig("box.png")samples[:, 1000:, :]