Esempio n. 1
0
    def __init__(self, h, loc, sign=True):
        # Initiates a Walker object.
        self.loc = loc
        if sign:
            self.signed_num = 1
        else:
            self.signed_num = -1
        self.diag = load_data.get_entry(h, self.loc.occup, self.loc.occup)

        # For test only.
        if global_var.test_print_flag:
            print "Created walker at  ",
            print self.loc.occup
Esempio n. 2
0
    def die(self, h):
        # The death/cloning process of one parent on this walker site.
        prob = global_var.tau * (
            load_data.get_entry(h, self.loc.occup, self.loc.occup) - h.ref_energy - global_var.shift
        )
        rand_val = random.random()

        # For test only.
        if global_var.test_print_flag:
            print "Start of dying step"
            print "Probability is  ",
            print prob
            print "Random number is",
            print rand_val

        if prob < 0:
            # Cloning.

            # For test only.
            if global_var.test_print_flag:
                print "In fact it is cloning"

            prob = -prob
            clone_num = int(prob)
            if rand_val < prob - clone_num:
                # Another cloning is successful.

                # For test only.
                if global_var.test_print_flag:
                    print "One walker is cloned."

                clone_num += 1
            if self.signed_num > 0:
                self.signed_num += clone_num
            else:
                self.signed_num -= clone_num
        else:
            # Death.
            if rand_val < prob:
                # Dead.

                # For test only.
                if global_var.test_print_flag:
                    print "One walker dies."

                if self.signed_num > 0:
                    self.signed_num -= 1
                else:
                    self.signed_num += 1
            else:

                # For test only.
                if global_var.test_print_flag:
                    print "No one dies."

                    # For test only.
        if global_var.test_print_flag:
            print "Number of living walkers on this site:",
            print self.signed_num
            print "End of dying step"
            print ""
Esempio n. 3
0
    def spawn(self, h):
        # Spawning of one parent on this walker site.
        # Returns a Walker object named child.
        select_prob, spawn_to = self.loc.excite(h.basis_list, "r")
        child = None
        child_num = 0

        # For test only.
        if global_var.test_print_flag:
            print "Start of spawning step"
            print "Attempt to spawn at",
            print spawn_to.occup

            # Gets the probability of spawning.
            # It may be larger than unity, which may imply multiple spawning.
        prob = global_var.tau * load_data.get_entry(h, self.loc.occup, spawn_to.occup) / select_prob
        if prob < 0:
            # Children have the same sign as their parent.
            child_sign = self.signed_num > 0
            prob = -prob
        else:
            # Children have the opposite sign as their parent.
            child_sign = self.signed_num < 0
        child_num = int(prob)
        if child_num > 0:
            # Spawns child_num children successfully.
            child = Walker(h, spawn_to)
            child.signed_num = child_num
            if not child_sign:
                child.signed_num = -child.signed_num
        rand_val = random.random()

        # For test only.
        if global_var.test_print_flag:
            for i in range(child_num):
                print "Probability is  ",
                print prob - i
                print "Spawn successfully"
            print "Probability is  ",
            print prob - child_num
            print "Random number is",
            print rand_val

        if rand_val < prob - child_num:
            # Another spawning is successful.

            # For test only.
            if global_var.test_print_flag:
                print "Spawn successfully"

            if child_num == 0:
                child = Walker(h, spawn_to, child_sign)
            elif child_sign:
                child.signed_num += 1
            else:
                child.signed_num -= 1
        else:
            # Spawning is unsuccessful.

            # For test only.
            if global_var.test_print_flag:
                print "Spawn unsuccessfully"

                # For test only.
        if global_var.test_print_flag:
            if child != None:
                print "Number of living walkers on this site:",
                print child.signed_num
            print "End of spawning step"
            print ""

        return child