Beispiel #1
0
 def __init__(self, inputs, system, verbose=False):
     self.nwalkers = get_input_value(inputs,
                                     'num_walkers',
                                     default=10,
                                     alias=['nwalkers'],
                                     verbose=verbose)
     self.dt = get_input_value(inputs,
                               'timestep',
                               default=0.005,
                               alias=['dt'],
                               verbose=verbose)
     self.nsteps = get_input_value(inputs,
                                   'num_steps',
                                   default=10,
                                   alias=['nsteps', 'steps'],
                                   verbose=verbose)
     self.nblocks = get_input_value(inputs,
                                    'blocks',
                                    default=1000,
                                    alias=['num_blocks', 'nblocks'],
                                    verbose=verbose)
     self.total_steps = self.nsteps * self.nblocks
     self.nstblz = get_input_value(inputs,
                                   'stabilise_freq',
                                   default=10,
                                   alias=['nstabilise', 'reortho'],
                                   verbose=verbose)
     self.npop_control = get_input_value(
         inputs,
         'pop_control_freq',
         default=1,
         alias=['npop_control', 'pop_control'],
         verbose=verbose)
     self.eqlb_time = get_input_value(inputs,
                                      'equilibration_time',
                                      default=2.0,
                                      alias=['tau_eqlb'],
                                      verbose=verbose)
     self.neqlb = int(self.eqlb_time / self.dt)
     self.beta = get_input_value(inputs,
                                 'beta',
                                 default=None,
                                 verbose=verbose)
     self.scaled_temp = get_input_value(inputs,
                                        'scaled_temperature',
                                        default=False,
                                        alias=['reduced_temperature'],
                                        verbose=verbose)
     if self.scaled_temp:
         self.beta_scaled = self.beta
         self.dt, self.beta = convert_from_reduced_unit(
             system, inputs, verbose)
     self.rng_seed = get_input_value(inputs,
                                     'rng_seed',
                                     default=None,
                                     alias=['random_seed', 'seed'],
                                     verbose=verbose)
Beispiel #2
0
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
Beispiel #3
0
 def __init__(self,
              comm,
              options=None,
              system=None,
              trial=None,
              parallel=False,
              verbose=False):
     if verbose is not None:
         self.verbosity = verbose
         if comm.rank != 0:
             self.verbosity = 0
         verbose = verbose > 0 and comm.rank == 0
     # 1. Environment attributes
     if comm.rank == 0:
         self.uuid = str(uuid.uuid1())
         get_sha1 = options.get('get_sha1', True)
         if get_sha1:
             self.sha1, self.branch = get_git_revision_hash()
         else:
             self.sha1 = 'None'
         if verbose:
             self.sys_info = get_sys_info(self.sha1, self.branch, self.uuid,
                                          comm.size)
     # Hack - this is modified later if running in parallel on
     # initialisation.
     self.root = comm.rank == 0
     self.rank = comm.rank
     self._init_time = time.time()
     self.run_time = time.asctime()
     # 2. Calculation objects.
     # if comm.rank == 0:
     # system = get_system(sys_opts=options.get('model', {}),
     # mf=mf, verbose=verbose)
     # else:
     # system = None
     # self.system = comm.bcast(system, root=0)
     if system is not None:
         self.system = system
     else:
         sys_opts = get_input_value(options,
                                    'model',
                                    default={},
                                    alias=['system'],
                                    verbose=self.verbosity > 1)
         self.system = get_system(sys_opts, verbose=verbose)
     qmc_opt = get_input_value(options,
                               'qmc',
                               default={},
                               alias=['qmc_options'],
                               verbose=self.verbosity > 1)
     self.qmc = QMCOpts(qmc_opt, self.system, verbose=self.verbosity > 1)
     self.qmc.rng_seed = set_rng_seed(self.qmc.rng_seed, comm)
     self.cplx = self.determine_dtype(options.get('propagator', {}),
                                      self.system)
     twf_opt = get_input_value(options,
                               'trial',
                               default={},
                               alias=['trial_wavefunction'],
                               verbose=self.verbosity > 1)
     if trial is not None:
         self.trial = trial
     else:
         if comm.rank == 0:
             self.trial = (get_trial_wavefunction(self.system,
                                                  options=twf_opt,
                                                  parallel=parallel,
                                                  verbose=verbose))
         else:
             self.trial = None
         self.trial = comm.bcast(self.trial, root=0)
     if self.system.name == "Generic":
         if self.trial.ndets == 1:
             if self.system.cplx_chol:
                 self.system.construct_integral_tensors_cplx(self.trial)
             else:
                 self.system.construct_integral_tensors_real(self.trial)
     if comm.rank == 0:
         self.trial.calculate_energy(self.system)
     prop_opt = options.get('propagator', {})
     self.propagators = get_propagator_driver(self.system,
                                              self.trial,
                                              self.qmc,
                                              options=prop_opt,
                                              verbose=verbose)
     self.tsetup = time.time() - self._init_time
     wlk_opts = get_input_value(options,
                                'walkers',
                                default={},
                                alias=['walker', 'walker_opts'],
                                verbose=self.verbosity > 1)
     est_opts = get_input_value(options,
                                'estimators',
                                default={},
                                alias=['estimates', 'estimator'],
                                verbose=self.verbosity > 1)
     est_opts['stack_size'] = wlk_opts.get('stack_size', 1)
     self.estimators = (Estimators(est_opts, self.root, self.qmc,
                                   self.system, self.trial,
                                   self.propagators.BT_BP, verbose))
     # Reset number of walkers so they are evenly distributed across
     # cores/ranks.
     # Number of walkers per core/rank.
     self.qmc.nwalkers = int(self.qmc.nwalkers / comm.size)
     # Total number of walkers.
     if self.qmc.nwalkers == 0:
         if comm.rank == 0:
             print("# WARNING: Not enough walkers for selected core count.")
             print(
                 "# There must be at least one walker per core set in the "
                 "input file.")
             print("# Setting one walker per core.")
         self.qmc.nwalkers = 1
     self.qmc.ntot_walkers = self.qmc.nwalkers * comm.size
     self.psi = Walkers(wlk_opts,
                        self.system,
                        self.trial,
                        self.qmc,
                        verbose,
                        nprop_tot=self.estimators.nprop_tot,
                        nbp=self.estimators.nbp,
                        comm=comm)
     if comm.rank == 0:
         json.encoder.FLOAT_REPR = lambda o: format(o, '.6f')
         json_string = to_json(self)
         self.estimators.json_string = json_string
         self.estimators.dump_metadata()
         if verbose:
             self.estimators.estimators['mixed'].print_key()
             self.estimators.estimators['mixed'].print_header()
Beispiel #4
0
 def __init__(self,
              system,
              wfn,
              nbasis=None,
              options={},
              init=None,
              parallel=False,
              verbose=False,
              orbs=None):
     self.verbose = verbose
     if verbose:
         print("# Parsing MultiSlater trial wavefunction input options.")
     init_time = time.time()
     self.name = "MultiSlater"
     self.type = "MultiSlater"
     # TODO : Fix for MSD.
     rediag = get_input_value(options,
                              'recompute_ci',
                              default=False,
                              alias=['rediag'],
                              verbose=verbose)
     self.half_rot = get_input_value(options,
                                     'half_rotate',
                                     default=False,
                                     alias=['rotate'],
                                     verbose=verbose)
     if len(wfn) == 3:
         # CI type expansion.
         self.from_phmsd(system, wfn, orbs)
         self.ortho_expansion = True
     else:
         self.psi = wfn[1]
         self.coeffs = numpy.array(wfn[0], dtype=numpy.complex128)
         self.ortho_expansion = False
     if self.verbose:
         if self.ortho_expansion:
             print("# Assuming orthogonal trial wavefunction expansion.")
         else:
             print(
                 "# Assuming non-orthogonal trial wavefunction expansion.")
         print("# Trial wavefunction shape: {}".format(self.psi.shape))
     self.ndets = len(self.coeffs)
     if self.ndets == 1:
         self.psi = self.psi[0]
         self.G, self.GH = gab_spin(self.psi, self.psi, system.nup,
                                    system.ndown)
     else:
         self.G = None
         self.GH = None
     if self.half_rot:
         self.half_rotate(system)
     if rediag:
         if self.verbose:
             print("# Recomputing CI coefficients.")
         self.recompute_ci_coeffs(system)
     if init is not None:
         self.init = init
     else:
         if len(self.psi.shape) == 3:
             self.init = self.psi[0].copy()
         else:
             self.init = self.psi.copy()
     self.error = False
     self.initialisation_time = time.time() - init_time
     self._nalpha = system.nup
     self._nelec = system.nelec
     self._nbasis = system.nbasis
     write_wfn = options.get('write_wavefunction', False)
     if write_wfn:
         self.write_wavefunction()
     if verbose:
         print("# Finished setting up trial wavefunction.")
Beispiel #5
0
 def __init__(self,
              estimates,
              root,
              qmc,
              system,
              trial,
              BT2,
              verbose=False):
     if verbose:
         print("# Setting up estimator object.")
     if root:
         index = estimates.get('index', 0)
         self.filename = estimates.get('filename', None)
         self.basename = estimates.get('basename', 'estimates')
         if self.filename is None:
             overwrite = estimates.get('overwrite', True)
             self.filename = self.basename + '.%s.h5' % index
             while os.path.isfile(self.filename) and not overwrite:
                 index = int(self.filename.split('.')[1])
                 index = index + 1
                 self.filename = self.basename + '.%s.h5' % index
         with h5py.File(self.filename, 'w') as fh5:
             pass
         if verbose:
             print("# Writing estimator data to {}.".format(self.filename))
     else:
         self.filename = None
     # Sub-members:
     # 1. Back-propagation
     mixed = estimates.get('mixed', {})
     self.estimators = {}
     dtype = complex
     self.estimators['mixed'] = Mixed(mixed, system, root, self.filename,
                                      qmc, trial, dtype)
     bp = get_input_value(estimates,
                          'back_propagation',
                          default=None,
                          alias=['back_propagated'],
                          verbose=verbose)
     self.back_propagation = bp is not None
     if self.back_propagation:
         self.estimators['back_prop'] = BackPropagation(
             bp, root, self.filename, qmc, system, trial, dtype, BT2)
         self.nprop_tot = self.estimators['back_prop'].nmax
         self.nbp = self.estimators['back_prop'].nmax
         if verbose:
             print("# Performing back propagation.")
             print("# Total number of back propagation steps: "
                   "{:d}.".format(self.nprop_tot))
     else:
         self.nprop_tot = None
         self.nbp = None
     # 2. Imaginary time correlation functions.
     itcf = estimates.get('itcf', None)
     self.calc_itcf = itcf is not None
     if self.calc_itcf:
         itcf['stack_size'] = estimates.get('stack_size', 1)
         self.estimators['itcf'] = ITCF(itcf, qmc, trial, root,
                                        self.filename, system, dtype, BT2)
         self.nprop_tot = self.estimators['itcf'].nprop_tot
     if verbose:
         print("# Finished settting up estimator object.")
Beispiel #6
0
    def __init__(self,
                 walker_opts,
                 system,
                 trial,
                 qmc,
                 verbose=False,
                 comm=None,
                 nprop_tot=None,
                 nbp=None):
        self.nwalkers = qmc.nwalkers
        self.ntot_walkers = qmc.ntot_walkers
        self.write_freq = walker_opts.get('write_freq', 0)
        self.write_file = walker_opts.get('write_file', 'restart.h5')
        self.read_file = walker_opts.get('read_file', None)
        if comm is None:
            rank = 0
        else:
            rank = comm.rank
        if verbose:
            print("# Setting up wavefunction object.")
        if trial.name == 'MultiSlater':
            self.walker_type = 'MSD'
            # TODO: FDM FIXTHIS
            if trial.ndets == 1:
                if verbose:
                    print("# Usinge single det walker with msd wavefunction.")
                self.walker_type = 'SD'
                self.walkers = [
                    SingleDetWalker(walker_opts,
                                    system,
                                    trial,
                                    index=w,
                                    nprop_tot=nprop_tot,
                                    nbp=nbp) for w in range(qmc.nwalkers)
                ]
            else:
                self.walkers = [
                    MultiDetWalker(walker_opts,
                                   system,
                                   trial,
                                   verbose=(verbose and w == 0))
                    for w in range(qmc.nwalkers)
                ]
            self.buff_size = self.walkers[0].buff_size
            if nbp is not None:
                self.buff_size += self.walkers[0].field_configs.buff_size
            self.walker_buffer = numpy.zeros(self.buff_size,
                                             dtype=numpy.complex128)
        elif trial.name == 'thermal':
            self.walker_type = 'thermal'
            self.walkers = [
                ThermalWalker(walker_opts, system, trial, verbose and w == 0)
                for w in range(qmc.nwalkers)
            ]
            self.buff_size = self.walkers[0].buff_size + self.walkers[
                0].stack.buff_size
            self.walker_buffer = numpy.zeros(self.buff_size,
                                             dtype=numpy.complex128)
            stack_size = self.walkers[0].stack_size
            if system.name == "Hubbard":
                if stack_size % qmc.nstblz != 0 or qmc.nstblz < stack_size:
                    if verbose:
                        print("# Stabilisation frequency is not commensurate "
                              "with stack size.")
                        print("# Determining a better value.")
                    if qmc.nstblz < stack_size:
                        qmc.nstblz = stack_size
                        if verbose:
                            print("# Updated stabilization frequency: "
                                  " {}".format(qmc.nstblz))
                    else:
                        qmc.nstblz = update_stack(qmc.nstblz,
                                                  stack_size,
                                                  name="nstblz",
                                                  verbose=verbose)
        else:
            self.walker_type = 'SD'
            self.walkers = [
                SingleDetWalker(walker_opts,
                                system,
                                trial,
                                index=w,
                                nprop_tot=nprop_tot,
                                nbp=nbp) for w in range(qmc.nwalkers)
            ]
            self.buff_size = self.walkers[0].buff_size
            if nbp is not None:
                if verbose:
                    print("# Performing back propagation.")
                    print("# Number of steps in imaginary time: {:}.".format(
                        nbp))
                self.buff_size += self.walkers[0].field_configs.buff_size
            self.walker_buffer = numpy.zeros(self.buff_size,
                                             dtype=numpy.complex128)
        if system.name == "Generic" or system.name == "UEG":
            dtype = complex
        else:
            dtype = int
        self.pcont_method = get_input_value(walker_opts,
                                            'population_control',
                                            default='comb')
        self.min_weight = walker_opts.get('min_weight', 0.1)
        self.max_weight = walker_opts.get('max_weight', 4.0)
        if verbose:
            print("# Using {} population control "
                  "algorithm.".format(self.pcont_method))
            mem = float(self.walker_buffer.nbytes) / (1024.0**3)
            print("# Buffer size for communication: {:13.8e} GB".format(mem))
            if mem > 2.0:
                # TODO: FDM FIX THIS
                print(" # Warning: Walker buffer size > 2GB. May run into MPI"
                      "issues.")
        if not self.walker_type == "thermal":
            walker_size = 3 + self.walkers[0].phi.size
        if self.write_freq > 0:
            self.write_restart = True
            self.dsets = []
            with h5py.File(self.write_file, 'w', driver='mpio',
                           comm=comm) as fh5:
                for i in range(self.ntot_walkers):
                    fh5.create_dataset('walker_%d' % i, (walker_size, ),
                                       dtype=numpy.complex128)

        else:
            self.write_restart = False
        if self.read_file is not None:
            if verbose:
                print("# Reading walkers from %s file series." %
                      self.read_file)
            self.read_walkers(comm)
        self.target_weight = qmc.ntot_walkers
        self.nw = qmc.nwalkers
        self.set_total_weight(qmc.ntot_walkers)
Beispiel #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
Beispiel #8
0
    def __init__(self, comm, options=None, system=None,
                 trial=None, parallel=False, verbose=None):
        if verbose is not None:
            self.verbosity = verbose
            if comm.rank != 0:
                self.verbosity = 0
            verbose = verbose > 0 and comm.rank == 0
        else:
            self.verbosity = 0
            verbose = False
        qmc_opts = get_input_value(options, 'qmc', default={},
                                   alias=['qmc_options'],
                                   verbose=self.verbosity>1)
        if qmc_opts.get('beta') is None:
            print("Shouldn't call ThermalAFQMC without specifying beta")
            exit()
        # 1. Environment attributes
        if comm.rank == 0:
            self.uuid = str(uuid.uuid1())
            get_sha1 = options.get('get_sha1', True)
            if get_sha1:
                self.sha1, self.branch = get_git_revision_hash()
            else:
                self.sha1 = 'None'
            if verbose:
                self.sys_info = get_sys_info(self.sha1, self.branch, self.uuid, comm.size)
        # Hack - this is modified later if running in parallel on
        # initialisation.
        self.root = comm.rank == 0
        self.nprocs = comm.size
        self.rank = comm.rank
        self._init_time = time.time()
        self.run_time = time.asctime(),
        # 2. Calculation objects.
        sys_opts = options.get('system')
        if system is not None:
            self.system = system
        else:
            sys_opts = get_input_value(options, 'system', default={},
                                       alias=['model'],
                                       verbose=self.verbosity>1)
            sys_opts['thermal'] = True
            self.system = get_system(sys_opts=sys_opts, verbose=verbose)
        self.qmc = QMCOpts(qmc_opts, self.system, verbose)
        self.qmc.rng_seed = set_rng_seed(self.qmc.rng_seed, comm)
        self.qmc.ntime_slices = int(round(self.qmc.beta/self.qmc.dt))
        # Overide whatever's in the input file due to structure of FT algorithm.
        self.qmc.nsteps = 1
        self.qmc.total_steps = self.qmc.nblocks
        if verbose:
            print("# Number of time slices = %i"%self.qmc.ntime_slices)
        self.cplx = True
        if trial is not None:
            self.trial = trial
        else:
            trial_opts = get_input_value(options, 'trial', default={},
                                         alias=['trial_density'],
                                         verbose=self.verbosity>1)
            self.trial = get_trial_density_matrices(comm, trial_opts,
                                                    self.system, self.cplx,
                                                    self.qmc.beta,
                                                    self.qmc.dt, verbose)

        self.qmc.ntot_walkers = self.qmc.nwalkers
        # Number of walkers per core/rank.
        self.qmc.nwalkers = int(self.qmc.nwalkers/comm.size)
        # Total number of walkers.
        self.qmc.ntot_walkers = self.qmc.nwalkers * self.nprocs
        if self.qmc.nwalkers == 0:
            if comm.rank == 0 and verbose:
                print("# WARNING: Not enough walkers for selected core count.")
                print("#          There must be at least one walker per core set in the "
                      "input file.")
                print("#          Setting one walker per core.")
            self.qmc.nwalkers = 1
            self.qmc.ntot_walkers = self.qmc.nwalkers * self.nprocs
        wlk_opts = get_input_value(options, 'walkers', default={},
                                   alias=['walker', 'walker_opts'],
                                   verbose=self.verbosity>1)
        self.walk = Walkers(wlk_opts, self.system, self.trial,
                            self.qmc, verbose)
        lowrank = self.walk.walkers[0].lowrank
        prop_opts = get_input_value(options, 'propagator', default={},
                                    verbose=self.verbosity>1)
        self.propagators = get_propagator(prop_opts, self.qmc, self.system,
                                          self.trial,
                                          verbose=verbose,
                                          lowrank=lowrank)

        self.tsetup = time.time() - self._init_time
        est_opts = get_input_value(options, 'estimators', default={},
                                   alias=['estimates'],
                                   verbose=self.verbosity>1)
        self.estimators = (
            Estimators(est_opts, self.root, self.qmc, self.system,
                       self.trial, self.propagators.BT_BP, verbose)
        )
        # stabilization frequency might be updated due to wrong user input
        if self.qmc.nstblz != self.propagators.nstblz:
            self.propagators.nstblz = self.qmc.nstblz
        if comm.rank == 0:
            json_string = to_json(self)
            self.estimators.json_string = json_string
            self.estimators.dump_metadata()
            if verbose:
                self.estimators.estimators['mixed'].print_key()
                self.estimators.estimators['mixed'].print_header()