mutual_information.py 1.46 KB
Newer Older
mgassner's avatar
mgassner committed
1
2
3
4
5
6
7
8
9
10
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
37
38
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():
    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
    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)
    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)
    rhos8 = reduced_dm(4, number_spins, hamming_weight, gs, basis_states)
    print(compute_entropy(rhos4), compute_entropy(rhos8))