Beispiel #1
0
def test():
    # Default multi-Slater wave function
    mol = gto.M(atom="Li 0. 0. 0.; H 0. 0. 1.5",
                basis="cc-pvtz",
                unit="bohr",
                spin=0)
    mf = scf.RHF(mol).run()
    mc = mcscf.CASCI(mf, ncas=2, nelecas=(1, 1))
    mc.kernel()

    wf, to_opt = default_msj(mol, mf, mc)
    old_parms = wf.parameters
    lt = LinearTransform(wf.parameters, to_opt)

    # Test serialize parameters
    x0 = lt.serialize_parameters(wf.parameters)
    x0 += np.random.normal(size=x0.shape)
    wf.parameters = lt.deserialize(x0)
    assert wf.parameters["wf1det_coeff"][0] == old_parms["wf1det_coeff"][0]
    assert np.sum(wf.parameters["wf2bcoeff"][0] -
                  old_parms["wf2bcoeff"][0]) == 0

    # Test serialize gradients
    configs = OpenConfigs(np.random.randn(10, 4, 3))
    wf.recompute(configs)
    pgrad = wf.pgradient()
    pgrad_serial = lt.serialize_gradients(pgrad)
    assert np.sum(pgrad_serial[:, :3] - pgrad["wf1det_coeff"][:, 1:4]) == 0
Beispiel #2
0
def test_transform():
    """ Just prints things out; 
    TODO: figure out a thing to test.
    """
    from pyscf import gto, scf

    r = 1.54 / 0.529177
    mol = gto.M(
        atom="H 0. 0. 0.; H 0. 0. %g" % r,
        ecp="bfd",
        basis="bfd_vtz",
        unit="bohr",
        verbose=1,
    )
    mf = scf.RHF(mol).run()
    wf, to_opt = pyqmc.default_sj(mol, mf)
    enacc = pyqmc.EnergyAccumulator(mol)
    print(list(wf.parameters.keys()))
    transform = LinearTransform(wf.parameters)
    x = transform.serialize_parameters(wf.parameters)

    nconfig = 10
    configs = pyqmc.initial_guess(mol, nconfig)
    wf.recompute(configs)
    pgrad = wf.pgradient()
    gradtrans = transform.serialize_gradients(pgrad)
    assert gradtrans.shape[1] == len(x)
    assert gradtrans.shape[0] == nconfig
Beispiel #3
0
def test_transform():
    """ Just prints things out; 
    TODO: figure out a thing to test.
    """
    from pyscf import gto, scf
    import pyqmc

    r = 1.54 / .529177
    mol = gto.M(atom='H 0. 0. 0.; H 0. 0. %g' % r,
                ecp='bfd',
                basis='bfd_vtz',
                unit='bohr',
                verbose=1)
    mf = scf.RHF(mol).run()
    wf = pyqmc.slater_jastrow(mol, mf)
    enacc = pyqmc.EnergyAccumulator(mol)
    print(list(wf.parameters.keys()))
    transform = LinearTransform(wf.parameters)
    x = transform.serialize_parameters(wf.parameters)

    nconfig = 10
    configs = pyqmc.initial_guess(mol, nconfig)
    wf.recompute(configs)
    pgrad = wf.pgradient()
    gradtrans = transform.serialize_gradients(pgrad)
    assert gradtrans.shape[1] == len(x)
    assert gradtrans.shape[0] == nconfig
Beispiel #4
0
def test_constraints(H2_ccecp_casci_s0):
    mol, mf, mc = H2_ccecp_casci_s0

    wf, to_opt = pyq.generate_wf(mol, mf, mc=mc)

    old_parms = copy.deepcopy(wf.parameters)
    lt = LinearTransform(wf.parameters, to_opt)

    # Test serialize parameters
    x0 = lt.serialize_parameters(wf.parameters)
    x0 += np.random.normal(size=x0.shape)
    for k, it in lt.deserialize(wf, x0).items():
        assert wf.parameters[k].shape == it.shape
        wf.parameters[k] = it

    # to_opt is supposed to be false for both of these.
    assert wf.parameters["wf1det_coeff"][0] == old_parms["wf1det_coeff"][0]
    assert np.sum(wf.parameters["wf2bcoeff"][0] -
                  old_parms["wf2bcoeff"][0]) == 0
    # While this one is supposed to change.
    assert np.sum(wf.parameters["wf2bcoeff"][1] -
                  old_parms["wf2bcoeff"][1]) != 0

    # Test serialize gradients
    configs = pyq.initial_guess(mol, 10)
    wf.recompute(configs)
    pgrad = wf.pgradient()
    pgrad_serial = lt.serialize_gradients(pgrad)

    # Pgrad should be walkers, configs
    assert pgrad_serial.shape[1] == x0.shape[0]
Beispiel #5
0
def test_transform(LiH_sto3g_rhf):
    """Tests that the shapes are ok"""
    mol, mf = LiH_sto3g_rhf
    wf, to_opt = pyq.generate_wf(mol, mf)
    transform = LinearTransform(wf.parameters)
    x = transform.serialize_parameters(wf.parameters)
    nconfig = 10
    configs = pyq.initial_guess(mol, nconfig)
    wf.recompute(configs)
    pgrad = wf.pgradient()
    gradtrans = transform.serialize_gradients(pgrad)
    assert gradtrans.shape[1] == len(x)
    assert gradtrans.shape[0] == nconfig