Пример #1
0
def run_tests(wf, epos, epsilon):

    _, epos = pyq.vmc(wf, epos, nblocks=1, nsteps=2, tstep=1)  # move off node

    for k, item in testwf.test_updateinternals(wf, epos).items():
        print(k, item)
        assert item < epsilon

    testwf.test_mask(wf, 0, epos)

    for fname, func in zip(
        ["gradient", "laplacian", "pgradient"],
        [
            testwf.test_wf_gradient,
            testwf.test_wf_laplacian,
            testwf.test_wf_pgradient,
        ],
    ):
        err = [
            func(wf, epos, delta) for delta in [1e-4, 1e-5, 1e-6, 1e-7, 1e-8]
        ]
        assert min(err) < epsilon, "epsilon {0}".format(epsilon)

    for fname, func in zip(
        ["gradient_value", "gradient_laplacian"],
        [
            testwf.test_wf_gradient_value,
            testwf.test_wf_gradient_laplacian,
        ],
    ):
        d = func(wf, epos)
        for k, v in d.items():
            assert v < 1e-10, (k, v)
Пример #2
0
def test_wfs():
    """
    Ensure that the wave function objects are consistent in several situations.
    """

    from pyscf import lib, gto, scf
    from pyqmc.slater import PySCFSlater
    from pyqmc.jastrowspin import JastrowSpin
    from pyqmc.multiplywf import MultiplyWF
    from pyqmc.manybody_jastrow import J3
    import pyqmc

    mol = gto.M(atom="Li 0. 0. 0.; H 0. 0. 1.5", basis="sto-3g", unit="bohr")
    mf = scf.RHF(mol).run()
    mf_rohf = scf.ROHF(mol).run()
    mf_uhf = scf.UHF(mol).run()
    epsilon = 1e-5
    nconf = 10
    epos = pyqmc.initial_guess(mol, nconf)
    for wf in [
            JastrowSpin(mol),
            J3(mol),
            MultiplyWF(PySCFSlater(mol, mf), JastrowSpin(mol)),
            MultiplyWF(PySCFSlater(mol, mf), JastrowSpin(mol), J3(mol)),
            PySCFSlater(mol, mf_uhf),
            PySCFSlater(mol, mf),
            PySCFSlater(mol, mf_rohf),
    ]:
        for k in wf.parameters:
            if k != "mo_coeff":
                wf.parameters[k] = np.random.rand(*wf.parameters[k].shape)
        for k, item in testwf.test_updateinternals(wf, epos).items():
            print(k, item)
            assert item < epsilon

        testwf.test_mask(wf, 0, epos)

        _, epos = pyqmc.vmc(wf, epos, nblocks=1, nsteps=2,
                            tstep=1)  # move off node

        for fname, func in zip(
            ["gradient", "laplacian", "pgradient"],
            [
                testwf.test_wf_gradient,
                testwf.test_wf_laplacian,
                testwf.test_wf_pgradient,
            ],
        ):
            err = []
            for delta in [1e-4, 1e-5, 1e-6, 1e-7, 1e-8]:
                err.append(func(wf, epos, delta)[0])
            print(type(wf), fname, min(err))
            assert min(err) < epsilon, "epsilon {0}".format(epsilon)
Пример #3
0
import numpy as np
from pyscf import lib, gto, scf
import pyqmc
from pyqmc.slateruhf import PySCFSlaterUHF
from pyqmc.jastrowspin import JastrowSpin
# from pyqmc.jastrow import Jastrow2B
from pyqmc.coord import OpenConfigs
import time
from pyqmc.manybody_jastrow import J3
import pyqmc.testwf as test
from pyqmc.wf import WaveFunction
from pyqmc.multiplywf import MultiplyWF
# import pandas as pd

mol = gto.M(atom="Li 0. 0. 0.; Li 0. 0. 1.5", basis="sto-3g", unit="bohr")
mf = scf.UHF(mol).run()
wf1 = PySCFSlaterUHF(mol, mf)
wf2 = JastrowSpin(mol)
# wf3 = J3(mol)
wf = WaveFunction([wf1, wf2])
wfmultiply = MultiplyWF(wf1, wf2)
configs = OpenConfigs(np.random.randn(10, np.sum(mol.nelec), 3))
wf.recompute(configs)
# res = test.test_wf_gradient(wf, configs)
e = 2
epos = configs.electron(e)
test.test_mask(wf, 3, epos)