Пример #1
0
def analyse_estimates(files, start_time, multi_sim=False):
    mds = []
    basic = []
    for f in files:
        md = get_metadata(f)
        read_rs = get_from_dict(md, ['psi', 'read_rs'])
        step = get_from_dict(md, ['qmc', 'nsteps'])
        dt = get_from_dict(md, ['qmc', 'dt'])
        start = int(start_time/(step*dt)) + 1
        if read_rs:
            start = 0
        data = extract_mixed_estimates(f, start)
        columns = set_info(data, md)
        basic.append(data.drop('Iteration', axis=1))
        mds.append(md)
    basic = pd.concat(basic).groupby(columns)
    basic_av = reblock_mixed(basic, columns)
    base = files[0].split('/')[-1]
    outfile = 'analysed_' + base
    fmt = lambda x: "{:13.8f}".format(x)
    print(basic_av.to_string(index=False, float_format=fmt))
    with h5py.File(outfile, 'w') as fh5:
        fh5['metadata'] = numpy.array(mds).astype('S')
        try:
            fh5['basic/estimates'] = basic_av.drop('integrals',axis=1).values.astype(float)
        except KeyError:
            print("integrals does not exist under the problem class")
        fh5['basic/headers'] = numpy.array(basic_av.columns.values).astype('S')
Пример #2
0
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)
Пример #3
0
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)
Пример #4
0
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)
Пример #5
0
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)