mattbitzesty commited on
Commit
376e3b9
Β·
verified Β·
1 Parent(s): 700d58b

Upload src/pino/train.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. src/pino/train.py +54 -36
src/pino/train.py CHANGED
@@ -276,6 +276,7 @@ def main():
276
  parser.add_argument("--structural-source", choices=["morgan", "openpom_256", "pom_alltags"], default="morgan", help="Structural embedding block + objective target: 'morgan' (138-dim Morgan, input 151, 138-dim pyramid) | 'openpom_256' (genuine 256-dim OpenPOM, input 269, 138-dim pyramid) | 'pom_alltags' (genuine 256-dim OpenPOM, input 269, 575-dim molequles all-tags objective)")
277
  parser.add_argument("--smoke-test", action="store_true", help="Run lightweight CPU smoke test")
278
  parser.add_argument("--use-gamma", action="store_true", help="Add the UNIFAC blend-interaction (gamma) 3rd physics channel; requires a gamma-augmented dataset (physics_gamma field)")
 
279
  args = parser.parse_args()
280
 
281
  logging.basicConfig(
@@ -329,44 +330,61 @@ def main():
329
  control_records = [r for r in all_records if r.get("is_control", False)]
330
  print(f"πŸ“Š Extracted {len(control_records)} pure single-molecule anchors.")
331
 
332
- split = create_molecule_disjoint_split_from_records(
333
- all_records,
334
- train_ratio=args.train_ratio,
335
- seed=args.seed,
336
- )
337
- train_records = split["train"]
338
- val_records = split["validation"]
339
-
340
- train_cas = set(split["train_compounds"])
341
- val_cas = set(split["validation_compounds"])
342
- overlap = train_cas & val_cas
343
- print(f"πŸ”’ Molecule isolation check: {len(overlap)} active CAS shared between splits.")
344
- print(f"🚫 Excluded mixed-boundary records: {len(split['excluded_indices'])}")
345
- assert len(overlap) == 0, f"Molecule leakage detected: {sorted(overlap)}"
346
- # Persist the zero-intersection assertion for the paper's reproducibility ledger.
347
- try:
348
- leakage_report = {
349
- "split_strategy": "molecule_disjoint",
350
- "seed": args.seed,
351
- "train_ratio": args.train_ratio,
352
- "n_train_records": len(train_records),
353
- "n_validation_records": len(val_records),
354
- "n_excluded_records": len(split["excluded_indices"]),
355
- "n_train_molecules": len(train_cas),
356
- "n_validation_molecules": len(val_cas),
357
- "shared_molecule_count": len(overlap),
358
- "zero_intersection_assertion": "PASSED" if not overlap else "FAILED",
359
- }
360
- Path(args.output_dir).mkdir(parents=True, exist_ok=True)
361
- report_name = f"split_leakage_report_seed{args.seed}.json"
362
- with open(Path(args.output_dir) / report_name, "w") as rf:
363
- json.dump(leakage_report, rf, indent=2)
364
- print(f"πŸ“ Split leakage report: {report_name} (zero-intersection: {leakage_report['zero_intersection_assertion']})")
365
- except Exception as e: # noqa: BLE001
366
- logger.warning("Could not write split leakage report: %s", e)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
367
  if not train_records or not val_records:
368
  raise RuntimeError(
369
- "Molecule-disjoint split produced an empty train or validation set. "
370
  "Adjust --train-ratio or --seed."
371
  )
372
 
 
276
  parser.add_argument("--structural-source", choices=["morgan", "openpom_256", "pom_alltags"], default="morgan", help="Structural embedding block + objective target: 'morgan' (138-dim Morgan, input 151, 138-dim pyramid) | 'openpom_256' (genuine 256-dim OpenPOM, input 269, 138-dim pyramid) | 'pom_alltags' (genuine 256-dim OpenPOM, input 269, 575-dim molequles all-tags objective)")
277
  parser.add_argument("--smoke-test", action="store_true", help="Run lightweight CPU smoke test")
278
  parser.add_argument("--use-gamma", action="store_true", help="Add the UNIFAC blend-interaction (gamma) 3rd physics channel; requires a gamma-augmented dataset (physics_gamma field)")
279
+ parser.add_argument("--split-strategy", choices=["molecule", "formula"], default="molecule", help="molecule = strict molecule-disjoint holdout (default, used for frozen-task headline results); formula = random formula-level holdout (E1 physics-gamma substantivity experiment; discloses molecule leakage for measured-Poucher eval power)")
280
  args = parser.parse_args()
281
 
282
  logging.basicConfig(
 
330
  control_records = [r for r in all_records if r.get("is_control", False)]
331
  print(f"πŸ“Š Extracted {len(control_records)} pure single-molecule anchors.")
332
 
333
+ if getattr(args, "split_strategy", "molecule") == "formula":
334
+ # Formula-level random holdout. Used by the E1 physics-gamma substantivity
335
+ # experiment, where strict molecule-disjointness starves the measured-
336
+ # Poucher eval (n~10) because Poucher molecules are ubiquitous. Trades a
337
+ # weaker generalization claim (molecules may leak) for eval power; the
338
+ # leakage is disclosed in the run summary. The frozen-task headline
339
+ # results in the paper still use the molecule-disjoint path below.
340
+ rng = np.random.default_rng(args.seed)
341
+ n_total = len(all_records)
342
+ n_val = max(1, int(round(n_total * (1.0 - args.train_ratio))))
343
+ perm = rng.permutation(n_total)
344
+ val_idx = set(perm[:n_val].tolist())
345
+ train_records = [all_records[i] for i in range(n_total) if i not in val_idx]
346
+ val_records = [all_records[i] for i in sorted(val_idx)]
347
+ print(f"πŸ“Š Formula-level split (E1; leakage disclosed): train={len(train_records)} val={len(val_records)}")
348
+ else:
349
+ split = create_molecule_disjoint_split_from_records(
350
+ all_records,
351
+ train_ratio=args.train_ratio,
352
+ seed=args.seed,
353
+ )
354
+ train_records = split["train"]
355
+ val_records = split["validation"]
356
+
357
+ if getattr(args, "split_strategy", "molecule") == "molecule":
358
+ train_cas = set(split["train_compounds"])
359
+ val_cas = set(split["validation_compounds"])
360
+ overlap = train_cas & val_cas
361
+ print(f"πŸ”’ Molecule isolation check: {len(overlap)} active CAS shared between splits.")
362
+ print(f"🚫 Excluded mixed-boundary records: {len(split['excluded_indices'])}")
363
+ assert len(overlap) == 0, f"Molecule leakage detected: {sorted(overlap)}"
364
+ # Persist the zero-intersection assertion for the paper's reproducibility ledger.
365
+ try:
366
+ leakage_report = {
367
+ "split_strategy": "molecule_disjoint",
368
+ "seed": args.seed,
369
+ "train_ratio": args.train_ratio,
370
+ "n_train_records": len(train_records),
371
+ "n_validation_records": len(val_records),
372
+ "n_excluded_records": len(split["excluded_indices"]),
373
+ "n_train_molecules": len(train_cas),
374
+ "n_validation_molecules": len(val_cas),
375
+ "shared_molecule_count": len(overlap),
376
+ "zero_intersection_assertion": "PASSED" if not overlap else "FAILED",
377
+ }
378
+ Path(args.output_dir).mkdir(parents=True, exist_ok=True)
379
+ report_name = f"split_leakage_report_seed{args.seed}.json"
380
+ with open(Path(args.output_dir) / report_name, "w") as rf:
381
+ json.dump(leakage_report, rf, indent=2)
382
+ print(f"πŸ“ Split leakage report: {report_name} (zero-intersection: {leakage_report['zero_intersection_assertion']})")
383
+ except Exception as e: # noqa: BLE001
384
+ logger.warning("Could not write split leakage report: %s", e)
385
  if not train_records or not val_records:
386
  raise RuntimeError(
387
+ "Split produced an empty train or validation set. "
388
  "Adjust --train-ratio or --seed."
389
  )
390