Skip to content

Commit fb1ade5

Browse files
author
Ananya Sutradhar
committed
added script to run ILP on different workloads(ads data)
1 parent fa04e70 commit fb1ade5

File tree

2 files changed

+52
-11
lines changed

2 files changed

+52
-11
lines changed

scripts/ml_ilp/ilp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def main():
138138
print("Done reading ground truth file")
139139

140140
# Read the filter match file
141-
filter_matches = np.loadtxt(args.filter_matches, dtype=np.int32)
141+
filter_matches = np.loadtxt(args.filter_matches, dtype=np.float32)
142142
print(f"Filter matches shape: {filter_matches.shape}")
143143
print("Done reading filter match file")
144144

scripts/ml_ilp/ilp_pipeline.py

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -255,46 +255,73 @@ def main():
255255
# Step 4: Run ILP weight calculation
256256
print("STEP 4: Running ILP weight calculation")
257257

258+
# Define output file for ILP weights
259+
ilp_weights_path = os.path.join(args.output_dir, f"ilp_weights_{args.base_size}_{args.query_size}.txt")
260+
258261
if not ensure_executable_exists(ilp_script, "ilp.py"):
259262
print("⚠ ILP script not found, skipping weight calculation")
260263
print("You can run ILP manually later using the generated ground truth files")
264+
ilp_result = None
261265
else:
262266
ilp_cmd = [
263267
sys.executable,
264268
ilp_script,
265269
unfiltered_gt_path,
266270
filtered_gt_path,
267-
# Note: match scores file not available, ILP script will work without it
271+
unfiltered_match_scores_path,
268272
"--method", "pulp", # Start with simple pulp method
269273
"--eps", "0.001"
270274
]
271275

272276
if args.norm_factors:
273277
ilp_cmd.extend(["--norm_factors", args.norm_factors])
274278

275-
result = run_command(ilp_cmd, "ILP weight calculation")
276-
if result is None:
279+
ilp_result = run_command(ilp_cmd, "ILP weight calculation")
280+
if ilp_result is None:
277281
print("ILP weight calculation failed. Trying with different parameters...")
278282

279283
# Try with PuLP method if ratio fails
280284
ilp_cmd_pulp = ilp_cmd.copy()
281285
try:
282286
ilp_cmd_pulp[ilp_cmd_pulp.index("ratio")] = "pulp"
283-
result = run_command(ilp_cmd_pulp, "ILP weight calculation (PuLP method)")
287+
ilp_result = run_command(ilp_cmd_pulp, "ILP weight calculation (PuLP method)")
284288
except ValueError:
285289
# "ratio" not in list, already using pulp
286290
print("Already using PuLP method, trying with different epsilon...")
287291
ilp_cmd_eps = ilp_cmd.copy()
288292
ilp_cmd_eps[ilp_cmd_eps.index("0.001")] = "0.01"
289-
result = run_command(ilp_cmd_eps, "ILP weight calculation (larger epsilon)")
293+
ilp_result = run_command(ilp_cmd_eps, "ILP weight calculation (larger epsilon)")
290294

291-
if result is None:
295+
if ilp_result is None:
292296
print("⚠ All ILP methods failed. Check your data and try manually.")
293297
print("Ground truth files are ready for manual ILP execution:")
294298
print(f" Unfiltered GT: {unfiltered_gt_path}")
295299
print(f" Filtered GT: {filtered_gt_path}")
296300
else:
297301
print("✓ ILP weight calculation completed successfully!")
302+
# Save the ILP output to a file since the script doesn't support --output
303+
print("⚠ Saving ILP output manually...")
304+
with open(ilp_weights_path, 'w') as f:
305+
f.write("ILP Weight Calculation Results\n")
306+
f.write("="*40 + "\n\n")
307+
f.write("STDOUT:\n")
308+
f.write(ilp_result.stdout)
309+
f.write("\n\nSTDERR:\n")
310+
f.write(ilp_result.stderr)
311+
f.write(f"\n\nGenerated at: {__import__('datetime').datetime.now()}\n")
312+
print(f"✓ ILP output saved to: {ilp_weights_path}")
313+
314+
# Extract w_m weight and save to separate file
315+
import re
316+
w_m_match = re.search(r'w_m = ([\d.]+)', ilp_result.stdout)
317+
if w_m_match:
318+
w_m_value = w_m_match.group(1)
319+
w_m_file = os.path.join(args.output_dir, "w_m_weight.txt")
320+
with open(w_m_file, 'w') as f:
321+
f.write(w_m_value)
322+
print(f"✓ w_m weight ({w_m_value}) saved to: {w_m_file}")
323+
else:
324+
print("⚠ Could not extract w_m value from ILP output")
298325

299326
# Save results summary
300327
summary_path = os.path.join(args.output_dir, "pipeline_summary.txt")
@@ -316,10 +343,15 @@ def main():
316343
f.write(f" Filtered GT: {filtered_gt_path} ({'exists' if os.path.exists(filtered_gt_path) else 'missing'})\n")
317344
if args.norm_factors:
318345
f.write(f" Normalization factors: {args.norm_factors} ({'exists' if os.path.exists(args.norm_factors) else 'missing'})\n")
346+
if 'ilp_weights_path' in locals():
347+
f.write(f" ILP weights: {ilp_weights_path} ({'exists' if os.path.exists(ilp_weights_path) else 'missing'})\n")
348+
w_m_file = os.path.join(args.output_dir, "w_m_weight.txt")
349+
if os.path.exists(w_m_file):
350+
f.write(f" w_m weight: {w_m_file} (exists)\n")
319351
f.write(f"\n")
320-
if 'result' in locals() and result:
352+
if 'ilp_result' in locals() and ilp_result:
321353
f.write("ILP Results:\n")
322-
f.write(result.stdout)
354+
f.write(ilp_result.stdout)
323355
f.write(f"\nPipeline completed at: {__import__('datetime').datetime.now()}\n")
324356

325357
print(f"\n{'='*60}")
@@ -335,10 +367,19 @@ def main():
335367
print(f" Filtered GT: {'✓' if os.path.exists(filtered_gt_path) else '✗'}")
336368
if args.norm_factors:
337369
print(f" Norm factors: {'✓' if os.path.exists(args.norm_factors) else '✗'}")
370+
if 'ilp_weights_path' in locals():
371+
print(f" ILP weights: {'✓' if os.path.exists(ilp_weights_path) else '✗'}")
372+
w_m_file = os.path.join(args.output_dir, "w_m_weight.txt")
373+
if os.path.exists(w_m_file):
374+
print(f" w_m weight: ✓")
338375

339376
if os.path.exists(unfiltered_gt_path) and os.path.exists(filtered_gt_path):
340-
print(f"\n✓ Ready for ILP weight calculation!")
341-
print(f"Check the summary file for ILP weights (w_d, w_m)")
377+
if 'ilp_weights_path' in locals() and os.path.exists(ilp_weights_path):
378+
print(f"\n✓ ILP pipeline completed successfully!")
379+
print(f"✓ ILP weights are available in: {ilp_weights_path}")
380+
else:
381+
print(f"\n✓ Ground truth files ready for ILP weight calculation!")
382+
print(f"Check the summary file for results")
342383
else:
343384
print(f"\n⚠ Some ground truth files are missing. Check the log above for errors.")
344385

0 commit comments

Comments
 (0)