File size: 2,981 Bytes
5e4510c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python3
"""
Quick test to verify the setup is working correctly.
"""

import json
import subprocess
import sys
from pathlib import Path

def test_initial_program():
    """Test that initial_program.py works"""
    print("Testing initial_program.py...")
    
    try:
        result = subprocess.run([sys.executable, "initial_program.py"], 
                              capture_output=True, text=True, timeout=10)
        
        if result.returncode == 0:
            output = json.loads(result.stdout)
            print(f"βœ… Initial program works. Params: {len(output['params'])} parameters")
            return True
        else:
            print(f"❌ Initial program failed: {result.stderr}")
            return False
            
    except Exception as e:
        print(f"❌ Initial program error: {e}")
        return False

def test_evaluator():
    """Test that evaluator.py works"""
    print("Testing evaluator.py...")
    
    try:
        result = subprocess.run([sys.executable, "evaluator.py", "initial_program.py"], 
                              capture_output=True, text=True, timeout=30)
        
        if result.returncode == 0:
            output = json.loads(result.stdout)
            if "score" in output:
                print(f"βœ… Evaluator works. Score: {output['score']:.3f}")
                return True
            else:
                print(f"❌ Evaluator missing score: {output}")
                return False
        else:
            print(f"❌ Evaluator failed: {result.stderr}")
            return False
            
    except Exception as e:
        print(f"❌ Evaluator error: {e}")
        return False

def test_mlir_file():
    """Test that MLIR file exists and is valid"""
    print("Testing MLIR baseline file...")
    
    mlir_file = Path("mlir/baseline_attention.mlir")
    if mlir_file.exists():
        content = mlir_file.read_text()
        if "func.func @baseline_attention" in content:
            print("βœ… MLIR file exists and looks valid")
            return True
        else:
            print("❌ MLIR file missing expected content")
            return False
    else:
        print("❌ MLIR file not found")
        return False

def main():
    """Run all tests"""
    print("πŸ§ͺ Testing OpenEvolve attention optimization setup...")
    print("=" * 50)
    
    tests = [
        test_mlir_file,
        test_initial_program, 
        test_evaluator
    ]
    
    passed = 0
    for test in tests:
        if test():
            passed += 1
        print()
    
    print("=" * 50)
    print(f"Tests passed: {passed}/{len(tests)}")
    
    if passed == len(tests):
        print("πŸŽ‰ Setup is ready! You can now run:")
        print("python ../../openevolve-run.py initial_program.py evaluator.py --config config.yaml --iterations 10")
    else:
        print("❌ Setup needs fixing before running evolution")
    
    return passed == len(tests)

if __name__ == "__main__":
    main()