Example #1
0
 def setUp(self):
     self.natoms = 4
     self.k = 1
     self.Emax = 2  #this choice is fundamentally arbitrary, it's only used to generate the initial configuration
     #self.temperatures = [0.2,0.27,0.362,0.487,0.65,0.88,1.18,1.6]
     self.temperatures = [0.2, 0.362, 0.65, 1.18]
     self.stepsize = 1
     self.niter = 2e6
     self.adjustf = 0.9
     self.adjust_niter = 0.3 * self.niter
     self.radius = 1e10
     self.tolerance = 2e-1
     self.bdim = 3
     self.ndim = self.natoms * self.bdim
     self.origin = np.zeros(self.ndim)
     self.seeds = dict(takestep=42, metropolis=44)
     self.potential = Harmonic(self.origin,
                               self.k,
                               bdim=self.bdim,
                               com=False)
     self.mcrunner = Metropolis_MCrunner(self.potential,
                                         self.origin,
                                         1,
                                         self.stepsize,
                                         self.niter,
                                         hEmax=100,
                                         adjustf=self.adjustf,
                                         adjustf_niter=self.adjust_niter,
                                         radius=self.radius,
                                         bdim=self.bdim,
                                         single=False,
                                         seeds=self.seeds)
Example #2
0
    def test_heat_capacity_2D(self):
        self.bdim = 2
        self.ndim = self.natoms * self.bdim
        self.origin = np.zeros(self.ndim)
        self.potential = Harmonic(self.origin,
                                  self.k,
                                  bdim=self.bdim,
                                  com=False)

        print "2D"
        for T in self.temperatures:

            mcrunner = Metropolis_MCrunner(self.potential,
                                           self.origin,
                                           T,
                                           self.stepsize,
                                           self.niter,
                                           hEmax=100,
                                           adjustf=self.adjustf,
                                           adjustf_niter=self.adjust_niter,
                                           radius=self.radius,
                                           bdim=self.bdim)
            #MCMC
            mcrunner.run()
            #collect the results
            binenergy, hist, mean, variance = mcrunner.get_histogram()

            cv = variance / (T * T)
            cv_true = self.natoms * self.bdim / 2.0

            print cv, cv_true

            self.assertLess(abs(cv - cv_true), self.tolerance,
                            'failed for temperature {}, cv = {}'.format(T, cv))
Example #3
0
    def test_heat_capacity_2D_com(self):
        self.bdim = 2
        self.ndim = self.natoms * self.bdim
        self.origin = np.zeros(self.ndim)
        potential = Harmonic(self.origin, self.k, bdim=self.bdim, com=True)
        #self.start_coords = vector_random_uniform_hypersphere(self.ndim) * np.sqrt(2*self.Emax) #coordinates sampled from Pow(ndim)

        print "2D com"
        for T in self.temperatures:

            mcrunner = Metropolis_MCrunner(potential,
                                           self.origin,
                                           T,
                                           self.stepsize,
                                           self.niter,
                                           hEmax=100,
                                           adjustf=self.adjustf,
                                           adjustf_niter=self.adjust_niter,
                                           radius=self.radius,
                                           bdim=self.bdim)
            #MCMC
            mcrunner.run()
            #collect the results
            binenergy, hist, mean, variance = mcrunner.get_histogram()

            cv = variance / (T * T)
            cv_true = (self.natoms - 1) * self.bdim / 2.0

            print cv, cv_true

            self.assertLess(abs(cv - cv_true), self.tolerance,
                            'failed for temperature {}, cv = {}'.format(T, cv))
Example #4
0
 def test_heat_capacity_3D_com(self):
     self.bdim = 3
     self.ndim = self.natoms*self.bdim
     self.origin = np.zeros(self.ndim)
     potential = Harmonic(self.origin, self.k, bdim=self.bdim, com=True)
     mcrunner = Metropolis_MCrunner(potential, self.origin, 1, self.stepsize, self.niter, hEmax = 100, 
                                        adjustf = self.adjustf, adjustf_niter = self.adjust_niter, radius=self.radius, 
                                        bdim=self.bdim, seeds=self.seeds)
     mcrunner.run()
                     
     print "3D com"
     for T in self.temperatures:
                     
         mcrunner = Metropolis_MCrunner(potential, self.origin, T, self.stepsize, self.niter, hEmax = 100, 
                                        adjustf = self.adjustf, adjustf_niter = self.adjust_niter, radius=self.radius, 
                                        bdim=self.bdim, seeds=self.seeds)
         #MCMC 
         mcrunner.run()
         #collect the results
         binenergy, hist, mean, variance = mcrunner.get_histogram()
         
         cv =  variance/(T*T)
         cv_true = (self.natoms-1)*self.bdim/2.0
         
         print cv, cv_true
         
         self.assertLess(abs(cv-cv_true),self.tolerance,'failed for temperature {}, cv = {}'.format(T,cv))
Example #5
0
 def test_heat_capacity_2D_com(self):
     self.bdim = 2
     self.ndim = self.natoms*self.bdim
     self.origin = np.zeros(self.ndim)
     potential = Harmonic(self.origin,self.k, bdim=self.bdim,com=True)
     #self.start_coords = vector_random_uniform_hypersphere(self.ndim) * np.sqrt(2*self.Emax) #coordinates sampled from Pow(ndim)
                     
     print "2D com"
     for T in self.temperatures:
                     
         mcrunner = Metropolis_MCrunner(potential, self.origin, T, self.stepsize, self.niter, hEmax = 100, 
                                        adjustf = self.adjustf, adjustf_niter = self.adjust_niter, radius=self.radius, 
                                        bdim=self.bdim)
         #MCMC 
         mcrunner.run()
         #collect the results
         binenergy, hist, mean, variance = mcrunner.get_histogram()
         
         cv =  variance/(T*T)
         cv_true = (self.natoms-1)*self.bdim/2.0
         
         print cv, cv_true
         
         self.assertLess(abs(cv-cv_true),self.tolerance,'failed for temperature {}, cv = {}'.format(T,cv))
Example #6
0
 def setUp(self):
     self.natoms = 4
     self.k=1
     self.Emax = 2 #this choice is fundamentally arbitrary, it's only used to generate the initial configuration
     #self.temperatures = [0.2,0.27,0.362,0.487,0.65,0.88,1.18,1.6]
     self.temperatures = [0.2, 0.362, 0.65, 1.18]
     self.stepsize = 1
     self.niter = 2e6
     self.adjustf = 0.9
     self.adjust_niter = 0.3 * self.niter
     self.radius = 1e10
     self.tolerance = 2e-1
     self.bdim = 3
     self.ndim = self.natoms * self.bdim
     self.origin = np.zeros(self.ndim)
     self.potential = Harmonic(self.origin, self.k, bdim=self.bdim, com=False)
     self.mcrunner = Metropolis_MCrunner(self.potential, self.origin, 1, self.stepsize, self.niter, hEmax = 100, 
                                        adjustf = self.adjustf, adjustf_niter = self.adjust_niter, radius=self.radius, 
                                        bdim=self.bdim, single=True)
Example #7
0
class TestMetropolisGlobal(unittest.TestCase):
    
    def setUp(self):
        self.natoms = 4
        self.k=1
        self.Emax = 2 #this choice is fundamentally arbitrary, it's only used to generate the initial configuration
        #self.temperatures = [0.2,0.27,0.362,0.487,0.65,0.88,1.18,1.6]
        self.temperatures = [0.2, 0.362, 0.65, 1.18]
        self.stepsize = 1
        self.niter = 2e6
        self.adjustf = 0.9
        self.adjust_niter = 0.3 * self.niter
        self.radius = 1e10
        self.tolerance = 2e-1
        self.bdim = 3
        self.ndim = self.natoms * self.bdim
        self.origin = np.zeros(self.ndim)
        self.seeds = dict(takestep=42, metropolis=44)
        self.potential = Harmonic(self.origin, self.k, bdim=self.bdim, com=False)
        self.mcrunner = Metropolis_MCrunner(self.potential, self.origin, 1, self.stepsize, self.niter, hEmax = 100, 
                                           adjustf = self.adjustf, adjustf_niter = self.adjust_niter, radius=self.radius, 
                                           bdim=self.bdim, single=False, seeds=self.seeds)
    
    def test_set_control(self):
        self.mcrunner.set_control(10)
        self.mcrunner.run()
        self.assertEqual(self.mcrunner.get_temperature(), self.mcrunner.temperature)
    
    def test_dump_histogram(self):
        self.mcrunner.run()
        mean, variance = self.mcrunner.dump_histogram("test_histogram.dat")
        data = np.genfromtxt("test_histogram.dat")
        #print data
        binenergy, hist, mean2, variance2 = self.mcrunner.get_histogram()
        self.assertListEqual(np.ndarray.tolist(binenergy), np.ndarray.tolist(data[:,0]))
        self.assertListEqual(np.ndarray.tolist(hist), np.ndarray.tolist(data[:,1]))
        self.assertEqual(mean, mean2)
        self.assertEqual(variance, variance2)
        count = self.mcrunner.histogram.get_count()
        self.assertEqual(count, 1400000)
    
    def test_heat_capacity_3D_com(self):
        self.bdim = 3
        self.ndim = self.natoms*self.bdim
        self.origin = np.zeros(self.ndim)
        potential = Harmonic(self.origin, self.k, bdim=self.bdim, com=True)
        mcrunner = Metropolis_MCrunner(potential, self.origin, 1, self.stepsize, self.niter, hEmax = 100, 
                                           adjustf = self.adjustf, adjustf_niter = self.adjust_niter, radius=self.radius, 
                                           bdim=self.bdim, seeds=self.seeds)
        mcrunner.run()
                        
        print "3D com"
        for T in self.temperatures:
                        
            mcrunner = Metropolis_MCrunner(potential, self.origin, T, self.stepsize, self.niter, hEmax = 100, 
                                           adjustf = self.adjustf, adjustf_niter = self.adjust_niter, radius=self.radius, 
                                           bdim=self.bdim, seeds=self.seeds)
            #MCMC 
            mcrunner.run()
            #collect the results
            binenergy, hist, mean, variance = mcrunner.get_histogram()
            
            cv =  variance/(T*T)
            cv_true = (self.natoms-1)*self.bdim/2.0
            
            print cv, cv_true
            
            self.assertLess(abs(cv-cv_true),self.tolerance,'failed for temperature {}, cv = {}'.format(T,cv))
    
    def test_heat_capacity_3D(self):
        self.bdim = 3
        self.ndim = self.natoms*self.bdim
        self.origin = np.zeros(self.ndim)
        potential = Harmonic(self.origin, self.k, bdim=self.bdim, com=False)
        
        print "3D"
        for T in self.temperatures:
                        
            mcrunner = Metropolis_MCrunner(potential, self.origin, T, self.stepsize, self.niter, hEmax = 100, 
                                           adjustf = self.adjustf, adjustf_niter = self.adjust_niter, radius=self.radius, 
                                           bdim=self.bdim, seeds=self.seeds)
            #MCMC 
            mcrunner.run()
            #collect the results
            binenergy, hist, mean, variance = mcrunner.get_histogram()
            
            cv =  variance/(T*T)
            cv_true = self.natoms*self.bdim/2.0
            
            print cv, cv_true
            
            self.assertLess(abs(cv-cv_true),self.tolerance,'failed for temperature {}, cv = {}'.format(T,cv))
    
    def test_heat_capacity_2D_com(self):
        self.bdim = 2
        self.ndim = self.natoms*self.bdim
        self.origin = np.zeros(self.ndim)
        potential = Harmonic(self.origin,self.k, bdim=self.bdim,com=True)
        #self.start_coords = vector_random_uniform_hypersphere(self.ndim) * np.sqrt(2*self.Emax) #coordinates sampled from Pow(ndim)
                        
        print "2D com"
        for T in self.temperatures:
                        
            mcrunner = Metropolis_MCrunner(potential, self.origin, T, self.stepsize, self.niter, hEmax = 100, 
                                           adjustf = self.adjustf, adjustf_niter = self.adjust_niter, radius=self.radius, 
                                           bdim=self.bdim, seeds=self.seeds)
            #MCMC 
            mcrunner.run()
            #collect the results
            binenergy, hist, mean, variance = mcrunner.get_histogram()
            
            cv =  variance/(T*T)
            cv_true = (self.natoms-1)*self.bdim/2.0
            
            print cv, cv_true
            
            self.assertLess(abs(cv-cv_true),self.tolerance,'failed for temperature {}, cv = {}'.format(T,cv))
    
    def test_heat_capacity_2D(self):
        self.bdim = 2
        self.ndim = self.natoms*self.bdim
        self.origin = np.zeros(self.ndim)
        self.potential = Harmonic(self.origin, self.k, bdim=self.bdim, com=False)
                        
        print "2D"
        for T in self.temperatures:
                        
            mcrunner = Metropolis_MCrunner(self.potential, self.origin, T, self.stepsize, self.niter, hEmax = 100, 
                                           adjustf = self.adjustf, adjustf_niter = self.adjust_niter, radius=self.radius, 
                                           bdim=self.bdim, seeds=self.seeds)
            #MCMC 
            mcrunner.run()
            #collect the results
            binenergy, hist, mean, variance = mcrunner.get_histogram()
            
            cv =  variance/(T*T)
            cv_true = self.natoms*self.bdim/2.0
            
            print cv, cv_true
            
            self.assertLess(abs(cv-cv_true),self.tolerance,'failed for temperature {}, cv = {}'.format(T,cv))
            
    def test_composite_moves(self):
        self.bdim = 2
        self.ndim = self.natoms*self.bdim
        self.origin = np.zeros(self.ndim)
        self.potential = Harmonic(self.origin, self.k, bdim=self.bdim, com=False)
Example #8
0
    natoms = 4
    bdim = 3
    k = 1
    origin = np.zeros(natoms * bdim)
    potential = Harmonic(origin, k, bdim=bdim, com=False)
    path = args.base_directory

    #Parallel Tempering
    temperature = 1.0
    stepsize = 1
    niter = 1e4
    mcrunner = Metropolis_MCrunner(potential,
                                   origin,
                                   temperature,
                                   stepsize,
                                   niter,
                                   hEmax=100,
                                   adjustf=0.9,
                                   adjustf_niter=3000,
                                   radius=100000,
                                   seeds=dict(metropolis=44, takestep=42))
    ptrunner = MPI_PT_RLhandshake(mcrunner,
                                  0.2,
                                  1.6,
                                  max_ptiter=501,
                                  pfreq=10,
                                  base_directory=path,
                                  verbose=False,
                                  suppress_histogram=False)
    ptrunner.run()
Example #9
0
class TestMetropolisGlobal(unittest.TestCase):
    def setUp(self):
        self.natoms = 4
        self.k = 1
        self.Emax = 2  #this choice is fundamentally arbitrary, it's only used to generate the initial configuration
        #self.temperatures = [0.2,0.27,0.362,0.487,0.65,0.88,1.18,1.6]
        self.temperatures = [0.2, 0.362, 0.65, 1.18]
        self.stepsize = 1
        self.niter = 2e6
        self.adjustf = 0.9
        self.adjust_niter = 0.3 * self.niter
        self.radius = 1e10
        self.tolerance = 2e-1
        self.bdim = 3
        self.ndim = self.natoms * self.bdim
        self.origin = np.zeros(self.ndim)
        self.seeds = dict(takestep=42, metropolis=44)
        self.potential = Harmonic(self.origin,
                                  self.k,
                                  bdim=self.bdim,
                                  com=False)
        self.mcrunner = Metropolis_MCrunner(self.potential,
                                            self.origin,
                                            1,
                                            self.stepsize,
                                            self.niter,
                                            hEmax=100,
                                            adjustf=self.adjustf,
                                            adjustf_niter=self.adjust_niter,
                                            radius=self.radius,
                                            bdim=self.bdim,
                                            single=False,
                                            seeds=self.seeds)

    def test_set_control(self):
        self.mcrunner.set_control(10)
        self.mcrunner.run()
        self.assertEqual(self.mcrunner.get_temperature(),
                         self.mcrunner.temperature)

    def test_dump_histogram(self):
        self.mcrunner.run()
        mean, variance = self.mcrunner.dump_histogram("test_histogram.dat")
        data = np.genfromtxt("test_histogram.dat")
        #print data
        binenergy, hist, mean2, variance2 = self.mcrunner.get_histogram()
        self.assertListEqual(np.ndarray.tolist(binenergy),
                             np.ndarray.tolist(data[:, 0]))
        self.assertListEqual(np.ndarray.tolist(hist),
                             np.ndarray.tolist(data[:, 1]))
        self.assertEqual(mean, mean2)
        self.assertEqual(variance, variance2)
        count = self.mcrunner.histogram.get_count()
        self.assertEqual(count, 1400000)

    def test_heat_capacity_3D_com(self):
        self.bdim = 3
        self.ndim = self.natoms * self.bdim
        self.origin = np.zeros(self.ndim)
        potential = Harmonic(self.origin, self.k, bdim=self.bdim, com=True)
        mcrunner = Metropolis_MCrunner(potential,
                                       self.origin,
                                       1,
                                       self.stepsize,
                                       self.niter,
                                       hEmax=100,
                                       adjustf=self.adjustf,
                                       adjustf_niter=self.adjust_niter,
                                       radius=self.radius,
                                       bdim=self.bdim,
                                       seeds=self.seeds)
        mcrunner.run()

        print "3D com"
        for T in self.temperatures:

            mcrunner = Metropolis_MCrunner(potential,
                                           self.origin,
                                           T,
                                           self.stepsize,
                                           self.niter,
                                           hEmax=100,
                                           adjustf=self.adjustf,
                                           adjustf_niter=self.adjust_niter,
                                           radius=self.radius,
                                           bdim=self.bdim,
                                           seeds=self.seeds)
            #MCMC
            mcrunner.run()
            #collect the results
            binenergy, hist, mean, variance = mcrunner.get_histogram()

            cv = variance / (T * T)
            cv_true = (self.natoms - 1) * self.bdim / 2.0

            print cv, cv_true

            self.assertLess(abs(cv - cv_true), self.tolerance,
                            'failed for temperature {}, cv = {}'.format(T, cv))

    def test_heat_capacity_3D(self):
        self.bdim = 3
        self.ndim = self.natoms * self.bdim
        self.origin = np.zeros(self.ndim)
        potential = Harmonic(self.origin, self.k, bdim=self.bdim, com=False)

        print "3D"
        for T in self.temperatures:

            mcrunner = Metropolis_MCrunner(potential,
                                           self.origin,
                                           T,
                                           self.stepsize,
                                           self.niter,
                                           hEmax=100,
                                           adjustf=self.adjustf,
                                           adjustf_niter=self.adjust_niter,
                                           radius=self.radius,
                                           bdim=self.bdim,
                                           seeds=self.seeds)
            #MCMC
            mcrunner.run()
            #collect the results
            binenergy, hist, mean, variance = mcrunner.get_histogram()

            cv = variance / (T * T)
            cv_true = self.natoms * self.bdim / 2.0

            print cv, cv_true

            self.assertLess(abs(cv - cv_true), self.tolerance,
                            'failed for temperature {}, cv = {}'.format(T, cv))

    def test_heat_capacity_2D_com(self):
        self.bdim = 2
        self.ndim = self.natoms * self.bdim
        self.origin = np.zeros(self.ndim)
        potential = Harmonic(self.origin, self.k, bdim=self.bdim, com=True)
        #self.start_coords = vector_random_uniform_hypersphere(self.ndim) * np.sqrt(2*self.Emax) #coordinates sampled from Pow(ndim)

        print "2D com"
        for T in self.temperatures:

            mcrunner = Metropolis_MCrunner(potential,
                                           self.origin,
                                           T,
                                           self.stepsize,
                                           self.niter,
                                           hEmax=100,
                                           adjustf=self.adjustf,
                                           adjustf_niter=self.adjust_niter,
                                           radius=self.radius,
                                           bdim=self.bdim,
                                           seeds=self.seeds)
            #MCMC
            mcrunner.run()
            #collect the results
            binenergy, hist, mean, variance = mcrunner.get_histogram()

            cv = variance / (T * T)
            cv_true = (self.natoms - 1) * self.bdim / 2.0

            print cv, cv_true

            self.assertLess(abs(cv - cv_true), self.tolerance,
                            'failed for temperature {}, cv = {}'.format(T, cv))

    def test_heat_capacity_2D(self):
        self.bdim = 2
        self.ndim = self.natoms * self.bdim
        self.origin = np.zeros(self.ndim)
        self.potential = Harmonic(self.origin,
                                  self.k,
                                  bdim=self.bdim,
                                  com=False)

        print "2D"
        for T in self.temperatures:

            mcrunner = Metropolis_MCrunner(self.potential,
                                           self.origin,
                                           T,
                                           self.stepsize,
                                           self.niter,
                                           hEmax=100,
                                           adjustf=self.adjustf,
                                           adjustf_niter=self.adjust_niter,
                                           radius=self.radius,
                                           bdim=self.bdim,
                                           seeds=self.seeds)
            #MCMC
            mcrunner.run()
            #collect the results
            binenergy, hist, mean, variance = mcrunner.get_histogram()

            cv = variance / (T * T)
            cv_true = self.natoms * self.bdim / 2.0

            print cv, cv_true

            self.assertLess(abs(cv - cv_true), self.tolerance,
                            'failed for temperature {}, cv = {}'.format(T, cv))

    def test_composite_moves(self):
        self.bdim = 2
        self.ndim = self.natoms * self.bdim
        self.origin = np.zeros(self.ndim)
        self.potential = Harmonic(self.origin,
                                  self.k,
                                  bdim=self.bdim,
                                  com=False)