Jump to content

Rep:Mod:DMS3053-3

From ChemWiki
   import time
   import IsingLattice as il
   import numpy as np
   from math import sqrt
   #Uses a large lattice (25 x 25) to give more accurate time data
   n_rows = 25
   n_cols = 25
   time_cycles = 1000 # Number of times the time measurement is made
   lattice = il.IsingLattice(n_rows, n_cols)
   times = []
   for i in range(time_cycles): # Runs the time measurement time_cycles times
       start_time = time.clock()
       for j in range(2000):
           lattice.montecarlostep(1.0)
       end_time = time.clock()
       elapsed_time = end_time - start_time
       times.append(elapsed_time) # Appends the measured time to a list of times
       print(i)
   average_time = np.mean(times) # Calculates the mean average of all times in the list
   print("Average time = %f" % average_time)
   standard_error = np.std(times) / sqrt(time_cycles) # Calculates the standard error of the times
   print("Standard error = %f" % standard_error)