<commit_before>from __future__ import print_function, division

import sys,os
quspin_path = os.path.join(os.getcwd(),"../")
sys.path.insert(0,quspin_path)

from quspin.basis.transformations import square_lattice_trans
from quspin.basis import spin_basis_general
from quspin.operators import hamiltonian
import numpy as np

Lx=5
Ly=4
N = Lx*Ly
tr = square_lattice_trans(Lx,Ly)

Z = [-(i+1) for i in range(N)]

print(tr.T_x)

basis = spin_basis_general(Lx*Ly,Nup=N//2,pauli=True,kx=(tr.T_x,0),ky=(tr.T_y,0),py=(tr.P_y,0),px=(tr.P_x,0),zb=(Z,0))
basis_full = spin_basis_general(Lx*Ly,Nup=N//2,pauli=True)

print(basis.Ns)
print(basis_full.Ns)

J = [[1.0,i,tr.T_x[i]] for i in range(N)]
J.extend([1.0,i,tr.T_y[i]] for i in range(N))

static = [["xx",J],["yy",J],["zz",J]]

H = hamiltonian(static,[],basis=basis,dtype=np.float64)
H_full = hamiltonian(static,[],basis=basis_full,dtype=np.float64)
[E2],_= H.eigsh(k=1,which="SA")
[E1],_= H_full.eigsh(k=1,which="SA")

assert(np.abs(E2-E1)<1.1e-10)<commit_msg>adding test for spin_basis_general<commit_after>from __future__ import print_function, division

import sys,os
qspin_path = os.path.join(os.getcwd(),"../")
sys.path.insert(0,qspin_path)

from quspin.basis import spin_basis_general
from quspin.basis.transformations import square_lattice_trans
from quspin.operators import hamiltonian
import numpy as np


Lx = 3
Ly = 3

N = Lx*Ly

tr = square_lattice_trans(Lx,Ly)


basis_full = spin_basis_general(N)


basis_dict = {}
Nup_list=range(N+1)

for Nup in Nup_list:
	basis_dict[(Nup,None,None)] = spin_basis_general(N,Nup=Nup)
	for kx in range(Lx):
		for ky in range(Ly):
			basis_dict[(Nup,kx,ky)] = spin_basis_general(N,Nup=Nup,kxblock=(tr.T_x,kx),kyblock=(tr.T_y,ky))
			# print basis_dict[(Nup,kx,ky)]._n

J = [[1.0,i,tr.T_x[i]] for i in range(N)]
J.extend([[1.0,i,tr.T_y[i]] for i in range(N)])
J.extend([[1.0,i,tr.T_y[tr.T_x[i]]] for i in range(N)])
J.extend([[1.0,i,tr.T_y[tr.T_x[i]]] for i in range(N)])

static = [["zz",J],["xx",J],["yy",J]]

H_full = hamiltonian(static,[],basis=basis_full,dtype=np.float64)

E_full = H_full.eigvalsh()

E_symm = {}

for key,basis in basis_dict.items():
	H = hamiltonian(static,[],basis=basis,dtype=np.complex128)
	E_symm[key] = H.eigvalsh()

E_pcon = []
for Nup in range(N+1):
	E_pcon.append(E_symm[(Nup,None,None)])

E_pcon = np.hstack(E_pcon)
E_pcon.sort()

np.testing.assert_allclose(E_pcon,E_full,atol=1e-14)


for Nup in Nup_list:
	E_full_block = E_symm[(Nup,None,None)]
	E_block = []
	for kx in range(Lx):
		for ky in range(Ly):
			E_block.append(E_symm[(Nup,kx,ky)])

	E_block = np.hstack(E_block)
	E_block.sort()
	np.testing.assert_allclose(E_full_block,E_block,atol=1e-14)
	print("passed Nup={} sector".format(Nup))

































{'fraction_non_alphanumeric': 0.18377001455604075, 'fraction_numerical': 0.01928675400291121, 'mean_word_length': 5.787654320987654, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5078095', 'n_tokens_mistral': 1337, 'n_tokens_neox': 1273, 'n_words': 194}