-
Notifications
You must be signed in to change notification settings - Fork 2
/
netsyncanalysisQuantumDAGmodel.py
170 lines (115 loc) · 4.16 KB
/
netsyncanalysisQuantumDAGmodel.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# -*- coding: utf-8 -*-
"""
Created on Sat Feb 13 13:30:10 2021
@author: cosmi
"""
import matplotlib
matplotlib.use('TkAgg')
from pylab import *
import networkx as nx
from math import pi
import numpy as np
import scipy
import numpy as np
from scipy import misc
from matplotlib import pyplot as plt # For image viewing
from matplotlib import colors
from matplotlib import ticker
from matplotlib.colors import LinearSegmentedColormap
#new feature 2022
from qutip.visualization import plot_wigner, hinton
import operator
from random import random as rand
from random import uniform
import rustworkx as rx
from rustworkx.visualization import mpl_draw
#def gridsize(val):
# '''
# Number Of Particles in a Grid Shall Be Entered such that gridsize 4 = 4 x 4 i.e. 16
# Particles in Total. Note: this can only be changed at the start of a new
# Simulation Run - In This Version Do Note Change While Running the Simulation!
# '''
# global n
# n = int(val)
# return val
def initialize():
global g, nextg, A, nextA
n = 3
#g = nx.grid_graph(dim=[n,n])
#using dag
#g = nx.from_edgelist([dag], create_using=nx.DiGraph)
#construct classical network graph g from adjacency matrix
g = nx.scale_free_graph(n) #obtain a directed acyclic graph
#remove self loops
g.remove_edges_from(nx.selfloop_edges(g))
#g = nx.karate_club_graph()
for i in list(g.nodes()):
g.node[i]['theta'] = 2 * pi * random()
#rows, cols = (-0.05, 0.05)
#arr = [[rand.randrange(10) for i in range(int(cols))] for j in range(int(rows))]
#a = numpy.asarray(arr)
#g.node[i]['omega'] = 1. + rand.uniform(-0.05, 0.05)
g.node[i]['omega'] = 1. + uniform(-0.05, 0.05)
nextg = g.copy()
for i in list(g.nodes()):
g.node[i]['theta'] = random()
nextg = g.copy()
#for space vs time graph
xdata = []
ydata = []
def observe():
global g, nextg
subplot(1,2,1)
cla()
nx.draw(g, cmap = cm.hsv, vmin = -1, vmax = 1,
node_color = [np.sin(g.node[i]['theta']) for i in list(g.nodes())],
pos = nx.spring_layout(g) )
axis('image')
subplot(1,2,2)
cla()
plot([np.cos(g.node[i]['theta']) for i in list(g.nodes())],
[np.sin(g.node[i]['theta']) for i in list(g.nodes())], '.')
axis('image')
axis([-1.1,1.1,-1.1,1.1])
#subplot(1,2,2)
#cla()
#plot(xdata, ydata,'o',alpha = 0.05)
#axis('image')
# for space vs time plotting (chimera search)
alpha = 2 # coupling strength
beta = 1 # acceleration rate
Dt = 0.01 # Delta t
#def update():
# global g, nextg
# for i in list(g.nodes()):
# theta_i = g.node[i]['theta']
# nextg.node[i]['theta'] = theta_i + (beta * theta_i + alpha * (np.sum(sin(g.node[j]['theta'] - theta_i) for j in g.neighbors(i))) * Dt)
# g, nextg = nextg, g
def update():
global g, nextg, A, k_in, L
for i in list(g.nodes()):
theta_i = g.node[i]['theta']
nextg.node[i]['theta'] = theta_i + (g.node[i]['omega'] + alpha * ( \
sum(np.sin(g.node[j]['theta'] - theta_i) for j in g.neighbors(i)) \
/ g.degree(i))) * Dt
g, nextg = nextg, g
A = nx.adj_matrix(nextg).todense()
k_in = np.zeros(nextg.number_of_nodes())
L = np.diag(k_in) - A
#for i, j in list(g.nodes()):
#xdata.append(g.degree(i))
#ccs = nx.connected_components(g)
#ydata.append(max(len(cc) for cc in ccs))
#xdata.append(g.degree(i)); ydata.append(g.degree(j))
#xdata.append(g.degree(j)); ydata.append(g.degree(i))
import pycxsimulator
pycxsimulator.GUI().start(func=[initialize, observe, update])
#plt.figure(1)
#compare red and blue pixel data
#nbins = 20
#plt.hexbin(x=plot_time_stamp, y=plot_agent, gridsize=nbins, cmap=plt.cm.jet)
#plt.xlabel('Blue Reflectance')
#plt.ylabel('NIR Reflectance')
# Add a title
#plt.title('NIR vs Blue Spectral Data')
#plt.show()