def test_random_cold(): np.random.seed(789) ising = Simulation.Ising(16, T=1e-5, initial_board='random') for _ in tqdm(range(int(1e5))): ising.step() assert np.isclose(ising.average_energy, -2) assert np.abs(ising.average_magnetization) - 1 <= (2 * ising.spins_board.std())
def test_magnetised_hot(): np.random.seed(789) ising = Simulation.Ising(32, T=900, initial_board='magnetised') E_start = ising.energy for _ in tqdm(range(int(1e5))): ising.step() assert ising.energy > E_start assert np.abs(ising.average_magnetization) < (2 * ising.spins_board.std())
def test_magnetised_cold(): np.random.seed(789) ising = Simulation.Ising(32, T=1e-5, initial_board='magnetised') E_avg_start = ising.average_energy for _ in tqdm(range(int(1e5))): ising.step() assert np.isclose(ising.average_energy, E_avg_start) assert np.abs(ising.average_magnetization) - 1 <= (2 * ising.spins_board.std())
def test_magnetised(): ising = Simulation.Ising(32, initial_board='magnetised') assert np.abs(ising.magnetization) == 32**2 assert np.isclose(ising.average_energy, -2)
def test_twosides(): small_ising = Simulation.Ising(32, initial_board='two sides') big_ising = Simulation.Ising(64, initial_board='two sides') assert np.abs(small_ising.magnetization) == np.abs( big_ising.magnetization) == 0
def test_checkerboard(): ising = Simulation.Ising(32, initial_board='checkerboard') assert np.abs(ising.magnetization) == 0 assert np.isclose(ising.average_energy, 2)
def __init__(self, master=None, *args, **kwargs): tk.Frame.__init__(self, master, *args, **kwargs) last = 100 self.working = False self.Time = [] self.N = 32 self.top_container = tk.Frame(self) self.top_container.pack(side="top", fill="both", expand=True) self.ising = Simulation.Ising(32) self.spins_grid = SpinsGrid(self.top_container, self.ising) self.spins_grid.grid(row=0, column=1, sticky="nsew") # Parametry do zmian programu self.N = self.ising.spins_board.shape[0] self.T = self.ising.T self.M = self.ising.outM self.plotsFrame = PlotsFrame(self, last) plt.ion() control_module = tk.Frame(self.top_container, width=400, height=400) control_module.grid(row=0, column=1, sticky="nsew") f2 = tk.Frame(control_module, width=400, height=400) f2.pack(side=tk.TOP, fill=tk.X) #Ustawienie tekstow parametrow razem z wypisaniem obecnych wartowsci self.strtemp = tk.StringVar() self.strtemp.set('Temp: ' + str('%.6f' % (self.ising.T))) self.templabel = tk.Label(f2, text=self.strtemp.get()) self.templabel.grid(row=0, column=0, sticky=tk.W, padx=20, pady=20) self.strMag = tk.StringVar() self.strMag.set('Outside_Mag: ' + str('%.2f' % (self.ising.outM))) self.maglabel = tk.Label(f2, text=self.strMag.get()) self.maglabel.grid(row=1, column=0, sticky=tk.W, padx=20, pady=20) self.strN = tk.StringVar() self.strN.set('N: ' + str(self.N)) self.Nlabel = tk.Label(f2, text=self.strN.get()) self.Nlabel.grid(row=2, column=0, sticky=tk.W, padx=20, pady=20) self.e1 = tk.Entry(f2) self.e2 = tk.Entry(f2) self.e3 = tk.Entry(f2) self.e1.grid(row=0, column=1, padx=40, pady=20) self.e2.grid(row=1, column=1, padx=40, pady=20) self.e3.grid(row=2, column=1, padx=40, pady=20) self.strspin = "Lista plansz" self.spinlabel = tk.Label(f2, text=self.strspin) self.spinlabel.grid(row=3, column=0, sticky=tk.W, padx=20, pady=10) self.listbox = tk.Listbox(f2, height=5) self.listbox.grid(row=3, column=1, sticky=tk.W, padx=40, pady=10) self.listbox.insert(1, Simulation.board_setups[0]) self.listbox.insert(2, Simulation.board_setups[1]) self.listbox.insert(3, Simulation.board_setups[2]) self.listbox.insert(4, Simulation.board_setups[3]) self.listbox.insert(5, Simulation.board_setups[4]) self.listbox.selection_set(0) self.listbox.see(0) self.listbox.activate(0) self.listbox.selection_anchor(0) # ErrorLabel, w przypadku wpisania zlej wartosci self.errortext = tk.StringVar() self.errortext.set("") self.errorlabel = tk.Label(control_module, text=self.errortext.get()) self.errorlabel.pack(side=tk.TOP, fill=tk.X, padx=20, pady=0) # Przyciski self.setbutton = tk.Button(control_module, text="Set New Parameters", command=lambda: self.set_new_parameters()) self.setbutton.pack(side=tk.TOP, fill=tk.X, padx=20, pady=20) self.plotbutton = tk.Button(control_module, text="Plot", command=lambda: self.click()) self.plotbutton.pack(side=tk.TOP, fill=tk.X, padx=20, pady=10)