From f862c58292ec6b3eac14fc704288d5167867aa5a Mon Sep 17 00:00:00 2001 From: Spencer Bryngelson Date: Thu, 26 Nov 2026 17:13:18 -0500 Subject: [PATCH 1/2] precheck: drop fixed sleeps in the monitor tests, load example cases in parallel monitor_slurm_job.sh had two hardcoded 2 s sleeps that ignored MFC_MONITOR_POLL_SECONDS, which the tests set to 0; they cost ~45 s of the toolchain unit tests. Example validation now runs the case files (one interpreter each) side by side. --- .github/scripts/monitor_slurm_job.sh | 4 ++-- toolchain/mfc/validate.py | 16 +++++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/.github/scripts/monitor_slurm_job.sh b/.github/scripts/monitor_slurm_job.sh index a56498d0d5..e0e7397b54 100755 --- a/.github/scripts/monitor_slurm_job.sh +++ b/.github/scripts/monitor_slurm_job.sh @@ -158,7 +158,7 @@ while [ ! -f "$output_file" ]; do RUNNING|COMPLETING) unknown_count=0 # Job is running but output file not yet visible (NFS delay) - sleep 2 + sleep "$MFC_MONITOR_POLL_SECONDS" ;; UNKNOWN) unknown_count=$((unknown_count + 1)) @@ -223,7 +223,7 @@ done # Give tail a moment to flush the final lines, then stop streaming. Whether it # was still alive decides how much needs reprinting below: if it streamed the # whole job, printing the file again just doubles every log. -sleep 2 +sleep "$MFC_MONITOR_POLL_SECONDS" streamed_ok=0 if kill -0 "${tail_pid}" 2>/dev/null; then streamed_ok=1 diff --git a/toolchain/mfc/validate.py b/toolchain/mfc/validate.py index ecef394d3f..b27b9d7df3 100644 --- a/toolchain/mfc/validate.py +++ b/toolchain/mfc/validate.py @@ -4,6 +4,7 @@ import os import sys +from concurrent.futures import ThreadPoolExecutor from . import state from .case_validator import CaseConstraintError, CaseValidator @@ -33,13 +34,18 @@ def _validate_batch_default_build(inputs): failed = [] refused = [] with_issues = [] - for c in inputs: - if not os.path.isfile(c): - failed.append(c) - continue + + def _load(c): try: - case = run_input.load(c, do_print=False) + return run_input.load(c, do_print=False) if os.path.isfile(c) else None except MFCException: + return None + + # Each load runs the case file in its own interpreter (~0.5 s, most of the time), so run them side by side. + with ThreadPoolExecutor(max_workers=min(16, os.cpu_count() or 1)) as pool: + cases = list(pool.map(_load, inputs)) + for c, case in zip(inputs, cases): + if case is None: failed.append(c) continue had_issue = False From 4c8c923bbd73740f2298451b9477e299894ede94 Mon Sep 17 00:00:00 2001 From: Spencer Bryngelson Date: Thu, 26 Nov 2026 17:26:24 -0500 Subject: [PATCH 2/2] precheck: run the unit tests in parallel, skip what a commit's staged files cannot affect pytest-xdist runs the toolchain unit tests on up to 16 workers (~58 s -> ~20 s), in CI's lint as well. The doc reference check now runs in the background with the others instead of delaying them. The pre-commit hook passes --staged: a commit that stages nothing under examples/ or toolchain/ skips example validation, and a docs-only commit skips the unit tests (they read src/ and examples/ too). A plain ./mfc.sh precheck and CI run everything. --- .githooks/pre-commit | 2 +- toolchain/bootstrap/lint.sh | 2 +- toolchain/bootstrap/precheck.sh | 39 ++++++++++++++++++++++++++------- toolchain/pyproject.toml | 1 + 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/.githooks/pre-commit b/.githooks/pre-commit index b13ccf0cfb..7ffe331c87 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -19,7 +19,7 @@ echo "" echo "mfc: Running precheck before commit (-j $JOBS)..." echo "" -if ./mfc.sh precheck -j "$JOBS"; then +if ./mfc.sh precheck --staged -j "$JOBS"; then echo "" exit 0 else diff --git a/toolchain/bootstrap/lint.sh b/toolchain/bootstrap/lint.sh index 024f9dcd12..f78c617d57 100644 --- a/toolchain/bootstrap/lint.sh +++ b/toolchain/bootstrap/lint.sh @@ -33,7 +33,7 @@ if [ "$RUN_TESTS" = true ]; then log "(venv) Running$MAGENTA unit tests$COLOR_RESET on$MAGENTA MFC$COLOR_RESET's $MAGENTA""toolchain$COLOR_RESET." cd toolchain - python3 -m pytest . -v + python3 -m pytest . -v -n auto --maxprocesses=16 cd - > /dev/null fi diff --git a/toolchain/bootstrap/precheck.sh b/toolchain/bootstrap/precheck.sh index 8e4d3cdf7c..34c1e87712 100755 --- a/toolchain/bootstrap/precheck.sh +++ b/toolchain/bootstrap/precheck.sh @@ -11,12 +11,14 @@ show_help() { echo "Options:" echo " -h, --help Display this help message and exit." echo " -j, --jobs JOBS Runs JOBS number of parallel jobs for formatting." + echo " --staged Skip the checks no staged file can affect (the pre-commit hook)." echo "" exit 0 } JOBS=1 +STAGED=0 while [[ $# -gt 0 ]]; do case "$1" in @@ -32,6 +34,9 @@ while [[ $# -gt 0 ]]; do JOBS="$2" shift ;; + --staged) + STAGED=1 + ;; -h | --help) show_help ;; @@ -56,6 +61,16 @@ export MFC_SKIP_SUITE_LINT=1 NCHECK=7 +# --staged: the unit tests read src/ and examples/ as well, so only a docs-only commit skips them; +# the example decks depend only on examples/ and toolchain/. CI runs everything. +LINT_ARGS=() +CHECK_EXAMPLES=1 +if [ "$STAGED" = 1 ]; then + staged=$(git diff --cached --name-only) + if [ -n "$staged" ] && ! grep -qv '^docs/' <<< "$staged"; then LINT_ARGS=(--no-test); fi + grep -qE '^(examples|toolchain)/' <<< "$staged" || CHECK_EXAMPLES=0 +fi + log "Running$MAGENTA precheck$COLOR_RESET (same checks as CI lint-gate)..." echo "" @@ -88,7 +103,7 @@ PID_SPELL=$! # Lint (ruff + unit tests) — safe after format since files are stable ( - if ./mfc.sh lint > /dev/null 2>&1; then + if ./mfc.sh lint "${LINT_ARGS[@]}" > /dev/null 2>&1; then echo "0" > "$TMPDIR_PC/lint_exit" else echo "1" > "$TMPDIR_PC/lint_exit" @@ -107,10 +122,14 @@ PID_LINT=$! PID_SOURCE=$! # Doc reference check -DOC_FAILED=0 -if ! python3 toolchain/mfc/lint_docs.py > /dev/null 2>&1; then - DOC_FAILED=1 -fi +( + if python3 toolchain/mfc/lint_docs.py > /dev/null 2>&1; then + echo "0" > "$TMPDIR_PC/doc_exit" + else + echo "1" > "$TMPDIR_PC/doc_exit" + fi +) & +PID_DOC=$! # Parameter documentation check ( @@ -127,6 +146,7 @@ PID_PARAM_DOCS=$! # (~90%) the ~6 min serial loop over 155 cases; batching drops it to well under a minute. # Every example directory holds its deck as case.py, so the glob below sees it (scaling/ is a benchmark harness). ( + [ "$CHECK_EXAMPLES" = 1 ] || { echo "skip" > "$TMPDIR_PC/examples_exit"; exit 0; } missing=$(git ls-files 'examples/*/*' | cut -d/ -f2 | sort -u | while read -r d; do [ -f "examples/$d/case.py" ] || [ "$d" = scaling ] || echo "examples/$d" done) @@ -165,7 +185,7 @@ wait $PID_LINT log "[$CYAN 3/$NCHECK$COLOR_RESET] Running$MAGENTA toolchain lint$COLOR_RESET..." LINT_RC=$(cat "$TMPDIR_PC/lint_exit" 2>/dev/null || echo "1") if [ "$LINT_RC" = "0" ]; then - ok "Toolchain lint passed." + ok "Toolchain lint passed${LINT_ARGS:+ (unit tests skipped: only docs/ staged)}." else error "Toolchain lint failed. Run$MAGENTA ./mfc.sh lint$COLOR_RESET for details." FAILED=1 @@ -181,8 +201,9 @@ else FAILED=1 fi +wait $PID_DOC log "[$CYAN 5/$NCHECK$COLOR_RESET] Checking$MAGENTA doc references$COLOR_RESET..." -if [ $DOC_FAILED -eq 0 ]; then +if [ "$(cat "$TMPDIR_PC/doc_exit" 2>/dev/null || echo 1)" = "0" ]; then ok "Doc references are valid." else error "Doc reference check failed. Run$MAGENTA python3 toolchain/mfc/lint_docs.py$COLOR_RESET for details." @@ -202,7 +223,9 @@ fi wait $PID_EXAMPLES log "[$CYAN 7/$NCHECK$COLOR_RESET] Validating$MAGENTA example cases$COLOR_RESET..." EXAMPLES_FAILED=$(cat "$TMPDIR_PC/examples_exit" 2>/dev/null || echo "1") -if [ "$EXAMPLES_FAILED" = "0" ]; then +if [ "$EXAMPLES_FAILED" = "skip" ]; then + ok "Example cases skipped: nothing staged under examples/ or toolchain/." +elif [ "$EXAMPLES_FAILED" = "0" ]; then ok "All example cases are valid." else [ -f "$TMPDIR_PC/examples_missing" ] && error "$(cat "$TMPDIR_PC/examples_missing") (name the deck case.py)." diff --git a/toolchain/pyproject.toml b/toolchain/pyproject.toml index e013f474ad..fffe565d95 100644 --- a/toolchain/pyproject.toml +++ b/toolchain/pyproject.toml @@ -28,6 +28,7 @@ dependencies = [ "ffmt==0.4.5", "ansi2txt", "pytest", + "pytest-xdist", # Profiling "numpy",