def test_drift_force(X, beta): with warnings.catch_warnings(): warnings.simplefilter("ignore") np_drift = 2 * grad(jastrow_np, 0)(X, 0.5, beta) / jastrow_np(X, 0.5, beta) psi = JastrowPade(0.5, beta) for expect, actual in zip(np_drift.ravel(), psi.drift_force(X)): if math.isfinite(expect): assert np.isclose(expect, actual)
def test_laplace(X, beta): with warnings.catch_warnings(): warnings.simplefilter("ignore") np_expect = np.trace( hessian(jastrow_np)(X, 0.5, beta).reshape(X.size, X.size) ) / jastrow_np(X, 0.5, beta) psi = JastrowPade(0.5, beta) if math.isfinite(np_expect): assert numpy.isclose(np_expect, psi.laplacian(X))
def test_gradient(X, beta): with warnings.catch_warnings(): warnings.simplefilter("ignore") np_grad_beta = grad(jastrow_np, 2)(X, 0.5, beta) / jastrow_np(X, 0.5, beta) psi = JastrowPade(0.5, beta) actual = psi.gradient(X) assert 1 == len(actual) if math.isfinite(np_grad_beta): assert np.isclose(np_grad_beta, actual[0])
def test_gradient(X, alpha, beta): with warnings.catch_warnings(): warnings.simplefilter("ignore") np_grad_alpha = grad(jastrow_np, 1)(X, alpha, beta) / jastrow_np( X, alpha, beta) np_grad_beta = grad(jastrow_np, 2)(X, alpha, beta) / jastrow_np( X, alpha, beta) psi_alpha_const = JastrowPade(alpha, beta) psi = JastrowPade(alpha, beta, False) actual = psi.gradient(X) assert 2 == len(actual) assert psi_alpha_const.gradient(X)[0] == 0 if math.isfinite(np_grad_beta): assert np.isclose(np_grad_alpha, actual[0]) assert np.isclose(np_grad_beta, actual[1])
_, sax = plt.subplots() sax.semilogx(symmetries, label=r"$S(\psi_{DNN})$") sax.set_ylabel("Symmetry") sax.set_xlabel(r"% of training") sax.legend(loc="lower right") matplotlib2tikz.save(__file__ + ".symmetry.tex") P, D = 2, 2 # Particles, dimensions system = np.empty((P, D)) H = CoulombHarmonicOscillator() # Wave functions: simple_gaussian = SimpleGaussian(alpha=0.5) jastrow = JastrowPade(alpha=1, beta=1) simple_and_jastrow = WavefunctionProduct(simple_gaussian, jastrow) layers = [ DenseLayer(P * D, 32, activation=tanh, scale_factor=0.001), DenseLayer(32, 16, activation=tanh), DenseLayer(16, 1, activation=exponential), ] dnn = Dnn() for l in layers: dnn.add_layer(l) psi = WavefunctionProduct(simple_and_jastrow, dnn) psi_sampler = ImportanceSampler(system, psi, step_size=0.1) # Sorted simple_gaussian2 = SimpleGaussian(alpha=0.5)
eax.set_xlabel(r"% of training") eax.axhline(y=3, label="Exact", linestyle="--", color="k", alpha=0.5) eax.legend() pax.plot(np.asarray(parameters)[:, [0, 3]]) pax.set_xlabel(r"% of training") pax.legend([r"$\alpha_G$", r"$\beta_{PJ}$"]) matplotlib2tikz.save(__file__ + ".tex") P, D = 2, 2 # Particles, dimensions system = np.empty((P, D)) H = CoulombHarmonicOscillator() simple_gaussian = SimpleGaussian(alpha=0.5) jastrow = JastrowPade(alpha=1, beta=1) psi = WavefunctionProduct(simple_gaussian, jastrow) psi_sampler = ImportanceSampler(system, psi, step_size=0.1) psi_simple_sampler = ImportanceSampler(system, simple_gaussian, step_size=0.1) psi_energies = EnergyCallback(samples=100000) psi_parameters = ParameterCallback() train( psi, H, psi_sampler, iters=2000, samples=1000, gamma=0, optimizer=AdamOptimizer(len(psi.parameters)),
def test_eval(X, beta): psi = JastrowPade(0.5, beta) with warnings.catch_warnings(): warnings.simplefilter("ignore") assert np.isclose(jastrow_np(X, 0.5, beta), psi(X))
import numpy as np import matplotlib.pyplot as plt import matplotlib2tikz from qflow.wavefunctions import JastrowPade, SimpleGaussian, WavefunctionProduct from qflow.hamiltonians import CoulombHarmonicOscillator from qflow.samplers import ImportanceSampler from qflow.mpi import master_rank P, D = 2, 2 # Particles, dimensions system = np.empty((P, D)) H = CoulombHarmonicOscillator() simple_gaussian = SimpleGaussian(alpha=0.4950) jastrow = JastrowPade(alpha=1, beta=0.3978) psi = WavefunctionProduct(simple_gaussian, jastrow) sampler = ImportanceSampler(system, psi, step_size=0.1) sampler.thermalize(10000) samples = 2**27 n_bins = 100 max_r = 3.0 r = np.linspace(0, max_r, n_bins) bins = H.onebodydensity(sampler, n_bins, max_r, samples) rho = bins / np.trapz(bins, x=r) exact_ideal = np.exp(-r**2) exact_ideal /= np.trapz(exact_ideal, x=r) if master_rank(): print(rho) plt.plot(r, rho, label=r"$\psi_{PJ}$") plt.plot(r, exact_ideal, "--", label=r"$\exp(-r^2)$")