コード例 #1
0
ファイル: Ising_magnet.py プロジェクト: NParhar/Spin-Flip
    def _flip(self, int_low, int_high, no_of_int):
        """ This is method used to calcualte if the spins flip or not"""
        #random test.py tests the randomness
        list_of_powers=np.random.random_integers(int_low,int_high, size=(no_of_int))
        list_of_spins_and_counts_a = ising_magnet_2d_Function()._get_spins(list_of_powers)
        list_of_spins= list_of_spins_and_counts_a[0]
        no_of_up = list_of_spins_and_counts_a[1]
        no_of_down = list_of_spins_and_counts_a[2]

        range_J=np.random.randint(1,101, size=None)
        J = np.random.randint(-range_J,range_J, size=None)
        list_of_delta_E = ising_magnet_2d_Function()._get_delta_energy(list_of_spins,J)
        
        list_of_prob_and_new_spins = ising_magnet_2d_Function()._get_probability_to_spin_flip(list_of_spins,list_of_delta_E)
        prob_spin_to_flip=list_of_prob_and_new_spins[0]
        new_list_of_spins=list_of_prob_and_new_spins[1]

        list_of_counts=ising_magnet_2d_Function()._get_counts(new_list_of_spins)
        no_of_up_new = list_of_counts[0]
        no_of_down_new = list_of_counts[1]
        

        no_of_spin = len(prob_spin_to_flip)
        no_of_spin_flipped = 0
        for i in range(len(prob_spin_to_flip)):
            if prob_spin_to_flip[i]=="YES":
                no_of_spin_flipped+=1
        print("ORIGINAL LIST OF SPINS      : ",list_of_spins)
        print("PROBABILITY FOR SPIN TO FLIP: ",prob_spin_to_flip)
        print("NEW LIST OF SPINS           : ",new_list_of_spins)
        print("ORIGINAL UP:DOWN            : ", no_of_up,":",no_of_down)
        print("NEW UP:DOWN                 : ", no_of_up_new,":",no_of_down_new)
        print("FLIPPED SPINS/ SPINS        : ", no_of_spin_flipped,"/", no_of_spin)
        plot_x=0
        plot_y=0
        if no_of_up>=no_of_down:
            plot_x+=no_of_up
            plot_y+=no_of_up_new
        else: 
            plot_x+=no_of_down
            plot_y+=no_of_down_new
        print(plot_x, plot_y)
        return_values = []
        return_values.append(plot_x)
        return_values.append(plot_y)
        return(return_values)
コード例 #2
0
ファイル: testing.py プロジェクト: NParhar/Spin-Flip
def test__get_counts():
    assert ising_magnet_2d_Function()._get_counts([1, 1, 1, 1,
                                                   1]) == [5, 0
                                                           ], "Should be [5,0]"
コード例 #3
0
ファイル: testing.py プロジェクト: NParhar/Spin-Flip
def test__get_delta_energy():
    assert ising_magnet_2d_Function()._get_delta_energy(
        [1, -1, 1, -1, 1], 5) == [0, -20, 0, -20,
                                  0], "Should be [0,-20,0,-20,0]"
コード例 #4
0
ファイル: testing.py プロジェクト: NParhar/Spin-Flip
def test__get_probability_to_spin_flip():
    assert ising_magnet_2d_Function()._get_probability_to_spin_flip(
        [1, -1, 1, -1, 1],
        [0, -20, 0, -20, 0]) == [["NO", "YES", "NO", "YES", "NO"],
                                 [1, 1, 1, 1, 1]], "Should be all the same"
コード例 #5
0
ファイル: testing.py プロジェクト: NParhar/Spin-Flip
def test__get_spins():
    assert ising_magnet_2d_Function()._get_spins(
        [0, 1, 2, 3, 4]) == [[1, -1, 1, -1, 1], 3,
                             2], "Should be [[1,-1,1,-1,1],3,2]"