Commit c1a39ed6 authored by mgassner's avatar mgassner
Browse files

minor changes

parent 912a6a22
......@@ -58,17 +58,23 @@ def sector_dm(trace_states, sub_states, amplitudes):
#Goal:
def reduced_dm(sub_dim, dim, hamming, amplitudes, states_of_amplitudes):
"""
:sub_dim:
:amplitudes:
:states_of_amplitudes:
:sub_dim: amount of spins in the subsystem (uint)
:dim: amount of spins of total system (uint)
:hamming: amount of upspins of total system(uint or None)
:amplitudes: amplitudes of input state (1d-array of floats)
:states_of_amplitudes: state which belongs to amplitude (1d-array of uints)
:return: List of sector density matrices
"""
sub_states = states_of_amplitudes >> (dim - sub_dim)
trace_states = states_of_amplitudes & (2**(dim-sub_dim)-1)
hamming_of_sub_states = np.array([_hamming_weight(n) for n in sub_states])
#distinct_states_out = list(set(states_out))
rho = []
for sub_hamming in range(max(0, hamming - (dim - sub_dim)), min(hamming, sub_dim) + 1):
if hamming is None:
sub_hammings = np.arange(0, sub_dim+1)
else:
sub_hammings = np.arange(max(0, hamming - (dim - sub_dim)), min(hamming, sub_dim) + 1)
for sub_hamming in sub_hammings:
indices = np.where(hamming_of_sub_states == sub_hamming)[0].tolist()
sector_sub_states = [sub_states[i] for i in indices]
sector_trace_states = [trace_states[i] for i in indices]
......@@ -79,16 +85,18 @@ def reduced_dm(sub_dim, dim, hamming, amplitudes, states_of_amplitudes):
def lambda_log_lambda(x):
"""
Von Neumann Entropy
Von Neumann Entropy (log with basis 2)
:x: array of eigenvalues of a sector density matrix
:return: negative Bipartite Entanglement entropy of a sector density_matrix
"""
y = np.where(x > 1e-7, np.log(x), 0.0)
y = np.where(x > 1e-7, np.log(x) / np.log(2), 0.0)
y *= x
return y
def compute_entropy(rho):
"""
:rho: list of sector density matrices
:return: Bipartite Entanglement Entropy (von Neumann)
"""
entropy = 0
for i in range(len(rho)):
......
......@@ -25,7 +25,7 @@ def test_xxx():
gs = model.eigenstates[:,0]
print('Number Spins: ', model.basis.number_spins)
print('States', model.basis.states)
rhos = reduced_dm(sub_dim, number_spins, hamming_weight, gs, basis_states)
rhos = reduced_dm(sub_dim, number_spins, 2, gs, basis_states)
print(rhos)
entropy = compute_entropy(rhos)
print(entropy)
......@@ -78,13 +78,13 @@ def test_area_law():
plt.legend()
plt.xlabel('x/L')
plt.ylabel('Bipartite Entanglement Entropy')
plt.title('Model:' + model_name + ' Number spins:' + str(number_spins))#, ' Periodic:' + str(periodic))
plt.title('Model:' + model_name + ' Number spins:' + str(number_spins), ' Periodic:' + str(periodic))
plt.grid(True)
plt.savefig('output/' + filename + '.jpg')
plt.figure(figsize=(20,20))
plt.figure(figsize=(8,8))
half_chain_ee = []
for key in entropies:
half_chain_ee.append(entropies[key][7])
......
......@@ -11,9 +11,9 @@ def test_tfim():
number_spins = 4
periodic = True
hamming_weight = number_spins // 2
param = 0.0
param = 1.0
model = spin_model(model_name=model_name, number_spins=number_spins, periodic=periodic,
param=param, hamming_weight=None)
param=param, hamming_weight=None)#hamming_weight)
model.compute_ew_and_ev()
print('EIGENSTATE at h/J = ', param, 'is: ', model.eigenstates[:,0])
sub_dim = 2
......@@ -22,34 +22,31 @@ def test_tfim():
basis_states = model.basis.states
print('Number Spins: ', model.basis.number_spins)
print('States', model.basis.states)
rhos = reduced_dm(sub_dim, number_spins, hamming_weight, gs, basis_states)
rhos = reduced_dm(sub_dim, number_spins, 0, gs, basis_states)
print(rhos)
entropy = compute_entropy(rhos)
print(entropy)
def test_area_law_tfim():
model_name = 'tfim'
number_spins = 12
number_spins = 14
periodic = True
params = np.linspace(0.0, 4.0, 21)
params = np.linspace(0.0, 1.5, 21)
hamming_weight = None # TODO: ?????
entropies = {}
sub_dims = [i for i in range(1,number_spins)]
for param in params:
bipartite_entropies = []
model = spin_model(model_name=model_name, number_spins=number_spins, periodic=periodic,
param=param, hamming_weight=None)
param=param, hamming_weight=hamming_weight)
model.compute_ew_and_ev()
gs = model.eigenstates[:,0]
basis_states = model.basis.states
for sub_dim in sub_dims:
print('----------------------------------')
print('Sub Dimension is ', sub_dim)
entropy = 0
for hamming_weight in range(1):
rhos = reduced_dm(sub_dim, number_spins, 6, gs, basis_states)
entropy += compute_entropy(rhos)
bipartite_entropies.append(entropy)
rhos = reduced_dm(sub_dim, number_spins, hamming_weight, gs, basis_states)
bipartite_entropies.append(compute_entropy(rhos))
entropies[str(param)] = bipartite_entropies
del model
......
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