To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

tfim.py 4.53 KB
Newer Older
mgassner's avatar
mgassner committed
1
2
3
4
5
6
7
8
import numpy as np
import yaml
import time
import matplotlib.pyplot as plt

from create_model import spin_model
from entropy_new import reduced_dm, compute_entropy

mgassner's avatar
mgassner committed
9
10
11
12
13
14
15
import argparse
parser = argparse.ArgumentParser()
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, required=False)
parser.add_argument("--boundary_condition", "-b", dest='periodic' ,type=bool, required=False)
args = parser.parse_args()

mgassner's avatar
mgassner committed
16
def test_tfim(number_spins, param_range, periodic = False):
mgassner's avatar
mgassner committed
17
    model_name = 'tfim'
mgassner's avatar
mgassner committed
18
    hamming_weight = None #number_spins // 2
mgassner's avatar
mgassner committed
19
    spin_inversion= None
mgassner's avatar
mgassner committed
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
    params = np.linspace(param_range[0], param_range[1], int(param_range[2]))
    entropies = []
    for param in params:
        model = spin_model(model_name=model_name, number_spins=number_spins, periodic=periodic, 
                                param=param, hamming_weight=hamming_weight)
        model.compute_ew_and_ev()
        # print('EIGENSTATE at h/J = ', param, 'is: ', model.eigenstates[:,0])
        gs = model.eigenstates[:,0]
        basis_states = model.basis.states
        sub_dim = number_spins // 2
        first_trace_spin = None #number_spins // 4
        rhos = reduced_dm(sub_dim, number_spins, hamming_weight, gs, basis_states, first_trace_spin=first_trace_spin)
        entropies.append(compute_entropy(rhos))
        del model

    plt.figure(figsize=(12, 12))
    plt.plot(params, entropies, label="half chain entropy")
    plt.legend()
    plt.xlabel('h / J')
    plt.ylabel('Bipartite Entanglement Entropy')
    plt.title('Model:' + model_name + str(number_spins) + str(periodic))
    plt.grid(True)
    timestr = time.strftime("%Y%m%d-%H%M%S")
    plt.savefig('output/' + timestr + 'entropytest.jpg')
mgassner's avatar
mgassner committed
44
    
mgassner's avatar
mgassner committed
45

mgassner's avatar
mgassner committed
46
def test_area_law(number_spins, periodic, param_range):
mgassner's avatar
mgassner committed
47
    model_name = 'tfim'
mgassner's avatar
mgassner committed
48
49
    spin_inversion = None
    params = np.linspace(param_range[0], param_range[1], int(param_range[2]))
mgassner's avatar
mgassner committed
50
    hamming_weight = None # TODO: ?????
mgassner's avatar
mgassner committed
51
52
53
54
55
    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, 
mgassner's avatar
mgassner committed
56
                                param=param, hamming_weight=hamming_weight, spin_inversion=spin_inversion)
mgassner's avatar
mgassner committed
57
58
59
60
61
62
        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)
mgassner's avatar
mgassner committed
63
64
            rhos = reduced_dm(sub_dim, number_spins, hamming_weight, gs, basis_states)
            bipartite_entropies.append(compute_entropy(rhos))
mgassner's avatar
mgassner committed
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
        entropies[str(param)] = bipartite_entropies
        del model
    
    data = {
        'Model': model_name,
        'Number_spins': number_spins,
        'Periodic': periodic,
        'Hamming_weight': hamming_weight,
        'Sub_dims': sub_dims,
        'Delta_over_J': params,
        'Entropies': entropies
    }

    timestr = time.strftime("%Y%m%d-%H%M%S")
    filename = 'test_area_law_tfim_' + timestr
    with open('output/' + filename + '.yaml', 'w') as outfile:
        yaml.dump(data, outfile, default_flow_style=False)
    print(filename)
    plt.figure(figsize=(12,12))
    i = 0
mgassner's avatar
mgassner committed
85
86
87
    x = np.array(sub_dims)/number_spins
    if spin_inversion:
        x -= 1/number_spins
mgassner's avatar
mgassner committed
88
89
    for key in entropies:
        if i % 5 == 0:
mgassner's avatar
mgassner committed
90
            plt.plot(np.array(sub_dims)/number_spins, entropies[key], label='h over J:' + key)
mgassner's avatar
mgassner committed
91
92
93
94
95
96
97
98
99
100
        i += 1
    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.grid(True)

    plt.savefig('output/' + filename + '.jpg')


mgassner's avatar
mgassner committed
101
    plt.figure(figsize=(12,12))
mgassner's avatar
mgassner committed
102
103
    half_chain_ee = []
    for key in entropies:
mgassner's avatar
mgassner committed
104
        half_chain_ee.append(entropies[key][number_spins // 2 - 1])
mgassner's avatar
mgassner committed
105
    plt.plot(params, half_chain_ee, label='h over J:' + key)
mgassner's avatar
mgassner committed
106
107
108
109
110
111
112
    plt.legend()
    plt.xlabel('Delta / J')
    plt.ylabel('Bipartite Entanglement Entropy')
    plt.title('Model:' + model_name + ' Number spins:' + str(number_spins))#, ' Periodic:' + str(periodic))
    plt.grid(True)

    plt.savefig('output/' + 'entropy_tfim_' + timestr + '.jpg')
mgassner's avatar
mgassner committed
113
114
115
116
117

if __name__ == "__main__":
    param_range = args.param_range
    number_spins = args.number_spins
    periodic = args.periodic
mgassner's avatar
mgassner committed
118
    #test_area_law(number_spins, periodic, param_range)
mgassner's avatar
mgassner committed
119
    test_tfim(number_spins, param_range)