-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpinGlass.jl
61 lines (44 loc) · 1.25 KB
/
SpinGlass.jl
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
addprocs(CPU_CORES)
@everywhere const n=20
@everywhere const sdJ=1/sqrt(n)
@everywhere const meanJ=0
trials=600
@everywhere function bitarray(int::Int)
2*digits(int,2,n)-1
end
@everywhere function energy(index, J)
c=bitarray(index)
-sum(J.*reshape(kron(c,c),(n,n)))
end
@everywhere function distance(a::Int,b::Int)
min(sum(digits(a$b,2,n)),sum(digits((2^(n+1)-1-a)$b,2,n)))
end
@everywhere function energydifferance(energies)
lowenergy=findmin(energies)
energies[lowenergy[2]]=NaN
secondlow=findmin(energies)
[lowenergy[1]-secondlow[1],distance(lowenergy[2]-1,secondlow[2]-1)]
end
@everywhere function energyinstance(J)
energydifferance([energy(i,J) for i=0:2^(n-1)-1])
end
gapdistance=@parallel (vcat) for i=1:trials
transpose(energyinstance(randn(n,n)*sdJ+meanJ))
end
rmprocs(workers())
using PyPlot
PyPlot.plt.hist(gapdistance[:,2],ceil(n/2))
title("histogram of required flips ")
ylabel("number of states")
xlabel("flips")
show()
PyPlot.plt.hist(gapdistance[:,1],40)
title("histogram of the energy gap ")
ylabel("number of states")
xlabel("energy gap")
show()
scatter(gapdistance[:,2],gapdistance[:,1],color="black")
title("energy gap vs required flips")
xlabel("required flips")
ylabel("energy gap")
show()