Complete P3 F3 evaluation and Windows execution

Implement the frozen F3 protocol, nested LOWO, posterior label banks,
ablations, diagnostics, checkpoint validation and full-volume inference.
Record the negative G-C result: improvement at 1/4 wells, coverage80 52.38%
and coverage90 60.91%, with unchanged thresholds and historical P2 results.

Add native Windows logging, the RTX 3060 environment lock, detached runs,
and an audited dashboard-lock recovery that preserves frozen scientific code.
Update report.html, the plan and agent guidance with completed P3 status.
Archive thesis sources under code_thesis with identical Git blobs and record
the original-output audit without committing large data or model artifacts.

Validation: 129 tests passed, 13 skipped; CUDA end-to-end smoke passed;
completion audit verified 1,320 checkpoint/prediction pairs, 28 registration
bundles and all 649 interior volume inlines. Scripts 04 and 09 were not rerun.

Co-authored-by: Codex <codex@openai.com>
This commit is contained in:
2026-10-28 07:01:08 +07:00
parent a22f9d951f
commit 9976abc96b
50 changed files with 2738 additions and 219 deletions

75
scripts/19_run_f3.py Normal file
View File

@@ -0,0 +1,75 @@
"""P3 on Windows/Linux: prepare -> benchmark -> lock -> register -> train -> diagnostics -> summarize.
Full run: python scripts/19_run_f3.py all --device cuda:0 --workers 4
CPU and reduced smoke results are never presented as the registered P3 experiment.
"""
from __future__ import annotations
import argparse
import os
import traceback
os.environ.setdefault('OMP_NUM_THREADS', '2')
os.environ.setdefault('MKL_NUM_THREADS', '2')
os.environ.setdefault('OPENBLAS_NUM_THREADS', '2')
os.environ.setdefault('NUMBA_NUM_THREADS', '2')
os.environ.setdefault('PYTHONHASHSEED', '0')
os.environ.setdefault('PYTHONUTF8', '1')
os.environ.setdefault('CUBLAS_WORKSPACE_CONFIG', ':4096:8')
def main() -> None:
from ml_porosity.f3.progress import update
from ml_porosity.f3.protocol import freeze, load_protocol
from ml_porosity.f3.runner import benchmark, benchmark_registration, prepare, run
ap = argparse.ArgumentParser(description=__doc__)
ap.add_argument('stage', choices=['status', 'prepare', 'benchmark', 'benchmark-registration', 'lock', 'register', 'train', 'diagnostics', 'summarize', 'all'])
ap.add_argument('--device', default='cuda:0')
ap.add_argument('--workers', type=int, default=4)
ap.add_argument('--smoke', action='store_true')
ap.add_argument('--sections', action='store_true', help='Explicitly reduce volume scope; never selected automatically')
ap.add_argument('--skip-volume', action='store_true', help='Stop after LOWO summary; leaves the volume task incomplete')
ap.add_argument('--benchmark-steps', type=int, default=100)
ap.add_argument('--benchmark-workers', type=int, nargs='+', default=[1, 2, 3])
args = ap.parse_args()
if args.workers < 1:
ap.error('--workers must be positive')
p = load_protocol()
if os.name == 'nt':
import ctypes
# Prevent automatic system sleep only while this process is alive.
ctypes.windll.kernel32.SetThreadExecutionState(0x80000001)
try:
if args.stage == 'status':
from ml_porosity.paths import outputs_dir
progress = outputs_dir()/'p3/progress.json'
print(progress.read_text(encoding='utf-8') if progress.exists() else 'P3 has not started.')
elif args.stage == 'prepare':
prepare()
elif args.stage == 'benchmark':
print(benchmark(p, args.device, args.benchmark_steps, args.benchmark_workers))
elif args.stage == 'benchmark-registration':
print(benchmark_registration(p, args.device))
elif args.stage == 'lock':
print(freeze())
update(tasks={'p3-protocol': 'done'}, status='Protocol F3 đã khoá', message='Mã băm protocol, code và dữ liệu được kiểm tra trước mọi giai đoạn P3.')
else:
stages = ['register', 'train', 'diagnostics', 'summarize'] if args.stage == 'all' else [args.stage]
for stage in stages:
run(stage, p, args.device, args.workers, args.smoke)
if args.stage == 'all' and not args.smoke and not args.skip_volume:
from ml_porosity.f3.volume import fit_deployment, predict_volume
fit_deployment(p, args.device, args.workers)
predict_volume(p, args.device, args.sections)
except Exception as exc:
update(status='Có lỗi cần xử lý', error=str(exc), message=f'Giai đoạn {args.stage} chưa hoàn tất; các job đã ghi đủ vẫn có thể resume.')
traceback.print_exc()
raise SystemExit(1)
finally:
if os.name == 'nt':
ctypes.windll.kernel32.SetThreadExecutionState(0x80000000)
if __name__ == '__main__':
main()