コード例 #1
0
def get_trial_wavefunction(options, system, cplx, parallel, verbose=False):
    """Wrapper to select trial wavefunction class.

    Parameters
    ----------
    options : dict
        Trial wavefunction input options.
    system : class
        System class.
    cplx : bool
        If true then trial wavefunction will be complex.
    parallel : bool
        If true then running in parallel.

    Returns
    -------
    trial : class or None
        Trial wavfunction class.
    """
    if options['name'] == 'free_electron':
        trial = FreeElectron(system, cplx, options, parallel, verbose)
    elif options['name'] == 'UHF':
        trial = UHF(system, cplx, options, parallel, verbose)
    elif options['name'] == 'multi_determinant':
        trial = MultiDeterminant(system, cplx, options, parallel, verbose)
    elif options['name'] == 'hartree_fock':
        trial = HartreeFock(system, cplx, options, parallel, verbose)
    else:
        trial = None

    return trial
コード例 #2
0
ファイル: test_afqmc.py プロジェクト: hungpham2017/pauxy
def test_constructor():
    options = {
        'verbosity': 0,
        'get_sha1': False,
        'qmc': {
            'timestep': 0.01,
            'num_steps': 10,
            'blocks': 10,
            'rng_seed': 8,
        },
        'estimates': {
            'mixed': {
                'energy_eval_freq': 1
            }
        }
    }
    model = {
        'name': "UEG",
        'rs': 2.44,
        'ecut': 4,
        'nup': 7,
        'ndown': 7,
    }
    system = UEG(model)
    trial = HartreeFock(system, True, {})
    comm = MPI.COMM_WORLD
    afqmc = AFQMC(comm=comm, options=options, system=system, trial=trial)
    afqmc.finalise(verbose=0)
    assert afqmc.trial.energy.real == pytest.approx(1.7796083856572522)
コード例 #3
0
ファイル: test_back_prop.py プロジェクト: hungpham2017/pauxy
def test_back_prop():
    sys = UEG({'rs': 2, 'nup': 7, 'ndown': 7, 'ecut': 1.0})
    bp_opt = {'tau_bp': 1.0, 'nsplit': 4}
    qmc = dotdict({'dt': 0.05, 'nstblz': 10, 'nwalkers': 1})
    trial = HartreeFock(sys, True, {})
    numpy.random.seed(8)
    prop = Continuous(sys, trial, qmc)
    est = BackPropagation(bp_opt, True, 'estimates.0.h5', qmc, sys, trial,
                          numpy.complex128, prop.BT_BP)
    walkers = Walkers({}, sys, trial, qmc, nbp=est.nmax, nprop_tot=est.nmax)
    wlk = walkers.walkers[0]
    from mpi4py import MPI
    comm = MPI.COMM_WORLD
    for i in range(0, 2 * est.nmax):
        prop.propagate_walker(wlk, sys, trial, 0)
        if i % 10 == 0:
            walkers.orthogonalise(trial, False)
        est.update_uhf(sys, qmc, trial, walkers, 100)
        est.print_step(comm, comm.size, i, 10)
コード例 #4
0
ファイル: continuous.py プロジェクト: hungpham2017/pauxy
def unit_test():
    from pauxy.systems.ueg import UEG
    from pauxy.qmc.options import QMCOpts
    from pauxy.trial_wavefunction.hartree_fock import HartreeFock

    inputs = {
        'nup': 1,
        'ndown': 1,
        'rs': 1.0,
        'ecut': 1.0,
        'dt': 0.05,
        'nwalkers': 10
    }

    system = UEG(inputs, True)

    qmc = QMCOpts(inputs, system, True)

    trial = HartreeFock(system, False, inputs, True)

    driver = Continuous({}, qmc, system, trial, True)
コード例 #5
0
def unit_test():
    from numpy import linalg as LA
    from pyscf import gto, scf, ao2mo, mcscf, fci, ci, cc, tdscf, gw, hci
    from pauxy.systems.ueg import UEG
    from pauxy.trial_wavefunction.hartree_fock import HartreeFock
    from pauxy.trial_wavefunction.free_electron import FreeElectron

    ecut = 1.0

    inputs = {'nup': 7, 'ndown': 7, 'rs': 1.0, 'thermal': False, 'ecut': ecut}

    system = PW_FFT(inputs, True)
    trial = FreeElectron(system, False, inputs, True)

    from pauxy.qmc.options import QMCOpts
    from pauxy.propagation.continuous import Continuous

    system2 = UEG(inputs, True)

    qmc = QMCOpts(inputs, system2, True)

    trial = HartreeFock(system2, False, inputs, True)
コード例 #6
0
def unit_test():
    import cProfile
    from pauxy.propagation.continuous import Continuous
    from pauxy.systems.ueg import UEG
    from pauxy.systems.pw_fft import PW_FFT
    from pauxy.qmc.options import QMCOpts
    from pauxy.walkers.single_det import SingleDetWalker
    from pauxy.trial_wavefunction.hartree_fock import HartreeFock
    from pauxy.trial_wavefunction.free_electron import FreeElectron

    inputs = {
        'nup': 1,
        'ndown': 1,
        'rs': 1.0,
        'ecut': 20.0,
        'dt': 0.05,
        'nwalkers': 1,
        'expansion_order': 6
    }

    numpy.random.seed(7)

    system = PW_FFT(inputs, True)
    qmc = QMCOpts(inputs, system, True)
    trial = HartreeFock(system, False, inputs, True)
    rpsi = numpy.random.rand(system.nbasis, system.nup + system.ndown)
    zpsi = numpy.random.rand(system.nbasis, system.nup + system.ndown)
    trial.psi = rpsi + 1.j * zpsi

    propagator = PW(system, trial, qmc, inputs, verbose=True)

    walker = SingleDetWalker({}, system, trial, index=0)
    walker.greens_function(trial)

    rphi = numpy.random.rand(system.nbasis, system.nup + system.ndown)
    zphi = numpy.random.rand(system.nbasis, system.nup + system.ndown)
    walker.phi = rphi + 1.j * zphi

    eshift = 0.0 + 0.0j

    # print(walker.phi)
    pr = cProfile.Profile()
    pr.enable()
    propagator.propagate_walker_phaseless(walker=walker,
                                          system=system,
                                          trial=trial,
                                          eshift=eshift)
    propagator.propagate_walker_phaseless(walker=walker,
                                          system=system,
                                          trial=trial,
                                          eshift=eshift)
    propagator.propagate_walker_phaseless(walker=walker,
                                          system=system,
                                          trial=trial,
                                          eshift=eshift)
    propagator.propagate_walker_phaseless(walker=walker,
                                          system=system,
                                          trial=trial,
                                          eshift=eshift)
    propagator.propagate_walker_phaseless(walker=walker,
                                          system=system,
                                          trial=trial,
                                          eshift=eshift)
    pr.disable()
    pr.print_stats(sort='tottime')
    # print(walker.phi)
    # phi_ref = walker.phi.copy()

    sort_basis = numpy.argsort(numpy.diag(system.H1[0]), kind='mergesort')
    numpy.random.seed(7)

    system = UEG(inputs, True)
    qmc = QMCOpts(inputs, system, True)
    trial = HartreeFock(system, False, inputs, True)
    rpsi = numpy.random.rand(system.nbasis, system.nup + system.ndown)
    zpsi = numpy.random.rand(system.nbasis, system.nup + system.ndown)
    trial.psi = rpsi + 1.j * zpsi
    trial.psi[:, :] = trial.psi[sort_basis, :]

    propagator = Continuous(system, trial, qmc, inputs, verbose=True)

    walker = SingleDetWalker({}, system, trial, index=0)
    walker.greens_function(trial)

    rphi = numpy.random.rand(system.nbasis, system.nup + system.ndown)
    zphi = numpy.random.rand(system.nbasis, system.nup + system.ndown)
    walker.phi = rphi + 1.j * zphi
    walker.phi[:, :] = walker.phi[sort_basis, :]

    # print(walker.phi)

    eshift = 0.0 + 0.0j

    pr = cProfile.Profile()
    pr.enable()
    propagator.propagate_walker_phaseless(walker=walker,
                                          system=system,
                                          trial=trial,
                                          eshift=eshift)
    propagator.propagate_walker_phaseless(walker=walker,
                                          system=system,
                                          trial=trial,
                                          eshift=eshift)
    propagator.propagate_walker_phaseless(walker=walker,
                                          system=system,
                                          trial=trial,
                                          eshift=eshift)
    propagator.propagate_walker_phaseless(walker=walker,
                                          system=system,
                                          trial=trial,
                                          eshift=eshift)
    propagator.propagate_walker_phaseless(walker=walker,
                                          system=system,
                                          trial=trial,
                                          eshift=eshift)
    pr.disable()
    pr.print_stats(sort='tottime')
コード例 #7
0
def get_trial_wavefunction(system,
                           options={},
                           mf=None,
                           parallel=False,
                           verbose=0):
    """Wrapper to select trial wavefunction class.

    Parameters
    ----------
    options : dict
        Trial wavefunction input options.
    system : class
        System class.
    cplx : bool
        If true then trial wavefunction will be complex.
    parallel : bool
        If true then running in parallel.

    Returns
    -------
    trial : class or None
        Trial wavfunction class.
    """
    wfn_file = get_input_value(options,
                               'filename',
                               default=None,
                               alias=['wavefunction_file'],
                               verbose=verbose)
    if wfn_file is not None:
        if verbose:
            print("# Reading wavefunction from {}.".format(wfn_file))
        read, psi0 = read_qmcpack_wfn_hdf(wfn_file)
        thresh = options.get('threshold', None)
        if thresh is not None:
            coeff = read[0]
            ndets = len(coeff[abs(coeff) > thresh])
            if verbose:
                print("# Discarding determinants with weight "
                      "  below {}.".format(thresh))
        else:
            ndets = options.get('ndets', None)
        if verbose:
            print("# Numeber of determinants in trial wavefunction: {}".format(
                ndets))
        if ndets is not None:
            wfn = []
            for x in read:
                wfn.append(x[:ndets])
        else:
            wfn = read
        trial = MultiSlater(system,
                            wfn,
                            options=options,
                            parallel=parallel,
                            verbose=verbose,
                            init=psi0)
    elif options['name'] == 'MultiSlater':
        if verbose:
            print("# Guessing RHF trial wavefunction.")
        na = system.nup
        nb = system.ndown
        wfn = numpy.zeros((1, system.nbasis, system.nup + system.ndown),
                          dtype=numpy.complex128)
        coeffs = numpy.array([1.0 + 0j])
        I = numpy.identity(system.nbasis, dtype=numpy.complex128)
        wfn[0, :, :na] = I[:, :na]
        wfn[0, :, na:] = I[:, :nb]
        trial = MultiSlater(system, (coeffs, wfn),
                            options=options,
                            parallel=parallel,
                            verbose=verbose)
    elif options['name'] == 'hartree_fock':
        trial = HartreeFock(system,
                            True,
                            options,
                            parallel=parallel,
                            verbose=verbose)
    elif options['name'] == 'free_electron':
        trial = FreeElectron(system, True, options, parallel, verbose)
    elif options['name'] == 'UHF':
        trial = UHF(system, True, options, parallel, verbose)
    else:
        print("Unknown trial wavefunction type.")
        sys.exit()

    return trial