LM_validify.py 832 Bytes
Newer Older
Hylke Donker's avatar
Hylke Donker committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from numpy import testing
from numpy import *
import bits
import sys
import ctypes

def calc_S2(psi):
	N = psi.get_size()
	S2=N*0.75
	for l in range(N):
		for k in range(l+1, N):
			Slk =pyspin.correlation(psi, l,k)
			S2 += 2*sum(Slk)
	return S2

flags = sys.getdlopenflags()
sys.setdlopenflags(flags|ctypes.RTLD_GLOBAL)
import pyspin
sys.setdlopenflags(flags)

lmsys = pyspin.lieb_mattis_system(4)
lmsys.initialize()
psi0 = array(lmsys.groundstate().get())


hhsys = pyspin.heisenberg_system(4, True)
hhsys.initialize()
psi0p = array(hhsys.groundstate().get())

testing.assert_almost_equal(absolute(dot(psi0, psi0p)), 1.0)
# TODO:
# Do some more unit testing to check that ground state is indeed singlet, etc.
lmsys2 = pyspin.lieb_mattis_system(6)
lmsys2.initialize()
testing.assert_almost_equal(calc_S2(lmsys2.groundstate()), 0)