add submitter sanity_check_submission.py
Browse files- sanity_check_submission.py +78 -0
sanity_check_submission.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
"""Local self-check for a benchmark submission STEP.
|
| 3 |
+
|
| 4 |
+
Runs the same CAD-validity gate that the grading pipeline uses: BREP
|
| 5 |
+
well-formedness + watertightness + meshable-as-closed-manifold. Exits
|
| 6 |
+
non-zero on any failure with the specific reason; exits 0 silently on
|
| 7 |
+
a clean submission.
|
| 8 |
+
|
| 9 |
+
Usage::
|
| 10 |
+
|
| 11 |
+
python _to_move_to_dataset_repo/sanity_check_submission.py path/to/output.step
|
| 12 |
+
|
| 13 |
+
The gate is the deciding factor for whether ``cad_score = 0``. See
|
| 14 |
+
``docs/benchmark/submission.md`` for the full contract.
|
| 15 |
+
"""
|
| 16 |
+
from __future__ import annotations
|
| 17 |
+
|
| 18 |
+
import argparse
|
| 19 |
+
import sys
|
| 20 |
+
from pathlib import Path
|
| 21 |
+
|
| 22 |
+
from cadgenbench.common.validity import analyze_step
|
| 23 |
+
from cadgenbench.common.mesh import deflection_for_bbox
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def main() -> int:
|
| 27 |
+
parser = argparse.ArgumentParser(
|
| 28 |
+
description=(
|
| 29 |
+
"Run the CAD-validity gate on one candidate STEP. Same gate "
|
| 30 |
+
"the grading pipeline uses."
|
| 31 |
+
),
|
| 32 |
+
)
|
| 33 |
+
parser.add_argument("step", type=Path, help="Path to the candidate STEP file.")
|
| 34 |
+
parser.add_argument(
|
| 35 |
+
"--quiet", action="store_true",
|
| 36 |
+
help="On pass, exit silently. On fail, still print the reason.",
|
| 37 |
+
)
|
| 38 |
+
args = parser.parse_args()
|
| 39 |
+
|
| 40 |
+
if not args.step.exists():
|
| 41 |
+
print(f"ERROR: file not found: {args.step}", file=sys.stderr)
|
| 42 |
+
return 2
|
| 43 |
+
|
| 44 |
+
try:
|
| 45 |
+
result = analyze_step(args.step)
|
| 46 |
+
except Exception as exc:
|
| 47 |
+
print(f"FAIL STEP load failed: {exc}", file=sys.stderr)
|
| 48 |
+
return 1
|
| 49 |
+
|
| 50 |
+
val = result.validation
|
| 51 |
+
m = result.measurements
|
| 52 |
+
|
| 53 |
+
if val.is_valid:
|
| 54 |
+
if not args.quiet:
|
| 55 |
+
defl = deflection_for_bbox(m.bounding_box.diagonal)
|
| 56 |
+
print(
|
| 57 |
+
f"PASS {args.step.name}: is_valid=True watertight=True\n"
|
| 58 |
+
f" solids={m.solid_count} shells={m.shell_count} "
|
| 59 |
+
f"faces={m.face_count}\n"
|
| 60 |
+
f" volume={m.volume:.2f} bbox="
|
| 61 |
+
f"{m.bounding_box.size_x:.2f}×{m.bounding_box.size_y:.2f}×"
|
| 62 |
+
f"{m.bounding_box.size_z:.2f} defl_used={defl:.4f} mm",
|
| 63 |
+
)
|
| 64 |
+
return 0
|
| 65 |
+
|
| 66 |
+
print(
|
| 67 |
+
f"FAIL {args.step.name}: is_valid=False watertight={val.is_watertight}",
|
| 68 |
+
file=sys.stderr,
|
| 69 |
+
)
|
| 70 |
+
for err in val.topology_errors[:10]:
|
| 71 |
+
print(f" - {err}", file=sys.stderr)
|
| 72 |
+
if len(val.topology_errors) > 10:
|
| 73 |
+
print(f" ... and {len(val.topology_errors) - 10} more", file=sys.stderr)
|
| 74 |
+
return 1
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
if __name__ == "__main__":
|
| 78 |
+
raise SystemExit(main())
|