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

minor changes

parent 3fdbebc5
......@@ -119,20 +119,17 @@ def compute_entropy(rho):
def compute_MI(sub_dim, dim, hamming, amplitudes, states_of_amplitudes, spin_inversion=None, first_trace_spin=None):
# so far left and right sub-dimension is the same and equal to sub_dim
assert (first_trace_spin + sub_dim) <= dim and first_trace_spin >= sub_dim
first_trace_spin_left = first_trace_spin + (dim - 2*sub_dim)
first_trace_spin_left = first_trace_spin - sub_dim
#S_AB:
print('--------------A and B---------------')
rhos_AB = reduced_dm(sub_dim*2, dim, hamming, amplitudes, states_of_amplitudes,
spin_inversion=spin_inversion, first_trace_spin=first_trace_spin)
S_AB = compute_entropy(rhos_AB)
#S_B (right)
print('-----------------B------------------')
rhos_B = reduced_dm(sub_dim, dim, hamming, amplitudes, states_of_amplitudes,
spin_inversion=spin_inversion, first_trace_spin=first_trace_spin)
S_B = compute_entropy(rhos_B)
#S_A (left)
print('-----------------A------------------')
rhos_A = reduced_dm(sub_dim, dim, hamming, amplitudes, states_of_amplitudes,
spin_inversion=spin_inversion, first_trace_spin=first_trace_spin_left)
S_A = compute_entropy(rhos_A)
return [S_A, S_B, S_AB]
\ No newline at end of file
return S_A + S_B - S_AB #[S_A, S_B, S_AB]
\ No newline at end of file
......@@ -2,7 +2,7 @@ from heisenberg import test_xxz, test_area_law
from tfim import test_tfim, test_area_law_tfim
from package_fails import test_symmetries_xxx
from ls_example_from_github import github_test
from mutual_information import test_mutual_information
from mutual_information import test_mutual_information, MI_vs_Entropy
if __name__ == "__main__":
#test_xxz()
......@@ -11,8 +11,8 @@ if __name__ == "__main__":
#test_tfim()
#test_symmetries_xxx('tfim')
test_mutual_information()
#test_mutual_information()
MI_vs_Entropy()
"""print('------------------------------------------------')
print('---With symmetries and spin inversion---')
github_test()
......
......@@ -7,6 +7,7 @@ from create_model import spin_model
from entropy_new import compute_MI, compute_entropy, reduced_dm
def test_mutual_information():
# change return in compute_MI to run this function [S_A, S_B, S_AB] instead of S_A + S_B - S_AB
model_name = 'xxz'
number_spins = 10
periodic = False
......@@ -22,7 +23,6 @@ def test_mutual_information():
print('EIGENSTATE at h/J = ', param, 'is: ', model.eigenstates[:,0])
sub_dim = 4
first_trace_spin = 4
number_spins = model.number_spins()
basis_states = model.basis.states
gs = model.eigenstates[:,0]
print('Number Spins: ', model.basis.number_spins)
......@@ -34,5 +34,40 @@ def test_mutual_information():
print(entropies)
print('--------------------Test-----------------------')
rhos4 = reduced_dm(4, number_spins, hamming_weight, gs, basis_states)
rhos8 = reduced_dm(4, number_spins, hamming_weight, gs, basis_states)
print(compute_entropy(rhos4), compute_entropy(rhos8))
\ No newline at end of file
rhos6 = reduced_dm(6, number_spins, hamming_weight, gs, basis_states)
print(compute_entropy(rhos4), compute_entropy(rhos6))
def MI_vs_Entropy():
model_name = 'xxz'
dim = 14#[8, 10, 12, 14]#, 16, 18]
periodic = False
spin_inversion = None
params = np.linspace(-1.5, 1.5, 51)
sub_dim = 4
first_trace_spin = 4
MIs = []
Entropies = []
print('Number Spins: ', dim)
print('Sub Dimension is ', sub_dim)
for param in params:
if param < -1.0:
hamming_weight = None
else:
hamming_weight = dim // 2
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()
basis_states = model.basis.states
gs = model.eigenstates[:,0]
MI = compute_MI(sub_dim, dim, hamming_weight, gs, basis_states, spin_inversion=None, first_trace_spin=first_trace_spin)
MIs.append(MI)
rho_half = reduced_dm(dim // 2, dim, hamming_weight, gs, basis_states)
Entropies.append(compute_entropy(rho_half))
plt.figure()
plt.plot(params, entropies)
plt.plot(params, MIs)
plt.savefig('test.jpg')
\ No newline at end of file
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