-
Notifications
You must be signed in to change notification settings - Fork 2
/
01_MBL_Produce_data_DANN.py
149 lines (130 loc) · 5.05 KB
/
01_MBL_Produce_data_DANN.py
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
39
40
41
42
43
44
45
46
47
48
49
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
from quspin.operators import hamiltonian # Hamiltonians and operators
from quspin.basis import spin_basis_1d # Hilbert space spin basis
import numpy as np # generic math functions
import h5py
from keras.utils.io_utils import HDF5Matrix
#np.random.seed(seed = 1)
##### define model parameters #####
L = 12 # system size
Jxy = 1.0 # xy interaction
Jzz_0 = 1.0 # zz interaction
hmax = 0.9
def Hamilt_qspin(Jxy, Jzz_0, hmax, N):
#basis = spin_basis_1d(L,pauli=False)
no_checks = {"check_herm": False, "check_pcon": False, "check_symm": False}
basis = spin_basis_1d(
N, pauli=False, Nup=N // 2) # zero magnetisation sector
#pauli false indicates that we use 1/2 sigma convention
#Nup is the number of spins pointing up.
hz = np.random.uniform(-hmax, hmax, N)
# define operators with OBC using site-coupling lists
J_zz = [[Jzz_0, i, (i + 1) % N] for i in range(N)] # PBC
J_xy = [[Jxy / 2.0, i, (i + 1) % N] for i in range(N)] # PBC
h_z = [[hz[i], i] for i in range(N)]
# static and dynamic lists
static = [["+-", J_xy], ["-+", J_xy], ["zz", J_zz]]
disorder_field = [["z", h_z]]
dynamic = []
# compute the time-dependent Heisenberg Hamiltonian
H_XXZ = hamiltonian(
static, dynamic, basis=basis, dtype=np.float64, **no_checks)
Hz = hamiltonian(
disorder_field, [], basis=basis, dtype=np.float64, **no_checks)
Htot = H_XXZ + Hz
Hqspin = Htot.todense() #makes it to a normal numpy matrix
return Hqspin
def statistics(n, E):
delta_n = (E[n] - E[n - 1])
delta_np1 = (E[n + 1] - E[n])
#print(delta_n, delta_np1, min(delta_n, delta_np1)/max(delta_n, delta_np1))
return min(delta_n, delta_np1) / max(delta_n, delta_np1)
def find_epsilon_index(Energies, epsilon):
# find epsilon = 0.5
# 0.5 = (E-Emax)/(Emin-Emax) --> E = 0.5*(Emin+Emax)
targetE = epsilon * (Energies[0] - Energies[-1]) + Energies[-1]
return np.abs(np.array(Energies) - targetE).argmin()
def mean_energy(samples, energies, hmax):
epsilon_index = find_epsilon_index(energies, 0.5)
deltas = []
for n in range(
max(1, epsilon_index - 25),
min(len(energies) - 1,
epsilon_index + 25)): #for n in range(1,2**N-1): #
deltas.append(statistics(n, energies))
mean = np.mean(deltas)
return mean, epsilon_index
hmax_list = [0.9,
5.0] #These are two values deep in the phases with good values
hmax_list = np.linspace(1.0, 4.8, 20)
samples = 10
labels = []
state_list = []
liste = []
for hmax in hmax_list:
stat = 0.0
for i in range(samples):
print(hmax, i)
H = Hamilt_qspin(Jxy, Jzz_0, hmax, L)
energies, states = np.linalg.eig(H)
sort_indices = energies.argsort()
energies = energies[sort_indices]
states = states[sort_indices]
#energies = np.sort(energies)
mean, epsilon_index = mean_energy(samples, energies, hmax)
stat += mean
for i in states[max(1, epsilon_index -
25):min(len(energies) - 1, epsilon_index + 25)]:
psi = np.asarray(i)
psi = psi.reshape(psi.shape[1], )
state_list.append(psi)
if hmax < 2.0:
labels.append([1, 0])
else:
labels.append([0, 1])
liste.append(stat / samples)
#import matplotlib.pyplot as plt
#plt.close()
#plt.plot(np.arange(0.2, 5.0, 0.2), liste)
#plt.savefig('N12_test')
folder = 'MBL_data/'
filename = folder + 'TARGET_Set_09_to_50_2' + '_N' + str(L) + '.h5'
f = h5py.File(filename, 'w')
# Creating dataset to store features
X_dset = f.create_dataset(
'my_data', (len(labels), state_list[0].shape[0]), dtype='f')
X_dset[:] = state_list
# Creating dataset to store labels
y_dset = f.create_dataset('my_labels', (len(labels), 2), dtype='i')
y_dset[:] = labels
f.close()
"""
# -----------------------------------------------------------------------------
# QUTIP Hamiltonian
from scipy.sparse import csr_matrix, rand
#import matplotlib
#matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
import qutip as qt
import scipy.sparse.linalg as sl
plt.close()
# Hamiltonian from Many-body localization edge in the random-field Heisenberg chain
# https://arxiv.org/pdf/1411.0660.pdf
# In the paper they set J=Jz=1
def Hamiltonian_Heisenberg_chain(hmax, sigmax, sigmay, sigmaz, N, J, Jz):
hz = np.random.uniform(-hmax, hmax, N)
hz = hzfix
#hz = [2]*N
H = np.sum(Jz*(sigmaz[j]*sigmaz[(j+1)%N]) + J*(sigmax[j]*sigmax[(j+1)%N]\
+ sigmay[j]*sigmay[(j+1)%N]) + hz[j]*sigmaz[j] for j in range(N)) #- hz[N-1]*sigmaz[N-1]
return H
N = L
qubitfactor = 1/2.0
sigmax = [qubitfactor*qt.tensor([qt.qeye(2)]*(j-1) + [qt.sigmax()] + [qt.qeye(2)]*(N-j))
for j in range(1, N+1)]
sigmay = [qubitfactor*qt.tensor([qt.qeye(2)]*(j-1) + [qt.sigmay()] + [qt.qeye(2)]*(N-j))
for j in range(1, N+1)]
sigmaz = [qubitfactor*qt.tensor([qt.qeye(2)]*(j-1) + [qt.sigmaz()] + [qt.qeye(2)]*(N-j))
for j in range(1, N+1)]
H = Hamiltonian_Heisenberg_chain(hmax, sigmax, sigmay, sigmaz, N, 0.0, 0.0)
"""