Exemple #1
0
#Written by Magnar K. Bugge

from math import sqrt
from numpy import linspace
import pypar
import MC

nprocs = pypar.size()  #Number of processes
myid = pypar.rank()  #Id of this process

MCcycles = 10000000  #Number of MC cycles
MCcycles2 = 10000  #Number of MC cycles for determination of optimal delta
delta_min = .01  #Minimum length of Metropolis step
delta_max = 2.0  #Maximum length of Metropolis step
tolerance = .01
idum = MC.seed() * (
    myid + 1)  #Seed for random number generator (different for each process)


#Function which should be close to zero for optimal delta
def difference(delta):
    x = MC.runMC(MCcycles2, delta, idum, alpha)
    return x.accepted * 1.0 / MCcycles2 - .5  #We want 50% accepted moves


#Array of alpha values
values = linspace(1.4, 2.0, 13)  #(alpha values)

if myid == 0:
    outfile = open('data', 'w')
#Written by Magnar K. Bugge

from math import sqrt
from numpy import linspace
import pypar
import MC

nprocs = pypar.size() #Number of processes      
myid = pypar.rank() #Id of this process

MCcycles = 10000000 #Number of MC cycles
MCcycles2 = 10000 #Number of MC cycles for determination of optimal delta
delta_min = .01 #Minimum length of Metropolis step
delta_max = 2.0 #Maximum length of Metropolis step
tolerance = .01
idum = MC.seed() * (myid+1) #Seed for random number generator (different for each process)

#Function which should be close to zero for optimal delta
def difference(delta):
    x = MC.runMC(MCcycles2,delta,idum,alpha)
    return x.accepted*1.0/MCcycles2 - .5 #We want 50% accepted moves

#Array of alpha values
values = linspace(1.4,2.0,13) #(alpha values)

if myid == 0:
    outfile = open('data','w')

#Loop over alpha values
for alpha in values:
#Variational Monte Carlo program for the Helium atom which utilizes the code in MC.cpp
#Written by Magnar K. Bugge

from math import sqrt
from numpy import linspace
import MC

MCcycles = 100000000  #Number of MC cycles
MCcycles2 = 10000  #Number of MC cycles for determination of optimal delta
delta_min = .01  #Minimum length of Metropolis step
delta_max = 2.0  #Maximum length of Metropolis step
tolerance = .01
idum = MC.seed()  #Seed for random number generator


#Function which should be close to zero for optimal delta
def difference(delta):
    x = MC.runMC(MCcycles2, delta, idum, alpha)
    return x.accepted * 1.0 / MCcycles2 - .5  #We want 50% accepted moves


#Array of alpha values
values = linspace(1.4, 2.5, 23)  #(alpha values)

outfile = open('data', 'w')

#Loop over alpha values
for alpha in values:

    #Determination of optimal delta value (for each alpha), i.e.
    #finding the zero-point of the difference function by the bisection method
myid = pypar.rank() #Id of this process

class result:
    alpha = 0.0
    E = 0.0
    sigma = 0.0
    error = 0.0
    acceptance = 0.0
    id = 0 #id of the process who did this job

MCcycles = 100000000 #Number of MC cycles
MCcycles2 = 10000 #Number of MC cycles for determination of optimal delta
delta_min = .01 #Minimum length of Metropolis step
delta_max = 2.0 #Maximum length of Metropolis step
tolerance = .01
idum = MC.seed() * (myid+1) #Seed for random number generator (different for each process)

#Function which should be close to zero for optimal delta
def difference(delta):
    x = MC.runMC(MCcycles2,delta,idum,alpha)
    return x.accepted*1.0/MCcycles2 - .5 #We want 50% accepted moves

#Function for sorting the results from small to large alpha
def sort(results):
    sorted_results = []
    
    for i in xrange(len(values)):
        sorted_results.append(result())
        sorted_results[i].alpha = values[i]
        j = 0
        while results[j].alpha != sorted_results[i].alpha:
#Variational Monte Carlo program for the Helium atom which utilizes the code in MC.cpp
#Written by Magnar K. Bugge

from math import sqrt
from numpy import linspace
import MC

MCcycles = 100000000 #Number of MC cycles
MCcycles2 = 10000 #Number of MC cycles for determination of optimal delta
delta_min = .01 #Minimum length of Metropolis step
delta_max = 2.0 #Maximum length of Metropolis step
tolerance = .01
idum = MC.seed() #Seed for random number generator

#Function which should be close to zero for optimal delta
def difference(delta):
    x = MC.runMC(MCcycles2,delta,idum,alpha)
    return x.accepted*1.0/MCcycles2 - .5 #We want 50% accepted moves

#Array of alpha values
values = linspace(1.4,2.5,23) #(alpha values)

outfile = open('data','w')

#Loop over alpha values
for alpha in values:

    #Determination of optimal delta value (for each alpha), i.e.
    #finding the zero-point of the difference function by the bisection method
    minimum = delta_min
    maximum = delta_max