@@ -180,40 +180,35 @@ def chemical_reaction_model(df: pd.DataFrame) -> pd.DataFrame:
180
180
181
181
results_log = []
182
182
183
- for iteration in range (N_ITERATIONS ):
183
+ for it in range (N_ITERATIONS ):
184
184
recommendations = campaign .recommend (batch_size = BATCH_SIZE )
185
185
186
186
reaction_results = lookup (recommendations )
187
187
measurements = pd .concat ([recommendations , reaction_results ], axis = 1 )
188
-
189
188
campaign .add_measurements (measurements )
190
-
191
- total_solvent = recommendations ["Solvent_Volume" ].sum ()
192
- total_catalyst = recommendations ["Catalyst_Loading" ].sum ()
193
-
194
- solvent_ok = abs (total_solvent - 60.0 ) < TOLERANCE
195
- catalyst_ok = total_catalyst <= (30.0 + TOLERANCE )
189
+ total_sol = recommendations ["Solvent_Volume" ].sum ()
190
+ total_cat = recommendations ["Catalyst_Loading" ].sum ()
191
+ solvent_ok = abs (total_sol - 60.0 ) < TOLERANCE
192
+ catalyst_ok = total_cat <= (30.0 + TOLERANCE )
196
193
197
194
assert solvent_ok , (
198
- f"Solvent constraint violated: { total_solvent :.1f} mL (expected 60.0 mL)"
195
+ f"Solvent constraint violated: { total_sol :.1f} mL (expected 60.0 mL)"
199
196
)
200
197
assert catalyst_ok , (
201
- f"Catalyst constraint violated: { total_catalyst :.1f} mol% (max 30.0 mol%)"
198
+ f"Catalyst constraint violated: { total_cat :.1f} mol% (max 30.0 mol%)"
202
199
)
203
200
204
201
results_log .append (
205
202
{
206
- "iteration" : iteration + 1 ,
207
- "total_solvent_mL" : total_solvent ,
208
- "total_catalyst_mol%" : total_catalyst ,
203
+ "iteration" : it + 1 ,
204
+ "total_solvent_mL" : total_sol ,
205
+ "total_catalyst_mol%" : total_cat ,
209
206
"individual_solvent_mL" : recommendations ["Solvent_Volume" ].tolist (),
210
207
"individual_catalyst_mol%" : recommendations ["Catalyst_Loading" ].tolist (),
211
208
}
212
209
)
213
210
214
- print (
215
- f"Batch { iteration + 1 } : Solvent={ total_solvent :.1f} mL, Catalyst={ total_catalyst :.1f} mol%"
216
- )
211
+ print (f"Batch { it + 1 } : Solvent={ total_sol :.1f} mL, Catalyst={ total_cat :.1f} mol%" )
217
212
218
213
# ## Visualization
219
214
@@ -224,56 +219,58 @@ def chemical_reaction_model(df: pd.DataFrame) -> pd.DataFrame:
224
219
225
220
results_df = pd .DataFrame (results_log )
226
221
227
- fig , ( ax1 , ax2 ) = plt .subplots (1 , 2 , figsize = (10 , 4 ))
222
+ fig , axs = plt .subplots (1 , 2 , figsize = (10 , 4 ))
228
223
224
+ plt .sca (axs [0 ])
229
225
for exp_idx in range (BATCH_SIZE ):
230
226
individual_values = [
231
227
batch [exp_idx ] for batch in results_df ["individual_solvent_mL" ]
232
228
]
233
- ax1 .plot (
229
+ plt .plot (
234
230
results_df ["iteration" ],
235
231
individual_values ,
236
232
"o-" ,
237
233
alpha = 0.6 ,
238
234
label = f"Exp { exp_idx + 1 } " ,
239
235
)
240
236
241
- ax1 .plot (
237
+ plt .plot (
242
238
results_df ["iteration" ],
243
239
results_df ["total_solvent_mL" ],
244
240
"s-" ,
245
241
color = "blue" ,
246
242
linewidth = 2 ,
247
243
label = "Total" ,
248
244
)
249
- ax1 .axhline (y = 60 , color = "red" , linestyle = "--" , label = "Required" )
250
- ax1 . set_title ("Solvent: Individual + Total" )
251
- ax1 .legend ()
245
+ plt .axhline (y = 60 , color = "red" , linestyle = "--" , label = "Required" )
246
+ plt . title ("Solvent: Individual + Total" )
247
+ plt .legend ()
252
248
249
+ plt .sca (axs [1 ])
253
250
for exp_idx in range (BATCH_SIZE ):
254
251
individual_values = [
255
252
batch [exp_idx ] for batch in results_df ["individual_catalyst_mol%" ]
256
253
]
257
- ax2 .plot (
254
+ plt .plot (
258
255
results_df ["iteration" ],
259
256
individual_values ,
260
257
"o-" ,
261
258
alpha = 0.6 ,
262
259
label = f"Exp { exp_idx + 1 } " ,
263
260
)
264
261
265
- ax2 .plot (
262
+ plt .plot (
266
263
results_df ["iteration" ],
267
264
results_df ["total_catalyst_mol%" ],
268
265
"s-" ,
269
266
color = "orange" ,
270
267
linewidth = 2 ,
271
268
label = "Total" ,
272
269
)
273
- ax2 .axhline (y = 30 , color = "red" , linestyle = "--" , label = "Limit" )
274
- ax2 . set_title ("Catalyst: Individual + Total" )
275
- ax2 .legend ()
270
+ plt .axhline (y = 30 , color = "red" , linestyle = "--" , label = "Limit" )
271
+ plt . title ("Catalyst: Individual + Total" )
272
+ plt .legend ()
276
273
277
274
plt .tight_layout ()
278
275
if not SMOKE_TEST :
279
- plt .savefig ("interpoint_constraints .svg" )
276
+ plt .savefig ("interpoint .svg" )
0 commit comments