Beispiel #1
0
    _, (eax, pax) = plt.subplots(ncols=2)
    eax.plot(energies, label=r"$\langle E_L\rangle$ [a.u]")
    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,
Beispiel #2
0
    pax.set_xlabel(r"% of training")

    matplotlib2tikz.save(__file__ + ".tex")

    _, 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)
Beispiel #3
0
    JastrowPade,
    SimpleGaussian,
    WavefunctionProduct,
    Dnn,
    InputSorter,
)
from qflow.wavefunctions.nn.layers import DenseLayer
from qflow.wavefunctions.nn.activations import tanh, exponential
from qflow.hamiltonians import CoulombHarmonicOscillator
from qflow.samplers import ImportanceSampler
from qflow.statistics import compute_statistics_for_series, statistics_to_tex
from qflow.mpi import mpiprint

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)
Beispiel #4
0
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)$")
Beispiel #5
0
import numpy as np
import matplotlib.pyplot as plt

from qflow.wavefunctions import SimpleGaussian, JastrowPade, WavefunctionProduct
from qflow.hamiltonians import CoulombHarmonicOscillator
from qflow.samplers import ImportanceSampler
from qflow.optimizers import SgdOptimizer
from qflow.training import train, EnergyCallback, ParameterCallback
from qflow.statistics import compute_statistics_for_series
from qflow.mpi import mpiprint, master_rank

P, D = 2, 2  # Particles, dimensions

# Define Hamiltonian:
H = CoulombHarmonicOscillator(omega_ho=1)

# Define trial wave function:
gaussian = SimpleGaussian(alpha=0.8)
jastrow = JastrowPade(alpha=1, beta=1)
psi = WavefunctionProduct(gaussian, jastrow)

# Set up sampling strategy:
sampler = ImportanceSampler(np.empty((P, D)), psi, step_size=0.1)

# Train wave function:
training_energies = EnergyCallback(samples=100000)
training_params = ParameterCallback()
train(
    psi,
    H,
    sampler,
Beispiel #6
0
    _, (sax, wax) = plt.subplots(ncols=2)
    sax.semilogx(symmetries, label=r"$S(\psi_{RBM})$")
    sax.set_ylabel("Symmetry")
    sax.set_xlabel(r"% of training")
    sax.legend(loc="lower right")

    w = np.asarray(parameters[-1])[P * D + N:].reshape(P * D, N)
    wax.matshow(w)
    wax.set_xlabel(r"$\mathbf{W}$")

    matplotlib2tikz.save(__file__ + ".symmetry.tex")


P, D, N = 2, 2, 4  # Particles, dimensions, hidden nodes.
system = np.empty((P, D))
H = CoulombHarmonicOscillator()
psi = RBMWavefunction(P * D, N)
psi_sorted = InputSorter(psi)
psi_sampler = ImportanceSampler(system, psi, step_size=0.1)
psi_sorted_sampler = ImportanceSampler(system, psi_sorted, step_size=0.1)

psi_energies = EnergyCallback(samples=1_000_000, verbose=True)
psi_symmetries = SymmetryCallback(samples=1_000_000)
psi_parameters = ParameterCallback()

train(
    psi,
    H,
    psi_sampler,
    iters=40000,
    samples=1000,
Beispiel #7
0
    FixedWavefunction,
    JastrowOrion,
    SimpleGaussian,
    SumPooling,
    WavefunctionProduct,
)
from qflow.wavefunctions.nn.activations import (
    exponential,
    identity,
    relu,
    sigmoid,
    tanh,
)
from qflow.wavefunctions.nn.layers import DenseLayer

H1 = CoulombHarmonicOscillator()
P, D = 8, 3  # Particles, dimensions
N = 4  # Hidden nodes
system = np.empty((P, D))

simple_gaussian = SimpleGaussian(alpha=0.5)
jastrow = JastrowOrion(beta=2, gamma=1.5)
layers = [
    DenseLayer(2 * D, 32, activation=tanh, scale_factor=0.001),
    DenseLayer(32, 1, activation=exponential),
]
dnn = Dnn()
for l in layers:
    dnn.add_layer(l)

simple_and_jastrow = WavefunctionProduct(simple_gaussian, jastrow)