Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
for k, item in testwf.test_updateinternals(wf, epos).items():
assert item < epsilon
assert testwf.test_wf_gradient(wf, epos, delta=delta)[0] < epsilon
assert testwf.test_wf_laplacian(wf, epos, delta=delta)[0] < epsilon
assert testwf.test_wf_pgradient(wf, epos, delta=delta)[0] < epsilon
# Test different number of elecs
mc = mcscf.CASCI(mf, ncas=4, nelecas=(2, 0))
mc.kernel()
wf = MultiSlater(mol, mf, mc)
nelec = np.sum(mol.nelec)
epos = initial_guess(mol, nconf)
for k, item in testwf.test_updateinternals(wf, epos).items():
assert item < epsilon
assert testwf.test_wf_gradient(wf, epos, delta=delta)[0] < epsilon
assert testwf.test_wf_laplacian(wf, epos, delta=delta)[0] < epsilon
assert testwf.test_wf_pgradient(wf, epos, delta=delta)[0] < epsilon
# Quick VMC test
nconf = 1000
coords = initial_guess(mol, nconf)
df, coords = vmc(
wf, coords, nsteps=nsteps, accumulators={"energy": EnergyAccumulator(mol)}
)
df = pd.DataFrame(df)
df = reblock(df["energytotal"][warmup:], 20)
en = df.mean()
err = df.sem()
wf.parameters[k] = np.random.rand(*wf.parameters[k].shape)
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(fname, min(err))
assert min(err) < epsilon, "epsilon {0}".format(epsilon)
for k, item in testwf.test_updateinternals(wf, epos).items():
print(k, item)
assert item < epsilon
wf.parameters[k] = np.random.rand(*wf.parameters[k].shape)
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(fname, min(err))
assert min(err) < epsilon
for k, item in testwf.test_updateinternals(wf, epos).items():
print(k, item)
assert item < epsilon
for k, item in testwf.test_updateinternals(wf, epos).items():
assert item < epsilon
assert testwf.test_wf_gradient(wf, epos, delta=delta)[0] < epsilon
assert testwf.test_wf_laplacian(wf, epos, delta=delta)[0] < epsilon
assert testwf.test_wf_pgradient(wf, epos, delta=delta)[0] < epsilon
# Test same number of elecs
mc = mcscf.CASCI(mf, ncas=4, nelecas=(1, 1))
mc.kernel()
wf = pyqmc.default_msj(mol, mf, mc)[0]
nelec = np.sum(mol.nelec)
epos = initial_guess(mol, nconf)
for k, item in testwf.test_updateinternals(wf, epos).items():
assert item < epsilon
assert testwf.test_wf_gradient(wf, epos, delta=delta)[0] < epsilon
assert testwf.test_wf_laplacian(wf, epos, delta=delta)[0] < epsilon
assert testwf.test_wf_pgradient(wf, epos, delta=delta)[0] < epsilon
# Test different number of elecs
mc = mcscf.CASCI(mf, ncas=4, nelecas=(2, 0))
mc.kernel()
wf = MultiSlater(mol, mf, mc)
nelec = np.sum(mol.nelec)
epos = initial_guess(mol, nconf)
for k, item in testwf.test_updateinternals(wf, epos).items():
assert item < epsilon
assert testwf.test_wf_gradient(wf, epos, delta=delta)[0] < epsilon
def test():
from pyscf import gto,scf
mol = gto.M(atom='Li 0. 0. 0.; H 0. 0. 1.5', basis='cc-pvtz',unit='bohr')
mf = scf.RHF(mol).run()
nconf=10
nelec=np.sum(mol.nelec)
slater=PySCFSlaterRHF(mol,mf)
configs=np.random.randn(nconf,nelec,3)
import pyqmc.testwf as testwf
for delta in [1e-3,1e-4,1e-5,1e-6,1e-7]:
print('delta', delta, "Testing gradient",testwf.test_wf_gradient(slater,configs,delta=delta))
print('delta', delta, "Testing laplacian", testwf.test_wf_laplacian(slater,configs,delta=delta))
print('delta', delta, "Testing pgradient", testwf.test_wf_pgradient(slater,configs,delta=delta))
print("testing internals:", testwf.test_updateinternals(slater,configs))
quit()
#Test the internal update
e=3
slater.recompute(configs)
inv=slater._inverse.copy()
configsnew=configs.copy()
configsnew[:,e,:]+=0.1
slater.updateinternals(e,configsnew[:,e,:])
inv_update=slater._inverse.copy()
slater.recompute(configsnew)
inv_recalc=slater._inverse.copy()
print(inv_recalc-inv_update)
def test():
from pyscf import lib, gto, scf
np.random.seed(10)
mol = gto.M(atom='Li 0. 0. 0.; H 0. 0. 1.5', basis='cc-pvtz',unit='bohr')
l = dir(mol)
nconf=20
configs=np.random.randn(nconf,np.sum(mol.nelec),3)
jastrow=Jastrow2B(mol)
jastrow.parameters['coeff']=np.random.random(jastrow.parameters['coeff'].shape)
import pyqmc.testwf as testwf
#print(testwf.test_updateinternals(jastrow,configs))
for key, val in testwf.test_updateinternals(jastrow, configs).items():
print(key, val)
print()
for delta in [1e-3,1e-4,1e-5,1e-6,1e-7]:
print('delta', delta, "Testing gradient",
testwf.test_wf_gradient(jastrow,configs,delta=delta))
print('delta', delta, "Testing laplacian",
testwf.test_wf_laplacian(jastrow,configs,delta=delta))
print('delta', delta, "Testing pgradient",
testwf.test_wf_pgradient(jastrow,configs,delta=delta))
print()