Download scripts/phase0_check.py from codewithyug/certified-safe-neural-control: direct link, hf CLI and curl.
- Browser
- Download file 2.19 kB
-
https://huggingface.co/codewithyug/certified-safe-neural-control/resolve/main/scripts/phase0_check.py
- Command line
-
hf download hf://codewithyug/certified-safe-neural-control/scripts/phase0_check.py
-
curl -L -o phase0_check.py https://huggingface.co/codewithyug/certified-safe-neural-control/resolve/main/scripts/phase0_check.py
2.19 kB
| """ | |
| Phase 0 Toolchain and Hardware Feasibility Smoke Test | |
| Validates PyTorch CUDA availability, GPU VRAM allocation, and basic QP solver integration. | |
| """ | |
| import sys | |
| import time | |
| import numpy as np | |
| def run_smoke_test(): | |
| print("=" * 60) | |
| print("PHASE 0: TOOLCHAIN & HARDWARE FEASIBILITY SMOKE TEST") | |
| print("=" * 60) | |
| # 1. Python version check | |
| py_ver = sys.version.split()[0] | |
| print(f"[+] Python Version: {py_ver}") | |
| # 2. PyTorch & CUDA Check | |
| try: | |
| import torch | |
| print(f"[+] PyTorch Version: {torch.__version__}") | |
| cuda_avail = torch.cuda.is_available() | |
| print(f"[+] CUDA Available: {cuda_avail}") | |
| if cuda_avail: | |
| device_name = torch.cuda.get_device_name(0) | |
| total_mem = torch.cuda.get_device_properties(0).total_memory / (1024**3) | |
| print(f"[+] Active GPU: {device_name} ({total_mem:.2f} GB VRAM)") | |
| # Allocation test | |
| x = torch.randn((1000, 1000), device="cuda") | |
| _ = torch.matmul(x, x) | |
| torch.cuda.synchronize() | |
| allocated = torch.cuda.memory_allocated(0) / (1024**2) | |
| print(f"[+] GPU Tensor Allocation Test Passed (~{allocated:.2f} MB allocated)") | |
| else: | |
| print("[!] WARNING: CUDA is not available. Using CPU fallback.") | |
| except ImportError: | |
| print("[!] PyTorch is not installed. Run 'pip install -r requirements.txt'") | |
| # 3. QP Solver Check | |
| try: | |
| import cvxpy as cp | |
| print(f"[+] CVXPY Version: {cp.__version__}") | |
| # Test basic QP formulation | |
| u = cp.Variable(2) | |
| u_nom = np.array([1.0, 0.5]) | |
| prob = cp.Problem(cp.Minimize(cp.sum_squares(u - u_nom)), [u[0] + u[1] >= 1.0]) | |
| t0 = time.time() | |
| prob.solve(solver=cp.OSQP) | |
| dt = (time.time() - t0) * 1000 | |
| print(f"[+] OSQP Solver Test Passed (solve time: {dt:.2f} ms, status: {prob.status})") | |
| except ImportError: | |
| print("[!] CVXPY or OSQP is not installed. Run 'pip install -r requirements.txt'") | |
| print("=" * 60) | |
| print("Phase 0 Environment Verification Complete.") | |
| print("=" * 60) | |
| if __name__ == "__main__": | |
| run_smoke_test() | |