示例#1
0
psi_energies = EnergyCallback(samples=plot_samples, verbose=True)
psi_symmetries = SymmetryCallback(samples=plot_samples)
psi_parameters = ParameterCallback()

train(
    psi,
    H,
    psi_sampler,
    iters=iters,
    samples=samples,
    gamma=gamma,
    optimizer=AdamOptimizer(len(psi.parameters)),
    call_backs=(psi_energies, psi_symmetries, psi_parameters),
)
mpiprint("Training regular dnn complete")

np.savetxt("QD-parameters-dnn-regular.txt", psi.parameters)

psi_sorted_energies = EnergyCallback(samples=plot_samples, verbose=True)
psi_sorted_parameters = ParameterCallback()

train(
    psi_sorted,
    H,
    psi_sorted_sampler,
    iters=iters,
    samples=samples,
    gamma=gamma,
    optimizer=AdamOptimizer(len(psi_sorted.parameters)),
    call_backs=(psi_sorted_energies, psi_sorted_parameters),
示例#2
0
psi_energies = EnergyCallback(samples=100000)
psi_parameters = ParameterCallback()

train(
    psi,
    H,
    psi_sampler,
    iters=2000,
    samples=1000,
    gamma=0,
    optimizer=AdamOptimizer(len(psi.parameters)),
    call_backs=(psi_energies, psi_parameters),
)

mpiprint("Training complete")

stats = [
    compute_statistics_for_series(
        H.local_energy_array(psi_simple_sampler, simple_gaussian, 2**22),
        method="blocking",
    ),
    compute_statistics_for_series(H.local_energy_array(psi_sampler, psi,
                                                       2**22),
                                  method="blocking"),
]
labels = [r"$\Phi$", r"$\psi_{PJ}$"]

mpiprint(stats, pretty=True)
mpiprint(statistics_to_tex(stats, labels, filename=__file__ + ".table.tex"))
mpiprint(psi.parameters)
示例#3
0
    exponential,
    identity,
    relu,
    sigmoid,
    tanh,
)
from qflow.wavefunctions.nn.layers import DenseLayer

os.makedirs("logfiles", exist_ok=True)

rho = 0.365 / (2.556) ** 3  # Å^-3
P, D = 32, 3  # Particles, dimensions
L = (P / rho) ** (1 / 3)
system = np.empty((P, D))

mpiprint(f"P = {P}, D = {D}, rho = {rho}, L = {L}")

H = LennardJones(L)
mcmillian = JastrowMcMillian(5, 2.965, L)
# layers = [
#     DenseLayer(P * D, 144, activation=tanh, scale_factor=0.001),
#     DenseLayer(144, 36, activation=tanh),
#     DenseLayer(36, 1, activation=exponential),
# ]
# dnn = Dnn()
# for l in layers:
#     dnn.add_layer(l)
# mcmillian_fixed = FixedWavefunction(mcmillian)
# psi_total = WavefunctionProduct(mcmillian_fixed, dnn)
# psi = InputSorter(psi_total)
psi = mcmillian
示例#4
0
    pax.legend([r"$\beta$"])

    matplotlib2tikz.save(__file__ + ".tex")


rho = 0.365 / (2.556)**3  # Å^-3
P, D = 32, 3  # Particles, dimensions
L = (P / rho)**(1 / 3)
system = np.empty((P, D))

H = LennardJones(L)
psi = JastrowMcMillian(5, 2.85, L)

sampler = HeliumSampler(system, psi, 0.5, L)
sampler.thermalize(20000)
mpiprint("Acceptance rate after thermalization:", sampler.acceptance_rate)

psi_energies = EnergyCallback(samples=5_000_000, verbose=True)
psi_parameters = ParameterCallback()

train(
    psi,
    H,
    sampler,
    iters=8000,
    samples=5000,
    gamma=0,
    optimizer=AdamOptimizer(len(psi.parameters), 0.0001),
    call_backs=(psi_energies, psi_parameters),
)
示例#5
0
psi_bench_sampler = ImportanceSampler(system, psi_bench, step_size=0.1)

wavefuncs = [psi_bench, psi, psi_sorted]
samplers = [psi_bench_sampler, psi_sampler, psi_sorted_sampler]

for s in samplers:
    s.thermalize(10000)

evaluation_points = 2**24
t0 = time.time()
H.mean_squared_radius_array(psi_sampler, 500)
H.mean_radius_array(psi_sampler, 500)
H.mean_distance_array(psi_sampler, P * 500)
t1 = time.time() - t0
eta = timedelta(seconds=round(t1 / 500 * evaluation_points))
mpiprint(f"Calculating final energy - ETA {eta}")

labels = [
    r"$\psi_{PJ}$", r"$\psi_{DNN}$", r"$\psi_{SDNN}$", r"$\hat{\psi}_{SDNN}$"
]

r2_stats = [
    compute_statistics_for_series(H.mean_squared_radius_array(
        s, evaluation_points),
                                  method="blocking") for s in samplers
]
mpiprint(
    statistics_to_tex(
        r2_stats,
        labels,
        filename=__file__ + ".r2-table.tex",
示例#6
0
psi_nopt = SimpleGaussian(alpha=0.51)
sampler_opt = ImportanceSampler(system, psi_opt, 0.1)
sampler_nopt = ImportanceSampler(system, psi_nopt, 0.1)

sampler_opt.thermalize(10000)
sampler_nopt.thermalize(10000)

samples = 2**23

stats = [
    compute_statistics_for_series(
        H.local_energy_array(sampler_opt, psi_opt, 100) / N),
    compute_statistics_for_series(
        H.local_energy_array(sampler_nopt, psi_nopt, samples) / N,
        method="blocking"),
]

labels = [r"$\alpha_G = 0.5$", r"$\alpha_G=0.51$"]

mpiprint(statistics_to_tex(stats, labels, filename=__file__ + ".table1.tex"))

stats = [
    compute_statistics_for_series(H.mean_radius_array(sampler_opt, samples)),
    compute_statistics_for_series(
        H.mean_squared_radius_array(sampler_opt, samples)),
]

labels = [r"$<r>$", r"$<r^2>$"]

mpiprint(statistics_to_tex(stats, labels, filename=__file__ + ".table2.tex"))
示例#7
0
    eax.legend()

    pax.plot(np.asarray(parameters)[:, 1:50])
    pax.set_xlabel(r"% of training")

    matplotlib2tikz.save(__file__ + ".tex")


os.makedirs("logfiles", exist_ok=True)

rho = 0.365 / (2.556)**3  # Å^-3
P, D = 32, 3  # Particles, dimensions
L = (P / rho)**(1 / 3)
system = np.empty((P, D))

mpiprint(f"P = {P}, D = {D}, rho = {rho}, L = {L}")

H = LennardJones(L)
layers = [
    DenseLayer(P * D, 144, activation=tanh, scale_factor=0.001),
    DenseLayer(144, 36, activation=tanh),
    DenseLayer(36, 1, activation=exponential),
]
dnn = Dnn()
for l in layers:
    dnn.add_layer(l)
mcmillian = JastrowMcMillian(5, 2.85, L)
psi_total = WavefunctionProduct(mcmillian, dnn)
psi = psi_total
sampler = HeliumSampler(system, psi, 0.5, L)
sampler.thermalize(10000)
示例#8
0
training_energies = EnergyCallback(samples=100000)
training_params = ParameterCallback()
train(
    psi,
    H,
    sampler,
    iters=150,     # Optimization steps.
    samples=1000,  # MC cycles per optimization step.
    gamma=0,       # Regularization parameter (disabled here).
    optimizer=SgdOptimizer(0.1),
    call_backs=(training_energies, training_params),
)

# With a trained model, time to evaluate!
energy = H.local_energy_array(sampler, psi, 2 ** 21)
stats = compute_statistics_for_series(energy, method="blocking")
mpiprint(stats, pretty=True)


if master_rank():
    fig, (eax, pax) = plt.subplots(ncols=2, sharex=True)
    eax.plot(training_energies)
    eax.set_title(r"$\langle E_L\rangle$ [a.u]")
    pax.plot(training_params)
    pax.set_title("Parameters")
    pax.legend(["Gaussian alpha", "Jastrow Alpha", "Jastrow Beta"])
    import matplotlib2tikz

    matplotlib2tikz.save(__file__ + "_.tex")
    plt.show()
示例#9
0
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,
    gamma=0.001,
    optimizer=AdamOptimizer(len(psi.parameters), 0.005),
    call_backs=(psi_energies, psi_symmetries, psi_parameters),
)

mpiprint("Training complete")

psi_sorted_sampler.thermalize(100_000)
mpiprint(
    f"Sorted sampler acceptance rate: {psi_sorted_sampler.acceptance_rate}")

stats = [
    compute_statistics_for_series(H.local_energy_array(psi_sampler, psi,
                                                       2**23),
                                  method="blocking"),
    compute_statistics_for_series(H.local_energy_array(psi_sorted_sampler,
                                                       psi_sorted, 2**23),
                                  method="blocking"),
]
labels = [r"$\psi_{RBM}$", r"$\psi_{SRBM}$"]
示例#10
0
)
from qflow.wavefunctions.nn.activations import (
    exponential,
    identity,
    relu,
    sigmoid,
    tanh,
)
from qflow.wavefunctions.nn.layers import DenseLayer

rho = 0.365 / (2.556)**3  # Å^-3
P, D = 4, 3  # Particles, dimensions
L = (P / rho)**(1 / 3)
system = np.empty((P, D))

mpiprint(f"P = {P}, D = {D}, rho = {rho}, L = {L}")

H = LennardJones(L)
mcmillian = JastrowMcMillian(5, 2.952, L)
layers = [
    DenseLayer(2 * D, 16, activation=tanh, scale_factor=0.005),
    DenseLayer(16, 1, activation=exponential),
]
dnn = Dnn()
for l in layers:
    dnn.add_layer(l)
mcmillian_fixed = FixedWavefunction(mcmillian)
psi = WavefunctionProduct(mcmillian_fixed, dnn)
# psi = mcmillian
sampler = HeliumSampler(system, psi, 0.5, L)
sampler.thermalize(5000)