Esempio n. 1
0
 def __init__(self, nfields, nprop_tot, nbp, dtype):
     self.configs = numpy.zeros(shape=(nprop_tot, nfields), dtype=dtype)
     self.cos_fac = numpy.zeros(shape=(nprop_tot, 1), dtype=float)
     self.weight_fac = numpy.zeros(shape=(nprop_tot, 1), dtype=complex)
     self.tot_wfac = 1.0 + 0j
     self.step = 0
     # need to account for first iteration and how we iterate
     self.block = -1
     self.ib = 0
     self.nfields = nfields
     self.nbp = nbp
     self.nprop_tot = nprop_tot
     self.nblock = nprop_tot // nbp
     self.buff_names, self.buff_size = get_numeric_names(self.__dict__)
Esempio n. 2
0
 def __init__(self,
              walker_opts,
              system,
              trial,
              index=0,
              weights='zeros',
              verbose=False,
              nprop_tot=None,
              nbp=None):
     if verbose:
         print("# Setting up MultiDetWalker object.")
     self.weight = walker_opts.get('weight', 1.0)
     self.unscaled_weight = self.weight
     self.alive = 1
     self.phase = 1 + 0j
     self.nup = system.nup
     self.E_L = 0.0
     self.phi = copy.deepcopy(trial.init)
     self.ndets = trial.psi.shape[0]
     dtype = numpy.complex128
     # This stores an array of overlap matrices with the various elements of
     # the trial wavefunction.
     self.inv_ovlp = [
         numpy.zeros(shape=(self.ndets, system.nup, system.nup),
                     dtype=dtype),
         numpy.zeros(shape=(self.ndets, system.ndown, system.ndown),
                     dtype=dtype)
     ]
     # TODO: RENAME to something less like weight
     if weights == 'zeros':
         self.weights = numpy.zeros(self.ndets, dtype=dtype)
     else:
         self.weights = numpy.ones(self.ndets, dtype=dtype)
     self.ovlps = numpy.zeros(self.ndets, dtype=dtype)
     # Compute initial overlap. Avoids issues with singular matrices for
     # PHMSD.
     self.ot = self.overlap_direct(trial)
     # TODO: fix name.
     self.ovlp = self.ot
     self.hybrid_energy = 0.0
     if verbose:
         print(
             "# Initial overlap of walker with trial wavefunction: {:13.8e}"
             .format(self.ot.real))
     # Green's functions for various elements of the trial wavefunction.
     self.Gi = numpy.zeros(shape=(self.ndets, 2, system.nbasis,
                                  system.nbasis),
                           dtype=dtype)
     # Actual green's function contracted over determinant index in Gi above.
     # i.e., <psi_T|c_i^d c_j|phi>
     self.G = numpy.zeros(shape=(2, system.nbasis, system.nbasis),
                          dtype=dtype)
     # Contains overlaps of the current walker with the trial wavefunction.
     self.greens_function(trial)
     self.nb = system.nbasis
     self.nup = system.nup
     self.ndown = system.ndown
     # Historic wavefunction for back propagation.
     self.phi_old = copy.deepcopy(self.phi)
     # Historic wavefunction for ITCF.
     self.phi_init = copy.deepcopy(self.phi)
     # Historic wavefunction for ITCF.
     # self.phi_bp = copy.deepcopy(trial.psi)
     self.buff_names, self.buff_size = get_numeric_names(self.__dict__)
     if nbp is not None:
         self.field_configs = FieldConfig(system.nfields, nprop_tot, nbp,
                                          numpy.complex128)
     else:
         self.field_configs = None
Esempio n. 3
0
    def __init__(self, walker_opts, system, trial, verbose=False):
        self.weight = walker_opts.get('weight', 1.0)
        self.unscaled_weight = self.weight
        self.phase = 1.0 + 0.0j
        self.alive = True
        self.num_slices = trial.num_slices
        dtype = numpy.complex128
        self.G = numpy.zeros(trial.dmat.shape, dtype=dtype)
        self.nbasis = trial.dmat[0].shape[0]
        self.total_weight = 0
        self.stack_size = walker_opts.get('stack_size', None)
        max_diff_diag = numpy.linalg.norm(
            (numpy.diag(trial.dmat[0].diagonal()) - trial.dmat[0]))
        if max_diff_diag < 1e-10:
            self.diagonal_trial = True
            if verbose:
                print("# Trial density matrix is diagonal.")
        else:
            self.diagonal_trial = False
            if verbose:
                print("# Trial density matrix is not diagonal.")

        if self.stack_size == None:
            self.stack_size = trial.stack_size
        if (self.num_slices //
                self.stack_size) * self.stack_size != self.num_slices:
            if verbose:
                print("# Input stack size does not divide number of slices.")
            self.stack_size = update_stack(self.stack_size, self.num_slices,
                                           verbose)
        if self.stack_size > trial.stack_size:
            if verbose:
                print("# Walker stack size differs from that estimated from "
                      "trial density matrix.")
                print("# Be careful. cond(BT)**stack_size: %10.3e." %
                      (trial.cond**self.stack_size))
        self.stack_length = self.num_slices // self.stack_size
        if verbose:
            print("# Walker stack size: {}".format(self.stack_size))

        self.lowrank = walker_opts.get('low_rank', False)
        self.lowrank_thresh = walker_opts.get('low_rank_thresh', 1e-6)
        if verbose:
            print("# Using low rank trick: {}".format(self.lowrank))
        self.stack = PropagatorStack(self.stack_size,
                                     trial.num_slices,
                                     trial.dmat.shape[-1],
                                     dtype,
                                     trial.dmat,
                                     trial.dmat_inv,
                                     diagonal=self.diagonal_trial,
                                     lowrank=self.lowrank,
                                     thresh=self.lowrank_thresh)

        # Initialise all propagators to the trial density matrix.
        self.stack.set_all(trial.dmat)
        self.greens_function_qr_strat(trial)
        self.stack.G = self.G
        self.M0 = numpy.array([
            scipy.linalg.det(self.G[0], check_finite=False),
            scipy.linalg.det(self.G[1], check_finite=False)
        ])
        self.stack.ovlp = numpy.array([1.0 / self.M0[0], 1.0 / self.M0[1]])
        self.ot = 1.0

        # # temporary storage for stacks...
        I = numpy.identity(system.nbasis, dtype=dtype)
        One = numpy.ones(system.nbasis, dtype=dtype)
        self.Tl = numpy.array([I, I])
        self.Ql = numpy.array([I, I])
        self.Dl = numpy.array([One, One])
        self.Tr = numpy.array([I, I])
        self.Qr = numpy.array([I, I])
        self.Dr = numpy.array([One, One])

        self.hybrid_energy = 0.0
        if verbose:
            eloc = self.local_energy(system)
            P = one_rdm_from_G(self.G)
            nav = particle_number(P)
            print("# Initial walker energy: {} {} {}".format(*eloc))
            print("# Initial walker electron number: {}".format(nav))
        # self.buff_names = ['weight', 'G', 'unscaled_weight', 'phase', 'Tl',
        # 'Ql', 'Dl', 'Tr', 'Qr', 'Dr', 'M0']
        self.buff_names, self.buff_size = get_numeric_names(self.__dict__)
Esempio n. 4
0
    def __init__(self,
                 stack_size,
                 ntime_slices,
                 nbasis,
                 dtype,
                 BT=None,
                 BTinv=None,
                 diagonal=False,
                 averaging=False,
                 lowrank=True,
                 thresh=1e-6):

        self.time_slice = 0
        self.stack_size = stack_size
        self.ntime_slices = ntime_slices
        self.nbins = ntime_slices // self.stack_size
        self.diagonal_trial = diagonal
        self.averaging = averaging
        self.thresh = thresh

        self.lowrank = lowrank
        self.ovlp = numpy.asarray([1.0, 1.0])

        if self.lowrank:
            assert diagonal

        self.reortho = 1

        if self.nbins * self.stack_size < self.ntime_slices:
            print("stack_size must divide the total path length")
            assert self.nbins * self.stack_size == self.ntime_slices

        self.nbasis = nbasis
        self.dtype = dtype
        self.BT = BT
        self.BTinv = BTinv
        self.counter = 0
        self.block = 0
        # self.buff_size = (
        # 2+3*self.nbins*2*nbasis*nbasis + 2*nbasis*nbasis # ovlp,stack,left,right,G
        # + (4*2*nbasis*nbasis + 2*2*nbasis if self.lowrank else 0) # low rank
        # )

        self.stack = numpy.zeros(shape=(self.nbins, 2, nbasis, nbasis),
                                 dtype=dtype)
        self.left = numpy.zeros(shape=(self.nbins, 2, nbasis, nbasis),
                                dtype=dtype)
        self.right = numpy.zeros(shape=(self.nbins, 2, nbasis, nbasis),
                                 dtype=dtype)

        self.G = numpy.asarray([
            numpy.eye(self.nbasis, dtype=dtype),
            numpy.eye(self.nbasis, dtype=dtype)
        ])

        if self.lowrank:
            self.update_new = self.update_low_rank
        else:
            self.update_new = self.update_full_rank

        # Global block matrix
        if self.lowrank:
            self.Ql = numpy.zeros(shape=(2, nbasis, nbasis), dtype=dtype)
            self.Dl = numpy.zeros(shape=(2, nbasis), dtype=dtype)
            self.Tl = numpy.zeros(shape=(2, nbasis, nbasis), dtype=dtype)

            self.Qr = numpy.zeros(shape=(2, nbasis, nbasis), dtype=dtype)
            self.Dr = numpy.zeros(shape=(2, nbasis), dtype=dtype)
            self.Tr = numpy.zeros(shape=(2, nbasis, nbasis), dtype=dtype)

            self.CT = numpy.zeros(shape=(2, nbasis, nbasis), dtype=dtype)
            self.theta = numpy.zeros(shape=(2, nbasis, nbasis), dtype=dtype)
            self.mT = nbasis

        self.buff_names, self.buff_size = get_numeric_names(self.__dict__)
        # set all entries to be the identity matrix
        self.reset()
Esempio n. 5
0
 def __init__(self,
              walker_opts,
              system,
              trial,
              index=0,
              nprop_tot=None,
              nbp=None):
     self.weight = walker_opts.get('weight', 1.0)
     self.unscaled_weight = self.weight
     self.phase = 1 + 0j
     self.alive = 1
     self.phi = trial.init.copy()
     # JOONHO randomizing the guess
     # self.phi = numpy.random.rand([system.nbasis,system.ne])
     self.inv_ovlp = [0.0, 0.0]
     self.nup = system.nup
     self.ndown = system.ndown
     self.inverse_overlap(trial)
     self.G = numpy.zeros(shape=(2, system.nbasis, system.nbasis),
                          dtype=trial.psi.dtype)
     self.Gmod = [
         numpy.zeros(shape=(system.nup, system.nbasis),
                     dtype=trial.psi.dtype),
         numpy.zeros(shape=(system.ndown, system.nbasis),
                     dtype=trial.psi.dtype)
     ]
     self.greens_function(trial)
     self.total_weight = 0.0
     self.ot = 1.0
     # interface consistency
     self.ots = numpy.zeros(1, dtype=numpy.complex128)
     self.E_L = local_energy(system, self.G, self.Gmod)[0].real
     # walkers overlap at time tau before backpropagation occurs
     self.ot_bp = 1.0
     # walkers weight at time tau before backpropagation occurs
     self.weight_bp = self.weight
     # Historic wavefunction for back propagation.
     self.phi_old = copy.deepcopy(self.phi)
     self.hybrid_energy = 0.0
     # Historic wavefunction for ITCF.
     self.phi_right = copy.deepcopy(self.phi)
     self.weights = numpy.array([1.0])
     # Number of propagators to store for back propagation / ITCF.
     num_propg = walker_opts.get('num_propg', 1)
     # if system.name == "Generic":
     # self.stack = PropagatorStack(self.stack_size, num_propg,
     # system.nbasis, trial.psi.dtype,
     # BT=None, BTinv=None,
     # diagonal=False)
     try:
         excite = trial.excite_ia
     except AttributeError:
         excite = None
     if excite is not None:
         self.ia = trial.excite_ia
         self.reortho = self.reortho_excite
         self.trial_buff = numpy.copy(trial.full_orbs[:, :self.ia[1] + 1])
     if nbp is not None:
         self.field_configs = FieldConfig(system.nfields, nprop_tot, nbp,
                                          numpy.complex128)
     else:
         self.field_configs = None
     self.buff_names, self.buff_size = get_numeric_names(self.__dict__)