File size: 2,194 Bytes
0210a65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""
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()