Commit 2b5b412a authored by mgassner's avatar mgassner
Browse files

minor changes

parent 3c8841ec
......@@ -50,6 +50,7 @@ class spin_model:
def __init__(self, model_name, number_spins, periodic, param, hamming_weight, use_symmetries=False, spin_inversion=None):
self.__number_spins = number_spins
self.__periodic = periodic
self.__param = param
self.__symmetries = []
self.__spin_inversion = spin_inversion
if use_symmetries:
......@@ -82,15 +83,17 @@ class spin_model:
def create_hamiltonian(self):
self.hamiltonian = ls.Operator(self.basis, [ls.Interaction(self.__matrix, self.edges)])
"""
def update_basis_and_hamiltonian(self, rearrangement):
# TODO: find out if I need to update edges as well!!!
new_states = idxs_rearrangement(self.basis.states, rearrangement)
self.basis.build(representatives=new_states)
self.hamiltonian = ls.Operator(self.basis, [ls.Interaction(self.__matrix, self.edges)])
"""
def compute_ew_and_ev(self, print_gs_energy=True):
self.eigenvalues, self.eigenstates = ls.diagonalize(self.hamiltonian, k=1)
if (self.__hamming_weight == 0 or self.__hamming_weight == self.__number_spins) and self.__name == 'xxz':
self.eigenvalues = np.array([self.__number_spins * self.__param])
if not self.__periodic:
self.eigenvalues -= self.__param
self.eigenstates = np.array([[1.],])
else:
self.eigenvalues, self.eigenstates = ls.diagonalize(self.hamiltonian, k=1)
if print_gs_energy:
print("Ground state energy is {:.10f}".format(self.eigenvalues[0]))
......@@ -106,4 +109,12 @@ class spin_model:
return self.__matrix
# destructor
def __del__(self):
del self
\ No newline at end of file
del self
"""
def update_basis_and_hamiltonian(self, rearrangement):
# TODO: find out if I need to update edges as well!!!
new_states = idxs_rearrangement(self.basis.states, rearrangement)
self.basis.build(representatives=new_states)
self.hamiltonian = ls.Operator(self.basis, [ls.Interaction(self.__matrix, self.edges)])
"""
\ No newline at end of file
......@@ -9,16 +9,16 @@ from entropy_new import reduced_dm, compute_entropy
def test_xxz():
model_name = 'xxz'
number_spins = 10
periodic = True
spin_inversion = -1
param = 1.0
number_spins = 6
periodic = False
spin_inversion = None
param = -2.0
if param < -1.0:
hamming_weight = None
hamming_weight = 0
else:
hamming_weight = number_spins // 2
model = spin_model(model_name=model_name, number_spins=number_spins, periodic=periodic,
param=param, hamming_weight=hamming_weight, use_symmetries=True,spin_inversion=spin_inversion)
param=param, hamming_weight=hamming_weight, use_symmetries=False ,spin_inversion=spin_inversion)
model.compute_ew_and_ev()
print('EIGENSTATE at h/J = ', param, 'is: ', model.eigenstates[:,0])
sub_dims = np.arange(1, number_spins)
......@@ -27,14 +27,14 @@ def test_xxz():
gs = model.eigenstates[:,0]
print('Number Spins: ', model.basis.number_spins)
print('States', model.basis.states)
"""for sub_dim in sub_dims:
for sub_dim in sub_dims:
print('Sub Dimension is ', sub_dim)
rhos = reduced_dm(sub_dim, number_spins, hamming_weight, gs, basis_states, spin_inversion)
#print(rhos)
print(rhos)
entropy = compute_entropy(rhos)
print(entropy)
print('-------------------------------------------')
"""
def test_area_law():
model_name = 'xxz'
number_spins = 14
......
......@@ -13,21 +13,3 @@ if __name__ == "__main__":
#test_mutual_information()
MI_vs_Entropy()
"""print('------------------------------------------------')
print('---With symmetries and spin inversion---')
github_test()
print('---Without symmetries, but spin inversion---')
github_test(use_symmetries=False)
print('---With symmetries, but no spin inversion---')
github_test(spin_inversion=None)
print('---Without symmetries and spin inversion---')
github_test(spin_inversion=None, use_symmetries=False)
print('------------------------------------------------')
print('---With symmetries and spin inversion---')
github_test()
print('---Without symmetries, but spin inversion---')
github_test(use_symmetries=False)
print('---With symmetries, but no spin inversion---')
github_test(spin_inversion=None)
print('---Without symmetries and spin inversion---')
github_test(spin_inversion=None, use_symmetries=False)"""
......@@ -39,14 +39,14 @@ def test_mutual_information():
def MI_vs_Entropy():
model_name = 'xxz'
dim = 18#[8, 10, 12, 14]#, 16, 18]
model_name = 'tfim'
dim = 14#[8, 10, 12, 14]#, 16, 18]
periodic = False
spin_inversion = None
params = np.linspace(-2.0, 2.0, 101)
params = np.linspace(0.0, 2.0, 21)
sub_dim = 4
first_trace_spin = 4
sub_dim = 1
first_trace_spin = 1
MIs = []
Entropies = []
......@@ -56,7 +56,7 @@ def MI_vs_Entropy():
if param < -1.0:
hamming_weight = None
else:
hamming_weight = dim // 2
hamming_weight = None
model = spin_model(model_name=model_name, number_spins=dim, periodic=periodic,
param=param, hamming_weight=hamming_weight ,spin_inversion=spin_inversion)
model.compute_ew_and_ev()
......@@ -69,6 +69,8 @@ def MI_vs_Entropy():
del model
plt.figure()
plt.plot(params, Entropies)
plt.plot(params, MIs)
plt.savefig('test2.jpg')
plt.plot(params, Entropies, label='Half-chain Entropy')
plt.plot(params, MIs, label='Mutual Information')
plt.grid(True)
plt.legend()
plt.savefig('test4.jpg')
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment