Пример #1
0
 def get_random_configuration(self):
     nspins = self.nspins
     if self.one_frozen:
         nspins -= 1
     coords = np.zeros([nspins, 2])
     for i in range(nspins):
         vec = vec_random()
         coords[i,:] = hs.make2dVector(vec)
     return coords.reshape(-1)
Пример #2
0
 def get_random_configuration(self):
     nspins = self.nspins
     if self.one_frozen:
         nspins -= 1
     coords = np.zeros([nspins, 2])
     for i in range(nspins):
         vec = vec_random()
         coords[i,:] = hs.make2dVector(vec)
     return coords.reshape(-1)
Пример #3
0
    for node in pot.G.nodes():
        i = pot.indices[node]
        fout.write("%g %g %g %g %g %g %g %g\n" % (node[0], node[1],
                                                  s[i, 0], s[i, 1], s[i, 2], h[i, 0], h[i, 1], h[i, 2] ))


pi = np.pi
L = 4
nspins = L ** 2

pot = HeisenbergModelRA(dim=[L, L], field_disorder=2.)

coords = np.zeros([nspins, 2])
for i in range(nspins):
    vec = rotations.vec_random()
    coords[i, :] = make2dVector(vec)
coords = np.reshape(coords, [nspins * 2])
coordsinit = np.copy(coords)

print coords

e = pot.getEnergy(coords)
print "energy ", e

print "try a quench"
from pele.optimize import mylbfgs

ret = mylbfgs(coords, pot)

print "quenched e = ", ret.energy, "funcalls", ret.nfev
print ret.coords
Пример #4
0
def normalize_2dspins(coords):
    """there is probably a better way to do this."""
    return hs.make2dVector(hs.make3dVector(coords))
Пример #5
0
def normalize_2dspins(coords):
    """there is probably a better way to do this."""
    return hs.make2dVector(hs.make3dVector(coords))
Пример #6
0
def test():
    pi = np.pi
    L = 4
    nspins = L**2
    
    #phases = np.zeros(nspins)
    pot = HeisenbergModelRA( dim = [L,L], field_disorder = 2. ) #, phases=phases)
    
    coords = np.zeros([nspins, 2])
    for i in range(nspins): 
        vec = rotations.vec_random()
        coords[i,:] = make2dVector(vec)
    coords = np.reshape(coords, [nspins*2])
    if False:
        normfields = np.copy(pot.fields)
        for i in range(nspins): normfields[i,:] /= np.linalg.norm(normfields[i,:])
        coords = coords3ToCoords2( np.reshape(normfields, [nspins*3] ) )
        coords  = np.reshape(coords, nspins*2)
    #print np.shape(coords)
    coordsinit = np.copy(coords)
    
    #print "fields", pot.fields
    print coords
    
    if False:
        coords3 = coords2ToCoords3(coords)
        coords2 = coords3ToCoords2(coords3)
        print np.reshape(coords, [nspins,2])
        print coords2
        coords3new = coords2ToCoords3(coords2)
        print coords3
        print coords3new

    e = pot.getEnergy(coords)
    print "energy ", e
    if True:
        print "numerical gradient"
        ret = pot.getEnergyGradientNumerical(coords)
        print ret[1]
        if True:
            print "analytical gradient"
            ret2 = pot.getEnergyGradient(coords)
            print ret2[1]
            print ret[0]
            print ret2[0]
            #print "ratio"
            #print ret2[1] / ret[1]
            #print "inverse sin"
            #print 1./sin(coords)
            #print cos(coords)
    
    print "try a quench"
    from pele.optimize import mylbfgs
    ret = mylbfgs(coords, pot)
    
    print "quenched e = ", ret.energy, "funcalls", ret.nfev
    print ret.coords
    with open("out.spins", "w") as fout:
        s = coords2ToCoords3( ret.coords )
        h = pot.fields
        c = coords2ToCoords3( coordsinit )
        for node in pot.G.nodes():
            i = pot.indices[node]
            fout.write( "%g %g %g %g %g %g %g %g %g %g %g\n" % (node[0], node[1], \
                s[i,0], s[i,1], s[i,2], h[i,0], h[i,1], h[i,2], c[i,0], c[i,1], c[i,2] ) )
    
    coords3 = coords2ToCoords3( ret.coords )
    m = np.linalg.norm( coords3.sum(0) ) / nspins
    print "magnetization after quench", m
    
    test_basin_hopping(pot, coords)
Пример #7
0
        i = pot.indices[node]
        fout.write("%g %g %g %g %g %g %g %g\n" %
                   (node[0], node[1], s[i, 0], s[i, 1], s[i, 2], h[i, 0],
                    h[i, 1], h[i, 2]))


pi = np.pi
L = 4
nspins = L**2

pot = HeisenbergModelRA(dim=[L, L], field_disorder=2.)

coords = np.zeros([nspins, 2])
for i in range(nspins):
    vec = rotations.vec_random()
    coords[i, :] = make2dVector(vec)
coords = np.reshape(coords, [nspins * 2])
coordsinit = np.copy(coords)

print coords

e = pot.getEnergy(coords)
print "energy ", e

print "try a quench"
from pele.optimize import mylbfgs

ret = mylbfgs(coords, pot)

print "quenched e = ", ret.energy, "funcalls", ret.nfev
print ret.coords