heisenberg.py 3.77 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
8
9
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
10
def test_xxz():
mgassner's avatar
mgassner committed
11
    model_name = 'xxz'
mgassner's avatar
mgassner committed
12
13
14
15
    number_spins = 6
    periodic = False
    spin_inversion = None
    param = -2.0
mgassner's avatar
mgassner committed
16
    if param < -1.0:
mgassner's avatar
mgassner committed
17
        hamming_weight = 0
mgassner's avatar
mgassner committed
18
    else: 
mgassner's avatar
mgassner committed
19
        hamming_weight = number_spins // 2
mgassner's avatar
mgassner committed
20
    model = spin_model(model_name=model_name, number_spins=number_spins, periodic=periodic, 
mgassner's avatar
mgassner committed
21
                            param=param, hamming_weight=hamming_weight,  use_symmetries=False ,spin_inversion=spin_inversion)
mgassner's avatar
mgassner committed
22
23
    model.compute_ew_and_ev()
    print('EIGENSTATE at h/J = ', param, 'is: ', model.eigenstates[:,0])
mgassner's avatar
mgassner committed
24
    sub_dims = np.arange(1, number_spins)
mgassner's avatar
mgassner committed
25
26
27
28
29
    number_spins = model.number_spins()
    basis_states = model.basis.states
    gs = model.eigenstates[:,0]
    print('Number Spins: ', model.basis.number_spins)
    print('States', model.basis.states)
mgassner's avatar
mgassner committed
30
    for sub_dim in sub_dims:
mgassner's avatar
mgassner committed
31
32
        print('Sub Dimension is ', sub_dim)
        rhos = reduced_dm(sub_dim, number_spins, hamming_weight, gs, basis_states, spin_inversion)
mgassner's avatar
mgassner committed
33
        print(rhos)
mgassner's avatar
mgassner committed
34
35
36
        entropy = compute_entropy(rhos)
        print(entropy)
        print('-------------------------------------------')
mgassner's avatar
mgassner committed
37
    
mgassner's avatar
mgassner committed
38
39
def test_area_law():
    model_name = 'xxz'
mgassner's avatar
mgassner committed
40
    number_spins = 14
mgassner's avatar
mgassner committed
41
42
    periodic = True
    hamming_weight = number_spins // 2
mgassner's avatar
mgassner committed
43
44
    params = np.linspace(-2.0, 2.0, 41)
    spin_inversion=True
mgassner's avatar
mgassner committed
45
46
    
    entropies = {}
mgassner's avatar
mgassner committed
47
    sub_dims = [i for i in range(1,number_spins)]
mgassner's avatar
mgassner committed
48
    for param in params:
mgassner's avatar
mgassner committed
49
50
51
52
        if param < -1.0:
            hamming = None
        else: 
            hamming = hamming_weight
mgassner's avatar
mgassner committed
53
54
        bipartite_entropies = []
        model = spin_model(model_name=model_name, number_spins=number_spins, periodic=periodic, 
mgassner's avatar
mgassner committed
55
                                param=param, hamming_weight=hamming, spin_inversion=spin_inversion)
mgassner's avatar
mgassner committed
56
57
58
59
60
61
        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
62
            rhos = reduced_dm(sub_dim, number_spins, hamming_weight, gs, basis_states, spin_inversion)
mgassner's avatar
mgassner committed
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
            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
91
    plt.title('Model:' + model_name + ' Number spins:' + str(number_spins))#, ' Periodic:' + str(periodic))
mgassner's avatar
mgassner committed
92
93
94
95
96
    plt.grid(True)

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


mgassner's avatar
mgassner committed
97
    plt.figure(figsize=(8,8))
mgassner's avatar
mgassner committed
98
99
100
101
102
103
104
105
106
107
108
    half_chain_ee = []
    for key in entropies:
        half_chain_ee.append(entropies[key][7])
    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')