Commit c1a39ed6 by mgassner

### minor changes

parent 912a6a22
 ... @@ -58,17 +58,23 @@ def sector_dm(trace_states, sub_states, amplitudes): ... @@ -58,17 +58,23 @@ def sector_dm(trace_states, sub_states, amplitudes): #Goal: #Goal: def reduced_dm(sub_dim, dim, hamming, amplitudes, states_of_amplitudes): def reduced_dm(sub_dim, dim, hamming, amplitudes, states_of_amplitudes): """ """ :sub_dim: :sub_dim: amount of spins in the subsystem (uint) :amplitudes: :dim: amount of spins of total system (uint) :states_of_amplitudes: :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) sub_states = states_of_amplitudes >> (dim - sub_dim) trace_states = states_of_amplitudes & (2**(dim-sub_dim)-1) trace_states = states_of_amplitudes & (2**(dim-sub_dim)-1) hamming_of_sub_states = np.array([_hamming_weight(n) for n in sub_states]) hamming_of_sub_states = np.array([_hamming_weight(n) for n in sub_states]) #distinct_states_out = list(set(states_out)) rho = [] 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() indices = np.where(hamming_of_sub_states == sub_hamming)[0].tolist() sector_sub_states = [sub_states[i] for i in indices] sector_sub_states = [sub_states[i] for i in indices] sector_trace_states = [trace_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): ... @@ -79,16 +85,18 @@ def reduced_dm(sub_dim, dim, hamming, amplitudes, states_of_amplitudes): def lambda_log_lambda(x): def lambda_log_lambda(x): """ """ Von Neumann Entropy Von Neumann Entropy (log with basis 2) :x: array of eigenvalues of a sector density matrix :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 y *= x return y return y def compute_entropy(rho): def compute_entropy(rho): """ """ :rho: list of sector density matrices :rho: list of sector density matrices :return: Bipartite Entanglement Entropy (von Neumann) """ """ entropy = 0 entropy = 0 for i in range(len(rho)): for i in range(len(rho)): ... ...
 ... @@ -25,7 +25,7 @@ def test_xxx(): ... @@ -25,7 +25,7 @@ def test_xxx(): 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) 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) print(rhos) entropy = compute_entropy(rhos) entropy = compute_entropy(rhos) print(entropy) print(entropy) ... @@ -78,13 +78,13 @@ def test_area_law(): ... @@ -78,13 +78,13 @@ def test_area_law(): plt.legend() plt.legend() plt.xlabel('x/L') plt.xlabel('x/L') plt.ylabel('Bipartite Entanglement Entropy') 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.grid(True) plt.savefig('output/' + filename + '.jpg') plt.savefig('output/' + filename + '.jpg') plt.figure(figsize=(20,20)) plt.figure(figsize=(8,8)) half_chain_ee = [] half_chain_ee = [] for key in entropies: for key in entropies: half_chain_ee.append(entropies[key][7]) half_chain_ee.append(entropies[key][7]) ... ...
 ... @@ -11,9 +11,9 @@ def test_tfim(): ... @@ -11,9 +11,9 @@ def test_tfim(): number_spins = 4 number_spins = 4 periodic = True periodic = True hamming_weight = number_spins // 2 hamming_weight = number_spins // 2 param = 0.0 param = 1.0 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=None) param=param, hamming_weight=None)#hamming_weight) 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_dim = 2 sub_dim = 2 ... @@ -22,34 +22,31 @@ def test_tfim(): ... @@ -22,34 +22,31 @@ def test_tfim(): basis_states = model.basis.states basis_states = model.basis.states print('Number Spins: ', model.basis.number_spins) print('Number Spins: ', model.basis.number_spins) print('States', model.basis.states) 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) print(rhos) entropy = compute_entropy(rhos) entropy = compute_entropy(rhos) print(entropy) print(entropy) def test_area_law_tfim(): def test_area_law_tfim(): model_name = 'tfim' model_name = 'tfim' number_spins = 12 number_spins = 14 periodic = True periodic = True params = np.linspace(0.0, 4.0, 21) params = np.linspace(0.0, 1.5, 21) hamming_weight = None # TODO: ????? entropies = {} entropies = {} sub_dims = [i for i in range(1,number_spins)] sub_dims = [i for i in range(1,number_spins)] for param in params: for param in params: bipartite_entropies = [] bipartite_entropies = [] 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=None) param=param, hamming_weight=hamming_weight) model.compute_ew_and_ev() model.compute_ew_and_ev() gs = model.eigenstates[:,0] gs = model.eigenstates[:,0] basis_states = model.basis.states basis_states = model.basis.states for sub_dim in sub_dims: for sub_dim in sub_dims: print('----------------------------------') print('----------------------------------') print('Sub Dimension is ', sub_dim) print('Sub Dimension is ', sub_dim) entropy = 0 rhos = reduced_dm(sub_dim, number_spins, hamming_weight, gs, basis_states) for hamming_weight in range(1): bipartite_entropies.append(compute_entropy(rhos)) rhos = reduced_dm(sub_dim, number_spins, 6, gs, basis_states) entropy += compute_entropy(rhos) bipartite_entropies.append(entropy) entropies[str(param)] = bipartite_entropies entropies[str(param)] = bipartite_entropies del model del model ... ...
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!