Commit e574d219 authored by mgassner's avatar mgassner
Browse files

minor changes

parent 45e9ac51
......@@ -17,14 +17,14 @@ def create_2spin_matrix(model_name, param):
returns 2 spin hamiltonian
"""
if model_name == 'xxz':
#return (0.5 * (np.kron(sigma_p, sigma_m) + np.kron(sigma_m, sigma_p)) +
# param * np.kron(sigma_z, sigma_z)).astype('float64').tolist()
return (0.5 * (np.kron(sigma_p, sigma_m) + np.kron(sigma_m, sigma_p)) +
param * np.kron(sigma_z, sigma_z)).astype('float64').tolist()
param * np.kron(sigma_z, sigma_z) + 0.01*(np.kron(sigma_z, sigma_0) + np.kron(sigma_0, sigma_z))).astype('float64')
elif model_name == 'tfim':
return ( np.kron(sigma_z, sigma_z) - 0.5*param*(np.kron(sigma_x, sigma_0) + np.kron(sigma_0, sigma_x))).astype('float64').tolist()
elif model_name == 'txxx':
return ((0.5 * (np.kron(sigma_p, sigma_m) + np.kron(sigma_m, sigma_p)) + np.kron(sigma_z, sigma_z))
+ 0.5*param*(np.kron(sigma_x, sigma_0) + np.kron(sigma_0, sigma_x))).astype('float64').tolist()
else:
return ( np.kron(sigma_z, sigma_z) - 0.5*param*(np.kron(sigma_x, sigma_0) + np.kron(sigma_0, sigma_x))
+ 0.01*(np.kron(sigma_z, sigma_0) + np.kron(sigma_0, sigma_z))).astype('float64').tolist()
else:
raise NameError
def generate_symmetries(model_name, number_spins, periodic):
......
......@@ -9,9 +9,11 @@ from entropy_new import compute_MI, compute_entropy, reduced_dm
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--set_number_spins", "-d", dest='number_spins',type=int, required=True)
parser.add_argument("--set_param_range_and_steps", '-p', dest='param_range', nargs='+', type=float)
parser.add_argument("--set_number_spins", "-d", dest='number_spins',type=int, required=False)
parser.add_argument("--set_param_range_and_steps", '-pr', dest='param_range', nargs='+', type=float)
parser.add_argument("--model_name", "-m", dest='model_name' ,type=str, required=True)
parser.add_argument("--set_spin_range", "-sr", dest='spin_range', nargs='+', type=int)
parser.add_argument("--set_param", "-p", dest='param',type=float, required=False)
args = parser.parse_args()
def test_mutual_information():
......@@ -94,15 +96,76 @@ def MI_vs_Entropy(model_name, number_spins, param_range):
print(filename)
plt.figure(figsize=(12,12))
plt.title('MI: number spins = ' + str(number_spins) + 'periodic = ' + str(periodic))
plt.title('MI: ' + model_name + ' ' + str(number_spins) + ' ' + str(periodic))
plt.plot(params, Entropies, label='Half-chain Entropy')
plt.plot(params, MIs, label='Mutual Information')
plt.grid(True)
plt.legend()
plt.savefig('output/' + filename + '.png')
def MutInf(model_name, param, spin_range):
model_name = model_name
periodic = False
spin_inversion = None
sub_dim = 4
first_trace_spin = 4
MIs = []
Entropies = []
Entropies_div_ns = []
number_spins_range = [2*i for i in range(spin_range[0]//2, spin_range[1]//2 + 1)]
for number_spins in number_spins_range:
print('Number Spins: ', number_spins)
print('Sub Dimension is ', sub_dim)
if param < -1.0:
hamming_weight = None
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 ,spin_inversion=spin_inversion)
model.compute_ew_and_ev()
basis_states = model.basis.states
gs = model.eigenstates[:,0]
MI = compute_MI(sub_dim, number_spins, hamming_weight, gs, basis_states, spin_inversion=None, first_trace_spin=first_trace_spin)
MIs.append(MI/sub_dim)
rho_half = reduced_dm(number_spins // 2, number_spins, hamming_weight, gs, basis_states)
Entropies.append(compute_entropy(rho_half))
Entropies_div_ns.append(Entropies[-1]/number_spins)
del model
data = {
'Model': model_name,
'Number_spins': number_spins_range,
'Periodic': periodic,
'Hamming_weight': hamming_weight,
'Sub_dim': sub_dim,
'Delta or h over J': param,
'Entropies': Entropies,
'Mutual Informations': MIs
}
timestr = time.strftime("%Y%m%d-%H%M%S")
filename = 'MI_fixed_param' + timestr
with open('output/' + filename + '.yaml', 'w') as outfile:
yaml.dump(data, outfile, default_flow_style=False)
print(filename)
plt.figure(figsize=(12,12))
plt.title('MI: ' + model_name + ' ' + str(param) + ' ' + str(periodic))
plt.plot(number_spins_range, Entropies_div_ns, label='Half-chain Entropy / Spin-Chain-Length')
plt.plot(number_spins_range, MIs, label='Mutual Information / SubDim--Length')
plt.grid(True)
plt.xlabel("Number Spins")
plt.legend()
plt.savefig('output/' + filename + '.png')
if __name__ == "__main__":
model_name = args.model_name
param_range = args.param_range
number_spins = args.number_spins
MI_vs_Entropy(model_name, number_spins, param_range)
\ No newline at end of file
spin_range = args.spin_range
param = args.param
MI_vs_Entropy(model_name, number_spins, param_range)
#MutInf(model_name, param, spin_range)
\ 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