This repository has been archived by the owner on Oct 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
plot.py
196 lines (180 loc) · 5.75 KB
/
plot.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import plotly.express as px
import plotly.graph_objects as go
import numpy as np
import pandas as pd
import scipy
from scipy import signal
import pickle
from plotly.subplots import make_subplots
import torch
import torch.nn.functional as F
import plotly.express as px
def smooth(scalars, weight): # Weight between 0 and 1
last = scalars[0] # First value in the plot (first timestep)
smoothed = list()
for point in scalars:
smoothed_val = last * weight + (1 - weight) * point # Calculate smoothed value
smoothed.append(smoothed_val) # Save it
last = smoothed_val # Anchor the last smoothed value
return smoothed
def plot_attn():
fname = '../att_/attn_150000_'
all_data = []
key ='attn'
for i in range(0, 17):
with open(fname+str(i)+'.pkl', "rb") as file:
data = pickle.load(file)
all_data.append(data[key])
fig = make_subplots(2,9)
for i in range(0, 8):
d = torch.sum(all_data[i], dim=0, keepdim=True)
d = F.softmax(d, dim=1)
fig.add_trace(go.Heatmap(z = d, zmin=0, zmax=1, colorscale = 'Viridis', y=[str(i)]), 1, i+1)
fig.layout.height = 500
for i in range(8, 16):
d = torch.sum(all_data[i], dim=0, keepdim=True)
d = F.softmax(d, dim=1)
fig.add_trace(go.Heatmap(z = d, zmin=0, zmax=1, colorscale = 'Viridis', y=[str(i)]), 2, i+1-8)
fig.layout.height = 500
d = torch.sum(all_data[16], dim=0, keepdim=True)
d = F.softmax(d, dim=1)
fig.add_trace(go.Heatmap(z = d, zmin=0, zmax=1, colorscale = 'Viridis', y=['16']), 2, 9)
fig.layout.height = 500
fig.update_layout(coloraxis = {'colorscale':'viridis'})
fig.show()
fig.write_image("att.pdf")
def plot_topologicalorder():
df = pd.read_csv('with_without_topologicalorder_nodeplace_ff_gnn_attention/no_ordered_data.csv')
df2 = pd.read_csv('with_without_topologicalorder_nodeplace_ff_gnn_attention/ordered_data.csv')
fig = go.Figure()
fig.add_trace(go.Scatter(
x=df2['Step'], y=smooth(df2['Value'], 0.9),
name="Ordered"
))
fig.add_trace(go.Scatter(
x=df['Step'], y=smooth(df['Value'], 0.1),
name="Not Ordered"
))
fig.update_layout(
xaxis_title="Epochs",
yaxis_title="Rewards",
xaxis_range=[2000, 15000],
showlegend=True,
font=dict(
family="Courier New, monospace",
size=20,
)
)
fig.show()
fig.write_image("topologicalorder.pdf")
def plot_ppo():
df = pd.read_csv('ifft_reward/ppo_data.csv')
df2 = pd.read_csv('ifft_reward/ppo_gnn_transform_data.csv')
fig = go.Figure()
fig.add_trace(go.Scatter(
x=df2['Step'], y=smooth(df2['Value'], 0.99),
name="GGA+MLP"
))
fig.add_trace(go.Scatter(
x=df['Step'], y=smooth(df['Value'], 0.99),
name="MLP"
))
fig.update_layout(
xaxis_title="Epochs",
yaxis_title="Rewards",
xaxis_range=[10000, 150000],
showlegend=True,
font=dict(
family="Courier New, monospace",
size=20,
)
)
fig.show()
fig.write_image("ppo.pdf")
def plot_masking():
df = pd.read_csv('with_nomask/ff_gnn_ifft_loop_with_mask.csv')
df2 = pd.read_csv('with_nomask/ff_gnn_ifft_loop_without_mask2.csv')
fig = go.Figure()
fig.add_trace(go.Scatter(
x=df['Step'], y=smooth(df['Value'], 0.99),
name="With Mask"
))
fig.add_trace(go.Scatter(
x=df2['Step'], y=smooth(df2['Value'], 0.99),
name="Without Mask"
))
fig.update_layout(
xaxis_title="Epochs",
yaxis_title="Rewards",
xaxis_range=[2000, 100000],
showlegend=True,
font=dict(
family="Courier New, monospace",
size=20,
)
)
fig.show()
fig.write_image("masking.pdf")
def plot_scaling_nodes():
df = pd.read_csv('nodes_data.csv')
print(df)
fig = px.bar(df, x='nodes', y=['MLP', 'GGA+MLP'], barmode='group')
fig.update_xaxes(type='category')
fig.update_layout(
title = " 16 tiles 64 tiles",
xaxis_title="Number of Nodes",
yaxis_title="Best schedule cycle count",
showlegend=True,
)
fig.show()
fig.write_image("scaling_nodes.pdf")
def plot_pretrain():
df = pd.read_csv('with_pretrain/run_after_pretrain_ifft_loop.csv')
df2 = pd.read_csv('with_pretrain/run_ff_gnn_attention_ifft_nopretrain.csv')
fig = go.Figure()
fig.add_trace(go.Scatter(
x=df['Step'], y=smooth(df['Value'], 0.99),
name="fine-tuned"
))
fig.add_trace(go.Scatter(
x=df2['Step'], y=smooth(df2['Value'], 0.99),
name="scratch"
))
fig.update_layout(
xaxis_title="Epochs",
yaxis_title="Rewards",
xaxis_range=[1000, 70000],
showlegend=True,
font=dict(
family="Courier New, monospace",
size=20,
)
)
fig.show()
fig.write_image("pretrain.pdf")
def plot_sa():
df = pd.read_csv('experiments/compare_sa/ppo_gnn_transform_data.csv')
df2 = pd.read_csv('experiments/compare_sa/simulated_anneal_ifft.csv')
fig = go.Figure()
fig.add_trace(go.Scatter(
x=df['Step'], y=smooth(df['Value'], 0.99),
name="GGA+MLP"
))
fig.add_trace(go.Scatter(
x=df2['Step'], y=smooth(df2['Value'], 0.99),
name="SA"
))
fig.update_layout(
xaxis_title="Epochs",
yaxis_title="Rewards",
xaxis_range=[2000, 100000],
showlegend=True,
font=dict(
family="Courier New, monospace",
size=20,
)
)
fig.show()
fig.write_image("sa.pdf")
if __name__ == "__main__":
pass