Skip to content

Commit 23cf823

Browse files
committed
WIP
1 parent a56d018 commit 23cf823

File tree

2 files changed

+25
-28
lines changed

2 files changed

+25
-28
lines changed

examples/Constraints_Continuous/interpoint.py

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -180,40 +180,35 @@ def chemical_reaction_model(df: pd.DataFrame) -> pd.DataFrame:
180180

181181
results_log = []
182182

183-
for iteration in range(N_ITERATIONS):
183+
for it in range(N_ITERATIONS):
184184
recommendations = campaign.recommend(batch_size=BATCH_SIZE)
185185

186186
reaction_results = lookup(recommendations)
187187
measurements = pd.concat([recommendations, reaction_results], axis=1)
188-
189188
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)
196193

197194
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)"
199196
)
200197
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%)"
202199
)
203200

204201
results_log.append(
205202
{
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,
209206
"individual_solvent_mL": recommendations["Solvent_Volume"].tolist(),
210207
"individual_catalyst_mol%": recommendations["Catalyst_Loading"].tolist(),
211208
}
212209
)
213210

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%")
217212

218213
# ## Visualization
219214

@@ -224,56 +219,58 @@ def chemical_reaction_model(df: pd.DataFrame) -> pd.DataFrame:
224219

225220
results_df = pd.DataFrame(results_log)
226221

227-
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 4))
222+
fig, axs = plt.subplots(1, 2, figsize=(10, 4))
228223

224+
plt.sca(axs[0])
229225
for exp_idx in range(BATCH_SIZE):
230226
individual_values = [
231227
batch[exp_idx] for batch in results_df["individual_solvent_mL"]
232228
]
233-
ax1.plot(
229+
plt.plot(
234230
results_df["iteration"],
235231
individual_values,
236232
"o-",
237233
alpha=0.6,
238234
label=f"Exp {exp_idx + 1}",
239235
)
240236

241-
ax1.plot(
237+
plt.plot(
242238
results_df["iteration"],
243239
results_df["total_solvent_mL"],
244240
"s-",
245241
color="blue",
246242
linewidth=2,
247243
label="Total",
248244
)
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()
252248

249+
plt.sca(axs[1])
253250
for exp_idx in range(BATCH_SIZE):
254251
individual_values = [
255252
batch[exp_idx] for batch in results_df["individual_catalyst_mol%"]
256253
]
257-
ax2.plot(
254+
plt.plot(
258255
results_df["iteration"],
259256
individual_values,
260257
"o-",
261258
alpha=0.6,
262259
label=f"Exp {exp_idx + 1}",
263260
)
264261

265-
ax2.plot(
262+
plt.plot(
266263
results_df["iteration"],
267264
results_df["total_catalyst_mol%"],
268265
"s-",
269266
color="orange",
270267
linewidth=2,
271268
label="Total",
272269
)
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()
276273

277274
plt.tight_layout()
278275
if not SMOKE_TEST:
279-
plt.savefig("interpoint_constraints.svg")
276+
plt.savefig("interpoint.svg")
File renamed without changes.

0 commit comments

Comments
 (0)