Exemplo n.º 1
0
def run_neugebaur(config, sirius_config, callback=None, final_callback=None):
    """
    Keyword Arguments:
    config        -- dictionary
    sirius_config -- /path/to/sirius.json
    """
    from sirius.edft import NeugebaurCG as CG, FreeEnergy

    cg_config = config['CG']
    X, fn, E, ctx, kset = initial_state(sirius_config, cg_config['nscf'])
    T = config['System']['T']
    smearing = make_smearing(config['System']['smearing'], T, ctx, kset)
    M = FreeEnergy(E=E, T=T, smearing=smearing)
    cg = CG(M)
    K = make_precond(cg_config, kset)

    tstart = time.time()
    X, fn, FE, success = cg.run(X,
                                fn,
                                tol=cg_config['tol'],
                                K=K,
                                maxiter=cg_config['maxiter'],
                                kappa=cg_config['method']['kappa'],
                                restart=cg_config['restart'],
                                cgtype=cg_config['type'],
                                tau=cg_config['tau'],
                                callback=callback(kset, E=E))
    assert success
    tstop = time.time()
    logger('cg.run took: ', tstop - tstart, ' seconds')
    if final_callback is not None:
        final_callback(kset, E=E)(X=X, fn=fn)
    return X, fn, FE
Exemplo n.º 2
0
def run_marzari(config, sirius_config, callback=None, final_callback=None):
    """
    Keyword Arguments:
    config        -- dictionary
    sirius_config -- /path/to/sirius.json
    """
    from sirius.edft import MarzariCG as CG, FreeEnergy

    cg_config = config['CG']

    X, fn, E, ctx, kset = initial_state(sirius_config, cg_config['nscf'])

    T = config['System']['T']
    smearing = make_smearing(config['System']['smearing'], T, ctx, kset)
    M = FreeEnergy(E=E, T=T, smearing=smearing)
    method_config = config['CG']['method']
    cg = CG(M, fd_slope_check=method_config['fd_slope_check'])
    K = make_precond(cg_config, kset)

    tstart = time.time()
    FE, X, fn, success = cg.run(X,
                                fn,
                                tol=cg_config['tol'],
                                maxiter=cg_config['maxiter'],
                                ninner=cg_config['method']['inner'],
                                K=K,
                                callback=callback(kset, E=E))
    assert success
    tstop = time.time()
    logger('cg.run took: ', tstop - tstart, ' seconds')
    if final_callback is not None:
        final_callback(kset, E=E)(X=X, fn=fn)
    return X, fn, FE
    def find(self, energy_tol, num_dft_iter, **_):
        """Find ground state by the orbital transformation method."""
        from sirius.edft.preconditioner import make_kinetic_precond2
        from sirius.edft import NeugebaurCG as CG
        import time

        cg = CG(self.M)
        K = make_kinetic_precond2(self.kset)

        def make_callback(histE):
            def _callback(**kwargs):
                histE.append(kwargs['FE'])

            return _callback

        tstart = time.time()
        X = self.kset.C
        fn = self.kset.fn
        histE = []
        X, fn, FE, success = cg.run(X,
                                    fn,
                                    tol=energy_tol,
                                    K=K,
                                    maxiter=num_dft_iter,
                                    kappa=0.3,
                                    restart=10,
                                    cgtype='FR',
                                    tau=0.1,
                                    callback=make_callback(histE))
        tstop = time.time()
        pprint('MVP2 took: ', tstop - tstart, ' seconds')
        pprint('number of steps found by callback:', len(histE))

        return {
            'converged': success,
            'num_scf_iterations': len(histE),
            'band_gap': -1,
            'energy': {
                'total': FE
            }
        }
Exemplo n.º 4
0
kset = res['kpointset']
potential = res['potential']
density = res['density']
hamiltonian = res['hamiltonian']
H = ApplyHamiltonian(hamiltonian, kset)
E = Energy(kset, potential, density, H)
T = args.T
kT = kb*T
nel = ctx.unit_cell().num_valence_electrons()
smearing = GaussianSplineSmearing(T=T, nel=nel, nspin=2, kw=kset.w)
# smearing = RegularizedFermiDiracSmearing(T=T, nel=nel, nspin=2, kw=kset.w)

fn = kset.fn
X = kset.C

M = FreeEnergy(H=H, E=E, T=T, smearing=smearing)
cg = CG(M, fd_slope_check=args.check_slope)
tstart = time.time()
FE, X, fn, success = cg.run(X, fn,
                            maxiter=args.maxiter,
                            ninner=args.ni,
                            prec_type=args.precond,
                            tol=args.tol,
                            callback=callback(kset))
tstop = time.time()
logger('cg.run took: ', tstop-tstart, ' seconds')
if not success:
    logger('!!! CG DID NOT CONVERGE !!!')
logger('final energy:', M(X, fn))
save_state({'X': X, 'f': fn}, kset=kset, prefix='marzari_final')
Exemplo n.º 5
0
# not yet implemented for single spin channel system
assert m == 1
kset = res['kpointset']
potential = res['potential']
density = res['density']
E = Energy(kset, potential, density, ApplyHamiltonian(potential, kset))
T = args.T
kT = kb * T

fn = kset.fn
X = kset.C

# smearing = make_fermi_dirac_smearing(T, ctx, kset)
smearing = make_gaussian_spline_smearing(T, ctx, kset)
M = FreeEnergy(E=E, T=T, smearing=smearing)
cg = CG(M)
tstart = time.time()


def callback(kset, interval=50, **kwargs):
    def _callback(fn, it, **kwargs):
        if it % interval == 0:
            save_state({'f': fn}, kset=kset, prefix='fn_%05d_' % it)

    return _callback


X, fn = cg.run(X,
               fn,
               tol=args.tol,
               prec=use_prec,