tfim.py 3.23 KB
Newer Older
mgassner's avatar
mgassner committed
1
2
3
4
5
6
7
8
9
10
11
12
13
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

def test_tfim():
    model_name = 'tfim'
    number_spins = 4
    periodic = True
    hamming_weight = number_spins // 2
mgassner's avatar
mgassner committed
14
    param = 1.0
mgassner's avatar
mgassner committed
15
    model = spin_model(model_name=model_name, number_spins=number_spins, periodic=periodic, 
mgassner's avatar
mgassner committed
16
                            param=param, hamming_weight=None)#hamming_weight)
mgassner's avatar
mgassner committed
17
18
19
20
21
22
23
24
    model.compute_ew_and_ev()
    print('EIGENSTATE at h/J = ', param, 'is: ', model.eigenstates[:,0])
    sub_dim = 2
    model.compute_ew_and_ev()
    gs = model.eigenstates[:,0]
    basis_states = model.basis.states
    print('Number Spins: ', model.basis.number_spins)
    print('States', model.basis.states)
mgassner's avatar
mgassner committed
25
    rhos = reduced_dm(sub_dim, number_spins, 0, gs, basis_states)
mgassner's avatar
mgassner committed
26
27
28
29
30
31
    print(rhos)
    entropy = compute_entropy(rhos)
    print(entropy)

def test_area_law_tfim():
    model_name = 'tfim'
mgassner's avatar
mgassner committed
32
    number_spins = 14
mgassner's avatar
mgassner committed
33
    periodic = True
mgassner's avatar
mgassner committed
34
35
    params = np.linspace(0.0, 1.5, 21)
    hamming_weight = None # TODO: ?????
mgassner's avatar
mgassner committed
36
37
38
39
40
    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
41
                                param=param, hamming_weight=hamming_weight)
mgassner's avatar
mgassner committed
42
43
44
45
46
47
        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
48
49
            rhos = reduced_dm(sub_dim, number_spins, hamming_weight, gs, basis_states)
            bipartite_entropies.append(compute_entropy(rhos))
mgassner's avatar
mgassner committed
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
        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
    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')
    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))
    half_chain_ee = []
    for key in entropies:
        half_chain_ee.append(entropies[key][5])
    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_tfim_' + timestr + '.jpg')