mutual_information.py 2.66 KB
Newer Older
mgassner's avatar
mgassner committed
1
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 compute_MI, compute_entropy, reduced_dm

def test_mutual_information():
mgassner's avatar
mgassner committed
10
    # change return in compute_MI to run this function [S_A, S_B, S_AB] instead of S_A + S_B - S_AB
mgassner's avatar
mgassner committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
    model_name = 'xxz'
    number_spins = 10
    periodic = False
    spin_inversion = None
    param = 1.0
    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()
    print('EIGENSTATE at h/J = ', param, 'is: ', model.eigenstates[:,0])
    sub_dim = 4
    first_trace_spin = 4
    basis_states = model.basis.states
    gs = model.eigenstates[:,0]
    print('Number Spins: ', model.basis.number_spins)
    print('States', model.basis.states)
    print('Sub Dimension is ', sub_dim)
    entropies = compute_MI(sub_dim, number_spins, hamming_weight, gs, basis_states, spin_inversion=None, first_trace_spin=first_trace_spin)
    MI = entropies[0] + entropies[1] - entropies[2]
    print(MI)
    print(entropies)
    print('--------------------Test-----------------------')
    rhos4 = reduced_dm(4, number_spins, hamming_weight, gs, basis_states)
mgassner's avatar
mgassner committed
37
38
39
40
41
42
    rhos6 = reduced_dm(6, number_spins, hamming_weight, gs, basis_states)
    print(compute_entropy(rhos4), compute_entropy(rhos6))

def MI_vs_Entropy():

    model_name = 'xxz'
mgassner's avatar
mgassner committed
43
    dim = 18#[8, 10, 12, 14]#, 16, 18]
mgassner's avatar
mgassner committed
44
45
    periodic = False
    spin_inversion = None
mgassner's avatar
mgassner committed
46
    params = np.linspace(-2.0, 2.0, 41)
mgassner's avatar
mgassner committed
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68

    sub_dim = 4
    first_trace_spin = 4
    MIs = []
    Entropies = []

    print('Number Spins: ', dim)
    print('Sub Dimension is ', sub_dim)
    for param in params:
        if param < -1.0:
            hamming_weight = None
        else: 
            hamming_weight = dim // 2
        model = spin_model(model_name=model_name, number_spins=dim, 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, dim, hamming_weight, gs, basis_states, spin_inversion=None, first_trace_spin=first_trace_spin)
        MIs.append(MI)
        rho_half = reduced_dm(dim // 2, dim, hamming_weight, gs, basis_states)
        Entropies.append(compute_entropy(rho_half))
mgassner's avatar
mgassner committed
69
        del model
mgassner's avatar
mgassner committed
70
71
    
    plt.figure()
mgassner's avatar
..    
mgassner committed
72
    plt.plot(params, Entropies)
mgassner's avatar
mgassner committed
73
74
    plt.plot(params, MIs)
    plt.savefig('test.jpg')