0

## 在執行程式碼的時候出現，cannot assign the function call : x0(l) = g(s,l,it)

def AcceptMoveCPP(it, g, a, x0, x1, vn, accepted):
vn[it] = -1 # perform spin-flip
L = len(vn)
b = 0.0
for s in range(2): # both members of pair need to be updated
b = a(s)/(1+a(s)
(1-g(s,it,it)))
prefactorb = a/(1+a(1-g_pp))
for l in range(L):
x0(l) = g(s,l,it)
x1(l) = g(s,l,it)
x0(it) -= 1.
return_val = b;
g[s]=lib.blas.fblas.dger(b,x0,x1,a=g[s],overwrite_a=1)
return accepted+1

froce iT邦大師 2 級 ‧ 2018-11-14 12:05:50 檢舉
x0那些是變數還是函數？

wendyduke iT邦新手 5 級 ‧ 2018-11-14 12:43:00 檢舉

import os, time
import scipy
from pylab import *
from scipy import *
#scipy.pkgload('lib') # To use blas functions directly
def g0_2D(tau, G0):
"Initialization of ising g0(tau,tau') from G0(tau-tau'). Must be antiperiodic in time."
L = len(tau)-1
print ('L=', L)
g0 = zeros((L,L), dtype=float)
for i in range(L):
for j in range(L):
if i>=j:
g0[i,j] = -G0[i-j] # antiperiodic boundary conditions for fermions
else:
g0[i,j] = G0[L+i-j] # antiperiodic boundary conditions for fermions
return g0

def CleanUpdate(g, g0, vn):
" Goes over all ising spins and recalculates g from g0 according to the current ising configuration."
L = len(vn)
sigma = [1,-1]
A = zeros((L,L),dtype=float)
for i in range(2):
# a = e^V-1
a = [exp(vn[l]*sigma[i])-1 for l in range(L)]
# Matrix A = 1 + (1-g)(e^V-1) == (1+a)*I - g*a
for l1 in range(L):
for l2 in range(L): A[l1,l2] = -g0[l1,l2]*a[l2]
A[l1,l1] += 1 + a[l1]
# Solves system of linear equations A*g0[i]=g[i]. This is faster than computing inverse.
g[i] = solve(A, g0)

def DetRatio(it, g, a):
# One of the most important subroutines in QMC.
# Computes the probability for the MC step - the ration of determinants between ising configurations.
# it -- time slice index
a[0] = exp(-2*vn[it]) - 1
a[1] = exp( 2*vn[it]) - 1
Det_up = 1+(1-g[0,it,it])*a[0]
Det_dn = 1+(1-g[1,it,it])*a[1]
return Det_up*Det_dn

def AcceptMove(it, g, a, vn, accepted):
# Most important subroutine in QMC.
# Updates the quantities (green's function) since the new ising configuration is accepted.
# This function needs most of the time and should be heavily optimized! Most of the time is currently spend in blas
# routine daxpy when doing rank1 update.
vn[it] *= -1 # perform spin-flip
L = len(vn)
#if accepted%ndirty==0: CleanUpdate(g,g0,vn)
#else # dirty update
for s in range(2): # both members of pair need to be updated
# prefactor b = a/(1+a(1-g_pp))
b = a[s]/(1+a[s]*(1-g[s,it,it]))
# this computes (g-1)_{l,it}
x0 = copy(g[s,:,it]) # first we set x0[l] = g_{l,it}
x0[it] -= 1 # now be sutract delta_{l,il} to get x0[l] = g_{l,it}-delta_{l,it}
x1 = g[s,it,:]
# Here we calculate b*(g-1) x g , where x is tensor product
#g[s] += lib.blas.fblas.dger(b,x0,x1)
g[s]=lib.blas.fblas.dger(b,x0,x1,a=g[s],overwrite_a=1)
return (accepted+1)
'''

froce iT邦大師 2 級 ‧ 2018-11-14 15:45:41 檢舉
1.你的code看起來很難看懂。
2.你沒有任何變數、class叫lib的，根本沒定義或import
youarefat iT邦新手 5 級 ‧ 2018-11-15 15:15:00 檢舉

wendyduke iT邦新手 5 級 ‧ 2018-11-16 19:57:32 檢舉