xxz.py 5.27 KB
Newer Older
mgassner's avatar
mgassner committed
1
from create_model import generate_symmetries
mgassner's avatar
mgassner committed
2
3
4
5
6
7
import numpy as np
import yaml
import time
import matplotlib.pyplot as plt

from create_model import spin_model
mgassner's avatar
mgassner committed
8
from entropy_new import _hamming_weight, reduced_dm, compute_entropy
mgassner's avatar
mgassner committed
9

mgassner's avatar
mgassner committed
10
11
12
13
14
15
16
17
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
18
def test_xxz(number_spins, param_range, periodic=True):
mgassner's avatar
mgassner committed
19
    model_name = 'xxz'
mgassner's avatar
mgassner committed
20
    params = np.linspace(param_range[0], param_range[1], int(param_range[2]))
mgassner's avatar
mgassner committed
21
    entropies = []
mgassner's avatar
mgassner committed
22
    hamming_weight = None #number_spins // 2
mgassner's avatar
mgassner committed
23
    for param in params:
mgassner's avatar
mgassner committed
24
25
        if param > -0.95:
            hamming_weight = number_spins // 2
mgassner's avatar
mgassner committed
26
        model = spin_model(model_name=model_name, number_spins=number_spins, periodic=periodic, 
mgassner's avatar
minor    
mgassner committed
27
                                param=param, hamming_weight=hamming_weight)
mgassner's avatar
mgassner committed
28
        model.compute_ew_and_ev()
mgassner's avatar
mgassner committed
29
        #print('EIGENSTATE at h/J = ', param, 'is: ', model.eigenstates[:,0])
mgassner's avatar
mgassner committed
30
31
        basis_states = model.basis.states
        gs = model.eigenstates[:,0]
mgassner's avatar
mgassner committed
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
        # just for testing
        if number_spins == 16 and param <= -1.1 and param > -1.4:
            print(gs[0])
            printi = []
            for i, x in enumerate(gs):
                if abs(x) > 1e-1:
                    printi.append([x, basis_states[i]])
            print(printi)
        if number_spins == 10 and param < -2.0:
            print(gs[0])
            printi = []
            for i, x in enumerate(gs):
                if abs(x) > 1e-2:
                    printi.append([x, basis_states[i]])
            print(printi)
mgassner's avatar
mgassner committed
47
48
        #print('Number Spins: ', model.basis.number_spins)
        #print('States', model.basis.states)
mgassner's avatar
mgassner committed
49
        sub_dim = number_spins // 2
mgassner's avatar
mgassner committed
50
        first_trace_spin = None #number_spins // 4
mgassner's avatar
mgassner committed
51
        rhos = reduced_dm(sub_dim, number_spins, hamming_weight, gs, basis_states, first_trace_spin=first_trace_spin)
mgassner's avatar
mgassner committed
52
        entropy = compute_entropy(rhos)
mgassner's avatar
mgassner committed
53
54
55
        entropies.append(entropy)

    plt.figure(figsize=(12, 12))
mgassner's avatar
minor    
mgassner committed
56
    plt.plot(params, entropies, label="half chain entropy")
mgassner's avatar
mgassner committed
57
58
59
    plt.legend()
    plt.xlabel('Delta / J')
    plt.ylabel('Bipartite Entanglement Entropy')
mgassner's avatar
mgassner committed
60
    plt.title('Model:' + model_name + str(number_spins) + str(periodic))
mgassner's avatar
mgassner committed
61
    plt.grid(True)
mgassner's avatar
mgassner committed
62
63
    timestr = time.strftime("%Y%m%d-%H%M%S")
    plt.savefig('output/' + timestr + 'entropytest.jpg')
mgassner's avatar
mgassner committed
64

mgassner's avatar
mgassner committed
65
    
mgassner's avatar
mgassner committed
66
def test_area_law(number_spins, periodic, param_range):
mgassner's avatar
mgassner committed
67
68
    model_name = 'xxz'
    hamming_weight = number_spins // 2
mgassner's avatar
mgassner committed
69
70
    params = np.linspace(param_range[0], param_range[1], int(param_range[2]))
    spin_inversion = None
mgassner's avatar
mgassner committed
71
    entropies = {}
mgassner's avatar
mgassner committed
72
    sub_dims = [i for i in range(1,number_spins)]
mgassner's avatar
mgassner committed
73
    for param in params:
mgassner's avatar
mgassner committed
74
        if param < -1.0:
mgassner's avatar
mgassner committed
75
            hamming = hamming_weight
mgassner's avatar
mgassner committed
76
77
        else: 
            hamming = hamming_weight
mgassner's avatar
mgassner committed
78
79
        bipartite_entropies = []
        model = spin_model(model_name=model_name, number_spins=number_spins, periodic=periodic, 
mgassner's avatar
mgassner committed
80
                                param=param, hamming_weight=hamming, spin_inversion=spin_inversion)
mgassner's avatar
mgassner committed
81
82
83
84
85
86
        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
87
            rhos = reduced_dm(sub_dim, number_spins, hamming_weight, gs, basis_states, spin_inversion)
mgassner's avatar
mgassner committed
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
            bipartite_entropies.append(compute_entropy(rhos))
        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_' + 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
    for key in entropies:
        if i % 5 == 0:
            plt.plot(np.array(sub_dims)/number_spins, entropies[key], label='Delta_over_J:' + key)
        i += 1
    plt.legend()
    plt.xlabel('x/L')
    plt.ylabel('Bipartite Entanglement Entropy')
mgassner's avatar
mgassner committed
116
    plt.title('Model:' + model_name + str(number_spins)+ str(periodic))
mgassner's avatar
mgassner committed
117
118
119
120
121
    plt.grid(True)

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


mgassner's avatar
mgassner committed
122
    plt.figure(figsize=(12, 12))
mgassner's avatar
mgassner committed
123
124
    half_chain_ee = []
    for key in entropies:
mgassner's avatar
mgassner committed
125
        half_chain_ee.append(entropies[key][number_spins // 2 - 1])
mgassner's avatar
mgassner committed
126
127
128
129
130
131
132
133
    plt.plot(params, half_chain_ee, label='Delta_over_J:' + key)
    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' + timestr + '.jpg')
mgassner's avatar
mgassner committed
134
135
136
137
138

if __name__ == "__main__":
    param_range = args.param_range
    number_spins = args.number_spins
    periodic = args.periodic
mgassner's avatar
mgassner committed
139
    #test_area_law(number_spins, periodic, param_range)
mgassner's avatar
mgassner committed
140
    test_xxz(number_spins, param_range)