コード例 #1
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)
コード例 #2
0
ファイル: calc.py プロジェクト: hungpham2017/pauxy
def get_driver(options, comm):
    qmc_opts = get_input_value(options,
                               'qmc',
                               default={},
                               alias=['qmc_options'])
    beta = get_input_value(qmc_opts, 'beta', default=None)
    verbosity = options.get('verbosity', 1)
    if beta is not None:
        afqmc = ThermalAFQMC(comm,
                             options=options,
                             parallel=comm.size > 1,
                             verbose=verbosity)
    else:
        afqmc = AFQMC(comm,
                      options=options,
                      parallel=comm.size > 1,
                      verbose=verbosity)
    return afqmc
コード例 #3
0
ファイル: test_afqmc.py プロジェクト: hungpham2017/pauxy
def test_generic_single_det():
    nmo = 11
    nelec = (3, 3)
    options = {
        'verbosity': 0,
        'qmc': {
            'timestep': 0.005,
            'num_steps': 10,
            'blocks': 10,
            'rng_seed': 8,
        },
        'trial': {
            'name': 'hartree_fock'
        },
        'estimator': {
            'back_propagated': {
                'tau_bp': 0.025,
                'one_rdm': True
            },
            'mixed': {
                'energy_eval_freq': 1
            }
        }
    }
    numpy.random.seed(7)
    h1e, chol, enuc, eri = generate_hamiltonian(nmo, nelec, cplx=False)
    sys_opts = {'sparse': True}
    sys = Generic(nelec=nelec, h1e=h1e, chol=chol, ecore=enuc, inputs=sys_opts)
    comm = MPI.COMM_WORLD
    afqmc = AFQMC(comm=comm, system=sys, options=options)
    afqmc.run(comm=comm, verbose=0)
    afqmc.finalise(verbose=0)
    afqmc.estimators.estimators['mixed'].update(afqmc.system, afqmc.qmc,
                                                afqmc.trial, afqmc.psi, 0)
    enum = afqmc.estimators.estimators['mixed'].names
    numer = afqmc.estimators.estimators['mixed'].estimates[enum.enumer]
    denom = afqmc.estimators.estimators['mixed'].estimates[enum.edenom]
    weight = afqmc.estimators.estimators['mixed'].estimates[enum.weight]
    assert numer.real == pytest.approx(3.8763193646854273)
    data = extract_mixed_estimates('estimates.0.h5')
    assert numpy.mean(
        data.ETotal.values[:-1].real) == pytest.approx(1.5485077038208)
    rdm = extract_rdm('estimates.0.h5')
    assert rdm[0, 0].trace() == pytest.approx(nelec[0])
    assert rdm[0, 1].trace() == pytest.approx(nelec[1])
    assert rdm[11, 0, 1, 3].real == pytest.approx(-0.121883381144845)
コード例 #4
0
ファイル: test_afqmc.py プロジェクト: hungpham2017/pauxy
def test_hubbard():
    options = {
        'verbosity': 0,
        'get_sha1': False,
        'qmc': {
            'timestep': 0.01,
            'num_steps': 10,
            'blocks': 10,
            'rng_seed': 8,
        },
        'model': {
            'name': "Hubbard",
            'nx': 4,
            'ny': 4,
            'nup': 7,
            "U": 4,
            'ndown': 7,
        },
        'trial': {
            'name': 'UHF'
        },
        'estimates': {
            'mixed': {
                'energy_eval_freq': 1
            }
        },
        'propagator': {
            'hubbard_stratonovich': 'discrete'
        }
    }
    comm = MPI.COMM_WORLD
    afqmc = AFQMC(comm=comm, options=options)
    afqmc.run(comm=comm, verbose=0)
    afqmc.finalise(verbose=0)
    afqmc.estimators.estimators['mixed'].update(afqmc.system, afqmc.qmc,
                                                afqmc.trial, afqmc.psi, 0)
    enum = afqmc.estimators.estimators['mixed'].names
    numer = afqmc.estimators.estimators['mixed'].estimates[enum.enumer]
    denom = afqmc.estimators.estimators['mixed'].estimates[enum.edenom]
    weight = afqmc.estimators.estimators['mixed'].estimates[enum.weight]
    assert numer.real == pytest.approx(-152.68468568462666)
    data = extract_mixed_estimates('estimates.0.h5')
    # old code seemed to ommit last value. Discard to avoid updating benchmark.
    assert numpy.mean(
        data.ETotal.values[:-1]) == pytest.approx(-14.974806533852874)
コード例 #5
0
ファイル: test_afqmc.py プロジェクト: hungpham2017/pauxy
def test_hubbard_complex():
    options = {
        'verbosity': 0,
        'get_sha1': False,
        'qmc': {
            'timestep': 0.01,
            'num_steps': 10,
            'blocks': 10,
            'rng_seed': 8,
        },
        'model': {
            'name': "Hubbard",
            'nx': 4,
            'ny': 4,
            'nup': 7,
            "U": 4,
            'ndown': 7,
        },
        'trial': {
            'name': 'UHF'
        },
        'estimates': {
            'mixed': {
                'energy_eval_freq': 1
            }
        },
        'propagator': {
            'hubbard_stratonovich': 'continuous'
        }
    }
    comm = MPI.COMM_WORLD
    afqmc = AFQMC(comm=comm, options=options)
    afqmc.run(comm=comm, verbose=0)
    afqmc.finalise(verbose=0)
    afqmc.estimators.estimators['mixed'].update(afqmc.system, afqmc.qmc,
                                                afqmc.trial, afqmc.psi, 0)
    enum = afqmc.estimators.estimators['mixed'].names
    numer = afqmc.estimators.estimators['mixed'].estimates[enum.enumer]
    denom = afqmc.estimators.estimators['mixed'].estimates[enum.edenom]
    weight = afqmc.estimators.estimators['mixed'].estimates[enum.weight]
    assert numer == pytest.approx(-152.91937839611)
    data = extract_mixed_estimates('estimates.0.h5')
    assert numpy.mean(
        data.ETotal.values[:-1].real) == pytest.approx(-15.14323385684513)
コード例 #6
0
ファイル: test_afqmc.py プロジェクト: hungpham2017/pauxy
def test_ueg():
    options = {
        'verbosity': 0,
        'get_sha1': False,
        'qmc': {
            'timestep': 0.01,
            'num_steps': 10,
            'blocks': 10,
            'rng_seed': 8,
        },
        'model': {
            'name': "UEG",
            'rs': 2.44,
            'ecut': 4,
            'nup': 7,
            'ndown': 7,
        },
        'estimates': {
            'mixed': {
                'energy_eval_freq': 1
            }
        },
        'trial': {
            'name': 'hartree_fock'
        }
    }
    comm = MPI.COMM_WORLD
    # FDM: Fix cython issue.
    afqmc = AFQMC(comm=comm, options=options)
    afqmc.run(comm=comm, verbose=0)
    afqmc.finalise(verbose=0)
    afqmc.estimators.estimators['mixed'].update(afqmc.system, afqmc.qmc,
                                                afqmc.trial, afqmc.psi, 0)
    enum = afqmc.estimators.estimators['mixed'].names
    numer = afqmc.estimators.estimators['mixed'].estimates[enum.enumer]
    assert numer == pytest.approx(15.5272838037998)
    denom = afqmc.estimators.estimators['mixed'].estimates[enum.edenom]
    assert denom == pytest.approx(10)
    weight = afqmc.estimators.estimators['mixed'].estimates[enum.uweight]
    assert weight == pytest.approx(9.76035750882054)
    ehy = afqmc.psi.walkers[0].hybrid_energy
    assert ehy.real == pytest.approx(2.41659997842609)
    assert ehy.imag == pytest.approx(-0.395817411848255)
コード例 #7
0
ファイル: test_afqmc.py プロジェクト: hungpham2017/pauxy
def test_generic():
    nmo = 11
    nelec = (3, 3)
    options = {
        'verbosity': 0,
        'get_sha1': False,
        'qmc': {
            'timestep': 0.005,
            'steps': 10,
            'blocks': 10,
            'rng_seed': 8,
        },
        'estimates': {
            'mixed': {
                'energy_eval_freq': 1
            }
        },
        'trial': {
            'name': 'MultiSlater'
        }
    }
    numpy.random.seed(7)
    h1e, chol, enuc, eri = generate_hamiltonian(nmo, nelec, cplx=False)
    sys = Generic(nelec=nelec, h1e=h1e, chol=chol, ecore=enuc)
    comm = MPI.COMM_WORLD
    afqmc = AFQMC(comm=comm, system=sys, options=options)
    afqmc.run(comm=comm, verbose=0)
    afqmc.finalise(verbose=0)
    afqmc.estimators.estimators['mixed'].update(afqmc.system, afqmc.qmc,
                                                afqmc.trial, afqmc.psi, 0)
    enum = afqmc.estimators.estimators['mixed'].names
    numer = afqmc.estimators.estimators['mixed'].estimates[enum.enumer]
    denom = afqmc.estimators.estimators['mixed'].estimates[enum.edenom]
    weight = afqmc.estimators.estimators['mixed'].estimates[enum.weight]
    assert numer.real == pytest.approx(3.8763193646854273)
    data = extract_mixed_estimates('estimates.0.h5')
    assert numpy.mean(
        data.ETotal.values[:-1].real) == pytest.approx(1.5485077038208)
コード例 #8
0
ファイル: calc.py プロジェクト: sunchong137/pauxy
def setup_parallel(options, comm=None, verbose=False):
    """Wrapper routine for initialising simulation

    Parameters
    ----------
    options : dict
        Input options.
    comm : MPI communicator
        MPI communicator object.
    verbose : bool
        If true print out set up information.

    Returns
    -------
    afqmc : :class:`pauxy.afqmc.CPMC`
        CPMC driver.
    """
    if comm.Get_rank() == 0:
        afqmc = AFQMC(options.get('model'),
                      options.get('qmc_options'),
                      options.get('estimates'),
                      options.get('trial_wavefunction'),
                      options.get('propagator', {}),
                      parallel=True,
                      verbose=verbose)
    else:
        afqmc = None
    afqmc = comm.bcast(afqmc, root=0)
    afqmc.init_time = time.time()
    if afqmc.trial.error:
        warnings.warn('Error in constructing trial wavefunction. Exiting')
        sys.exit()
    afqmc.rank = comm.Get_rank()
    afqmc.nprocs = comm.Get_size()
    afqmc.root = afqmc.rank == 0
    # We can't serialise '_io.BufferWriter' object, so just delay initialisation
    # of estimators object to after MPI communication.
    # Simpler to just ensure a fixed number of walkers per core.
    afqmc.qmc.nwalkers = int(afqmc.qmc.nwalkers / afqmc.nprocs)
    if afqmc.qmc.nwalkers == 0:
        # This should occur on all processors so we don't need to worry about
        # race conditions / mpi4py hanging.
        if afqmc.root:
            warnings.warn('Not enough walkers for selected core count. There '
                          'must be at least one walker per core set in the '
                          'input file. Exiting.')
        sys.exit()

    afqmc.estimators = (Estimators(options.get('estimates'), afqmc.root,
                                   afqmc.qmc, afqmc.system, afqmc.trial,
                                   afqmc.propagators.BT_BP))
    afqmc.psi = Walkers(afqmc.system, afqmc.trial, afqmc.qmc.nwalkers,
                        afqmc.estimators.nprop_tot, afqmc.estimators.nbp)
    if comm.Get_rank() == 0:
        json.encoder.FLOAT_REPR = lambda o: format(o, '.6f')
        json_string = json.dumps(serialise(afqmc, verbose=1),
                                 sort_keys=False,
                                 indent=4)
        afqmc.estimators.h5f.create_dataset('metadata',
                                            data=numpy.array([json_string],
                                                             dtype=object),
                                            dtype=h5py.special_dtype(vlen=str))

    return afqmc