Download task_033/tests/validate_outputs.py from Lego-X/UXInteract: direct link, hf CLI and curl.
- Browser
- Download file 2.52 kB
-
https://huggingface.co/datasets/Lego-X/UXInteract/resolve/main/task_033/tests/validate_outputs.py
- Command line
-
hf download hf://datasets/Lego-X/UXInteract/task_033/tests/validate_outputs.py
-
curl -L -o validate_outputs.py https://huggingface.co/datasets/Lego-X/UXInteract/resolve/main/task_033/tests/validate_outputs.py
2.52 kB
| import pathlib | |
| import struct | |
| import subprocess | |
| import sys | |
| root = pathlib.Path.cwd() | |
| def _py_sources(): | |
| _skip = {"tests", "logs", "output", "__pycache__", "node_modules", ".git"} | |
| return [ | |
| p | |
| for p in root.rglob("*.py") | |
| if p.is_file() | |
| and not (set(p.relative_to(root).parts) & _skip) | |
| and p.name != "validate_outputs.py" | |
| ] | |
| def run_candidate() -> None: | |
| scripts = [root / 'solve.py'] | |
| assert scripts, "missing candidate python source (e.g. solve.py)" | |
| failures = [] | |
| for script in scripts[:2]: | |
| proc = subprocess.run( | |
| [sys.executable, str(script)], | |
| cwd=root, | |
| capture_output=True, | |
| text=True, | |
| timeout=60, | |
| ) | |
| if proc.returncode == 0: | |
| return | |
| failures.append((script.name, proc.returncode, proc.stdout, proc.stderr)) | |
| raise AssertionError( | |
| "candidate script(s) failed to execute:\n" | |
| + "\n".join( | |
| f"{name}: rc={rc}\nstdout={out}\nstderr={err}" for name, rc, out, err in failures | |
| ) | |
| ) | |
| def validate_outputs() -> None: | |
| report_path = root / "report.html" | |
| sample_path = root / "mnist_samples.png" | |
| for p in (report_path, sample_path): | |
| assert p.exists() and p.stat().st_size > 0, f"missing {p.name}" | |
| img_path = root / "train-images-idx3-ubyte" | |
| label_path = root / "train-labels-idx1-ubyte" | |
| magic, count, rows, cols = struct.unpack(">IIII", img_path.read_bytes()[:16]) | |
| lmagic, lcount = struct.unpack(">II", label_path.read_bytes()[:8]) | |
| assert (magic, count, rows, cols) == (2051, 10, 8, 8), "unexpected tiny MNIST header" | |
| assert (lmagic, lcount) == (2049, 10), "unexpected tiny label header" | |
| assert count == lcount == 10, "image count and label count should match" | |
| report = report_path.read_text(encoding="utf-8", errors="ignore").lower() | |
| assert "mnist" in report, "report missing mnist" | |
| assert "mlp" in report or "network" in report, "report missing mlp/network" | |
| assert "80" in report and "20" in report, "report should mention 80/20 split" | |
| assert any(word in report for word in ('transform', 'normalize', 'flip', '变换', '归一化')), "report missing transform discussion" | |
| assert any(word in report for word in ('layer', 'hidden', 'network', '隐层', '网络')), "report missing network structure discussion" | |
| run_candidate() | |
| validate_outputs() | |
| print("validate_outputs OK: task_049 checks the packaged IDX fixture and MNIST task outputs") | |