cyrusyc commited on
Commit
f7e9143
1 Parent(s): bcf00b7

add cache for stability page

Browse files
mlip_arena/models/registry.yaml CHANGED
@@ -108,6 +108,7 @@ SevenNet:
108
  - qmof
109
  gpu-tasks:
110
  - homonuclear-diatomics
 
111
  - combustion
112
  github: https://github.com/MDIL-SNU/SevenNet
113
  doi: https://doi.org/10.1021/acs.jctc.4c00190
 
108
  - qmof
109
  gpu-tasks:
110
  - homonuclear-diatomics
111
+ - stability
112
  - combustion
113
  github: https://github.com/MDIL-SNU/SevenNet
114
  doi: https://doi.org/10.1021/acs.jctc.4c00190
serve/tasks/stability.py CHANGED
@@ -53,14 +53,21 @@ color_sequence = color_palettes[palette_name]
53
  if not models:
54
  st.stop()
55
 
56
- families = [REGISTRY[str(model)]["family"] for model in models]
 
57
 
58
- dfs = [
59
- pd.read_json(DATA_DIR / family.lower() / "chloride-salts.json")
60
- for family in families
61
- ]
62
- df = pd.concat(dfs, ignore_index=True)
63
- df.drop_duplicates(inplace=True, subset=["material_id", "formula", "method"])
 
 
 
 
 
 
64
 
65
  method_color_mapping = {
66
  method: color_sequence[i % len(color_sequence)]
@@ -69,8 +76,6 @@ method_color_mapping = {
69
 
70
  ###
71
 
72
- fig = go.Figure()
73
-
74
  # Determine the bin edges for the entire dataset to keep them consistent across groups
75
  # bins = np.histogram_bin_edges(df['total_steps'], bins=10)
76
 
@@ -101,63 +106,68 @@ counts_per_method = {k: v for k, v in sorted(counts_per_method.items(), key=lamb
101
 
102
 
103
  count_or_percetange = st.toggle("show counts", False)
104
- # Create a figure
105
- fig = go.Figure()
106
-
107
- # Add a bar for each bin range across all methods
108
- for i, bin_label in enumerate(bin_labels):
109
- for method, counts in counts_per_method.items():
110
- fig.add_trace(go.Bar(
111
- # name=method, # This will be the legend entry
112
- x=[counts[i]/counts.sum()*100] if not count_or_percetange else [counts[i]],
113
- y=[method], # Method as the y-axis category
114
- # name=bin_label,
115
- orientation="h", # Horizontal bars
116
- marker=dict(
117
- color=bin_colors[i],
118
- line=dict(color="rgb(248, 248, 249)", width=1)
119
- ),
120
- text=f"{bin_label}: {counts[i]/counts.sum()*100:.0f}%",
121
- width=0.5
122
- ))
123
-
124
- # Update the layout to stack the bars
125
- fig.update_layout(
126
- barmode="stack", # Stack the bars
127
- title="Total MD steps (before crash or completion)",
128
- xaxis_title="Percentage (%)" if not count_or_percetange else "Count",
129
- yaxis_title="Method",
130
- showlegend=False
131
- )
132
-
133
- # bins = np.linspace(0, 0.9, 10)
134
-
135
- # for method, data in df.groupby("method"):
136
-
137
- # # print(method, data)
138
- # counts, bins = np.histogram(data['total_steps'])
139
-
140
- # bin_labels = [f"{int(bins[i])}-{int(bins[i+1])}" for i in range(len(bins)-1)]
141
-
142
- # # Create a horizontal bar chart
143
- # fig = go.Figure(go.Bar(
144
- # x=[counts[i]], # Count for this bin
145
- # y=[method], # Method as the y-axis category
146
- # # x=counts, # Bar lengths
147
- # # y=bin_labels, # Bin labels as y-tick labels
148
- # orientation='h' # Horizontal bars
149
- # ))
150
-
151
-
152
- # # Update layout for clarity
153
- # fig.update_layout(
154
- # title="Histogram of Total Steps",
155
- # xaxis_title="Count",
156
- # yaxis_title="Total Steps Range"
157
- # )
158
-
159
- st.plotly_chart(fig)
160
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
 
162
  ###
163
 
@@ -166,44 +176,49 @@ st.plotly_chart(fig)
166
 
167
  # """)
168
 
169
- fig = px.scatter(
170
- df,
171
- x="natoms",
172
- y="steps_per_second",
173
- color="method",
174
- size="total_steps",
175
- hover_data=["material_id", "formula"],
176
- color_discrete_map=method_color_mapping,
177
- # trendline="ols",
178
- # trendline_options=dict(log_x=True),
179
- log_x=True,
180
- # log_y=True,
181
- # range_y=[1, 1e2],
182
- range_x=[df["natoms"].min()*0.9, df["natoms"].max()*1.1],
183
- # range_x=[1e3, 1e2],
184
- title="Inference speed (on single A100 GPU)",
185
- labels={"steps_per_second": "Steps per second", "natoms": "Number of atoms"},
186
- )
187
-
188
-
189
  def func(x, a, n):
190
  return a * x ** (-n)
191
 
192
- x = np.linspace(df["natoms"].min(), df["natoms"].max(), 100)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193
 
194
- for method, data in df.groupby("method"):
195
- data.dropna(subset=["steps_per_second"], inplace=True)
196
- popt, pcov = curve_fit(func, data["natoms"], data["steps_per_second"])
197
 
198
- fig.add_trace(go.Scatter(
199
- x=x,
200
- y=func(x, *popt),
201
- mode="lines",
202
- # name='Fit',
203
- line=dict(color=method_color_mapping[method], width=3),
204
- showlegend=False,
205
- name=f"{popt[0]:.2f}N^{-popt[1]:.2f}",
206
- hovertext=f"{popt[0]:.2f}N^{-popt[1]:.2f}",
207
- ))
208
 
209
- st.plotly_chart(fig)
 
53
  if not models:
54
  st.stop()
55
 
56
+ @st.cache_data
57
+ def get_data(models):
58
 
59
+ families = [REGISTRY[str(model)]["family"] for model in models]
60
+
61
+ dfs = [
62
+ pd.read_json(DATA_DIR / family.lower() / "chloride-salts.json")
63
+ for family in families
64
+ ]
65
+ df = pd.concat(dfs, ignore_index=True)
66
+ df.drop_duplicates(inplace=True, subset=["material_id", "formula", "method"])
67
+
68
+ return df
69
+
70
+ df = get_data(models)
71
 
72
  method_color_mapping = {
73
  method: color_sequence[i % len(color_sequence)]
 
76
 
77
  ###
78
 
 
 
79
  # Determine the bin edges for the entire dataset to keep them consistent across groups
80
  # bins = np.histogram_bin_edges(df['total_steps'], bins=10)
81
 
 
106
 
107
 
108
  count_or_percetange = st.toggle("show counts", False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
 
110
+ @st.experimental_fragment()
111
+ def plot_md_steps(counts_per_method, count_or_percetange):
112
+ # Create a figure
113
+ fig = go.Figure()
114
+
115
+ # Add a bar for each bin range across all methods
116
+ for i, bin_label in enumerate(bin_labels):
117
+ for method, counts in counts_per_method.items():
118
+ fig.add_trace(go.Bar(
119
+ # name=method, # This will be the legend entry
120
+ x=[counts[i]/counts.sum()*100] if not count_or_percetange else [counts[i]],
121
+ y=[method], # Method as the y-axis category
122
+ # name=bin_label,
123
+ orientation="h", # Horizontal bars
124
+ marker=dict(
125
+ color=bin_colors[i],
126
+ line=dict(color="rgb(248, 248, 249)", width=1)
127
+ ),
128
+ text=f"{bin_label}: {counts[i]/counts.sum()*100:.0f}%",
129
+ width=0.5
130
+ ))
131
+
132
+ # Update the layout to stack the bars
133
+ fig.update_layout(
134
+ barmode="stack", # Stack the bars
135
+ title="Total MD steps (before crash or completion)",
136
+ xaxis_title="Percentage (%)" if not count_or_percetange else "Count",
137
+ yaxis_title="Method",
138
+ showlegend=False
139
+ )
140
+
141
+ # bins = np.linspace(0, 0.9, 10)
142
+
143
+ # for method, data in df.groupby("method"):
144
+
145
+ # # print(method, data)
146
+ # counts, bins = np.histogram(data['total_steps'])
147
+
148
+ # bin_labels = [f"{int(bins[i])}-{int(bins[i+1])}" for i in range(len(bins)-1)]
149
+
150
+ # # Create a horizontal bar chart
151
+ # fig = go.Figure(go.Bar(
152
+ # x=[counts[i]], # Count for this bin
153
+ # y=[method], # Method as the y-axis category
154
+ # # x=counts, # Bar lengths
155
+ # # y=bin_labels, # Bin labels as y-tick labels
156
+ # orientation='h' # Horizontal bars
157
+ # ))
158
+
159
+
160
+ # # Update layout for clarity
161
+ # fig.update_layout(
162
+ # title="Histogram of Total Steps",
163
+ # xaxis_title="Count",
164
+ # yaxis_title="Total Steps Range"
165
+ # )
166
+
167
+ st.plotly_chart(fig)
168
+
169
+
170
+ plot_md_steps(counts_per_method, count_or_percetange)
171
 
172
  ###
173
 
 
176
 
177
  # """)
178
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
  def func(x, a, n):
180
  return a * x ** (-n)
181
 
182
+ @st.experimental_fragment()
183
+ def plot_speed(df, method_color_mapping):
184
+
185
+ fig = px.scatter(
186
+ df,
187
+ x="natoms",
188
+ y="steps_per_second",
189
+ color="method",
190
+ size="total_steps",
191
+ hover_data=["material_id", "formula"],
192
+ color_discrete_map=method_color_mapping,
193
+ # trendline="ols",
194
+ # trendline_options=dict(log_x=True),
195
+ log_x=True,
196
+ # log_y=True,
197
+ # range_y=[1, 1e2],
198
+ range_x=[df["natoms"].min()*0.9, df["natoms"].max()*1.1],
199
+ # range_x=[1e3, 1e2],
200
+ title="Inference speed (on single A100 GPU)",
201
+ labels={"steps_per_second": "Steps per second", "natoms": "Number of atoms"},
202
+ )
203
+
204
+ x = np.linspace(df["natoms"].min(), df["natoms"].max(), 100)
205
+
206
+ for method, data in df.groupby("method"):
207
+ data.dropna(subset=["steps_per_second"], inplace=True)
208
+ popt, pcov = curve_fit(func, data["natoms"], data["steps_per_second"])
209
+
210
+ fig.add_trace(go.Scatter(
211
+ x=x,
212
+ y=func(x, *popt),
213
+ mode="lines",
214
+ # name='Fit',
215
+ line=dict(color=method_color_mapping[method], width=3),
216
+ showlegend=False,
217
+ name=f"{popt[0]:.2f}N^{-popt[1]:.2f}",
218
+ hovertext=f"{popt[0]:.2f}N^{-popt[1]:.2f}",
219
+ ))
220
 
221
+ st.plotly_chart(fig)
 
 
222
 
 
 
 
 
 
 
 
 
 
 
223
 
224
+ plot_speed(df, method_color_mapping)