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

minor changes

parent 3c8841ec
...@@ -50,6 +50,7 @@ class spin_model: ...@@ -50,6 +50,7 @@ class spin_model:
def __init__(self, model_name, number_spins, periodic, param, hamming_weight, use_symmetries=False, spin_inversion=None): def __init__(self, model_name, number_spins, periodic, param, hamming_weight, use_symmetries=False, spin_inversion=None):
self.__number_spins = number_spins self.__number_spins = number_spins
self.__periodic = periodic self.__periodic = periodic
self.__param = param
self.__symmetries = [] self.__symmetries = []
self.__spin_inversion = spin_inversion self.__spin_inversion = spin_inversion
if use_symmetries: if use_symmetries:
...@@ -82,15 +83,17 @@ class spin_model: ...@@ -82,15 +83,17 @@ class spin_model:
def create_hamiltonian(self): def create_hamiltonian(self):
self.hamiltonian = ls.Operator(self.basis, [ls.Interaction(self.__matrix, self.edges)]) 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): def compute_ew_and_ev(self, print_gs_energy=True):
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) self.eigenvalues, self.eigenstates = ls.diagonalize(self.hamiltonian, k=1)
if print_gs_energy: if print_gs_energy:
print("Ground state energy is {:.10f}".format(self.eigenvalues[0])) print("Ground state energy is {:.10f}".format(self.eigenvalues[0]))
...@@ -107,3 +110,11 @@ class spin_model: ...@@ -107,3 +110,11 @@ class spin_model:
# destructor # destructor
def __del__(self): def __del__(self):
del self 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 ...@@ -9,16 +9,16 @@ from entropy_new import reduced_dm, compute_entropy
def test_xxz(): def test_xxz():
model_name = 'xxz' model_name = 'xxz'
number_spins = 10 number_spins = 6
periodic = True periodic = False
spin_inversion = -1 spin_inversion = None
param = 1.0 param = -2.0
if param < -1.0: if param < -1.0:
hamming_weight = None hamming_weight = 0
else: else:
hamming_weight = number_spins // 2 hamming_weight = number_spins // 2
model = spin_model(model_name=model_name, number_spins=number_spins, periodic=periodic, 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() model.compute_ew_and_ev()
print('EIGENSTATE at h/J = ', param, 'is: ', model.eigenstates[:,0]) print('EIGENSTATE at h/J = ', param, 'is: ', model.eigenstates[:,0])
sub_dims = np.arange(1, number_spins) sub_dims = np.arange(1, number_spins)
...@@ -27,14 +27,14 @@ def test_xxz(): ...@@ -27,14 +27,14 @@ def test_xxz():
gs = model.eigenstates[:,0] gs = model.eigenstates[:,0]
print('Number Spins: ', model.basis.number_spins) print('Number Spins: ', model.basis.number_spins)
print('States', model.basis.states) print('States', model.basis.states)
"""for sub_dim in sub_dims: for sub_dim in sub_dims:
print('Sub Dimension is ', sub_dim) print('Sub Dimension is ', sub_dim)
rhos = reduced_dm(sub_dim, number_spins, hamming_weight, gs, basis_states, spin_inversion) rhos = reduced_dm(sub_dim, number_spins, hamming_weight, gs, basis_states, spin_inversion)
#print(rhos) print(rhos)
entropy = compute_entropy(rhos) entropy = compute_entropy(rhos)
print(entropy) print(entropy)
print('-------------------------------------------') print('-------------------------------------------')
"""
def test_area_law(): def test_area_law():
model_name = 'xxz' model_name = 'xxz'
number_spins = 14 number_spins = 14
......
...@@ -13,21 +13,3 @@ if __name__ == "__main__": ...@@ -13,21 +13,3 @@ if __name__ == "__main__":
#test_mutual_information() #test_mutual_information()
MI_vs_Entropy() 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(): ...@@ -39,14 +39,14 @@ def test_mutual_information():
def MI_vs_Entropy(): def MI_vs_Entropy():
model_name = 'xxz' model_name = 'tfim'
dim = 18#[8, 10, 12, 14]#, 16, 18] dim = 14#[8, 10, 12, 14]#, 16, 18]
periodic = False periodic = False
spin_inversion = None spin_inversion = None
params = np.linspace(-2.0, 2.0, 101) params = np.linspace(0.0, 2.0, 21)
sub_dim = 4 sub_dim = 1
first_trace_spin = 4 first_trace_spin = 1
MIs = [] MIs = []
Entropies = [] Entropies = []
...@@ -56,7 +56,7 @@ def MI_vs_Entropy(): ...@@ -56,7 +56,7 @@ def MI_vs_Entropy():
if param < -1.0: if param < -1.0:
hamming_weight = None hamming_weight = None
else: else:
hamming_weight = dim // 2 hamming_weight = None
model = spin_model(model_name=model_name, number_spins=dim, periodic=periodic, model = spin_model(model_name=model_name, number_spins=dim, periodic=periodic,
param=param, hamming_weight=hamming_weight ,spin_inversion=spin_inversion) param=param, hamming_weight=hamming_weight ,spin_inversion=spin_inversion)
model.compute_ew_and_ev() model.compute_ew_and_ev()
...@@ -69,6 +69,8 @@ def MI_vs_Entropy(): ...@@ -69,6 +69,8 @@ def MI_vs_Entropy():
del model del model
plt.figure() plt.figure()
plt.plot(params, Entropies) plt.plot(params, Entropies, label='Half-chain Entropy')
plt.plot(params, MIs) plt.plot(params, MIs, label='Mutual Information')
plt.savefig('test2.jpg') 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