Nihar Shah commited on
Commit
0db260c
Β·
1 Parent(s): 99ba617

feat: Add comprehensive Phase 2 diagnostic script - all checks pass

Browse files
Files changed (1) hide show
  1. comprehensive_diagnostic.py +225 -0
comprehensive_diagnostic.py ADDED
@@ -0,0 +1,225 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Comprehensive Phase 2 Diagnostic - Ensures submission will pass validation
4
+ """
5
+
6
+ import sys
7
+ import json
8
+ import yaml
9
+ from pathlib import Path
10
+
11
+ def check_yaml_tasks():
12
+ """Check if openenv.yaml has all tasks with graders"""
13
+ print("\n" + "="*80)
14
+ print("πŸ“‹ YAML TASK CONFIGURATION CHECK")
15
+ print("="*80)
16
+
17
+ try:
18
+ with open('openenv.yaml', 'r') as f:
19
+ config = yaml.safe_load(f)
20
+
21
+ tasks_in_yaml = config.get('tasks', [])
22
+ print(f"βœ… Tasks defined in openenv.yaml: {len(tasks_in_yaml)}")
23
+
24
+ for task in tasks_in_yaml:
25
+ print(f" - {task['task_id']}: {task['difficulty']}")
26
+ ground_truth = task.get('ground_truth', {})
27
+ print(f" Ground truth: {ground_truth}")
28
+
29
+ if len(tasks_in_yaml) < 3:
30
+ print(f"\n❌ ERROR: Only {len(tasks_in_yaml)} tasks in yaml, need β‰₯3")
31
+ return False
32
+
33
+ return True
34
+
35
+ except Exception as e:
36
+ print(f"❌ Error reading openenv.yaml: {e}")
37
+ return False
38
+
39
+ def check_python_tasks_and_graders():
40
+ """Check if Python code has all tasks with graders"""
41
+ print("\n" + "="*80)
42
+ print("🐍 PYTHON TASK & GRADER CHECK")
43
+ print("="*80)
44
+
45
+ try:
46
+ from app import get_tasks, GRADERS, get_all_graders
47
+
48
+ tasks = get_tasks()
49
+ graders = get_all_graders()
50
+
51
+ print(f"βœ… Tasks in Python code: {len(tasks)}")
52
+
53
+ # Check each task
54
+ all_valid = True
55
+ for task in tasks:
56
+ has_grader = task.grader is not None
57
+ in_registry = task.task_id in GRADERS
58
+
59
+ status = "βœ…" if (has_grader and in_registry) else "❌"
60
+ print(f" {status} {task.task_id}:")
61
+ print(f" Has grader function: {has_grader}")
62
+ print(f" In GRADERS registry: {in_registry}")
63
+ print(f" Difficulty: {task.difficulty}")
64
+
65
+ if not (has_grader and in_registry):
66
+ all_valid = False
67
+
68
+ if len(tasks) < 3:
69
+ print(f"\n❌ ERROR: Only {len(tasks)} tasks in Python, need β‰₯3")
70
+ return False
71
+
72
+ if len(graders) < 3:
73
+ print(f"\n❌ ERROR: Only {len(graders)} graders, need β‰₯3")
74
+ return False
75
+
76
+ if not all_valid:
77
+ print("\n❌ ERROR: Some tasks missing graders")
78
+ return False
79
+
80
+ print(f"\nβœ… Graders in registry: {len(graders)}")
81
+ return True
82
+
83
+ except Exception as e:
84
+ print(f"❌ Error: {e}")
85
+ import traceback
86
+ traceback.print_exc()
87
+ return False
88
+
89
+ def check_score_ranges():
90
+ """Verify all graders return scores strictly in (0, 1)"""
91
+ print("\n" + "="*80)
92
+ print("πŸ“Š SCORE RANGE VALIDATION")
93
+ print("="*80)
94
+
95
+ try:
96
+ from app import GRADERS, get_task_by_id
97
+
98
+ test_cases = [
99
+ ("Perfect match", lambda gt: {"customer_ids": gt}, "all"),
100
+ ("Wrong answer", lambda gt: {"customer_ids": ["C999"]}, "none"),
101
+ ("Empty answer", lambda gt: {"customer_ids": []}, "none"),
102
+ ]
103
+
104
+ all_valid = True
105
+
106
+ for task_id, grader in GRADERS.items():
107
+ print(f"\n{task_id}:")
108
+ task = get_task_by_id(task_id)
109
+ ground_truth = task.ground_truth.get("customer_ids", [])
110
+
111
+ for test_name, answer_gen, expected in test_cases:
112
+ answer = answer_gen(ground_truth)
113
+ score = grader(answer)
114
+
115
+ is_valid = 0.0 < score < 1.0
116
+ status = "βœ…" if is_valid else "❌"
117
+
118
+ print(f" {status} {test_name:20} score={score:.4f} (valid: {is_valid})")
119
+
120
+ if not is_valid:
121
+ all_valid = False
122
+
123
+ if not all_valid:
124
+ print("\n❌ ERROR: Some scores are not strictly between 0 and 1")
125
+ return False
126
+
127
+ print("\nβœ… All scores are strictly in (0, 1)")
128
+ return True
129
+
130
+ except Exception as e:
131
+ print(f"❌ Error: {e}")
132
+ import traceback
133
+ traceback.print_exc()
134
+ return False
135
+
136
+ def check_api_exports():
137
+ """Verify all necessary APIs are exported"""
138
+ print("\n" + "="*80)
139
+ print("πŸ”— API EXPORT CHECK")
140
+ print("="*80)
141
+
142
+ required_exports = [
143
+ 'GRADERS',
144
+ 'get_grader',
145
+ 'get_all_graders',
146
+ 'get_tasks',
147
+ 'get_task_by_id',
148
+ 'TaskGrader',
149
+ ]
150
+
151
+ try:
152
+ import app
153
+
154
+ all_exported = True
155
+ for export in required_exports:
156
+ has_export = hasattr(app, export)
157
+ status = "βœ…" if has_export else "❌"
158
+ print(f"{status} app.{export}")
159
+
160
+ if not has_export:
161
+ all_exported = False
162
+
163
+ if not all_exported:
164
+ print("\n❌ ERROR: Some required APIs are not exported")
165
+ return False
166
+
167
+ print("\nβœ… All required APIs are exported")
168
+ return True
169
+
170
+ except Exception as e:
171
+ print(f"❌ Error: {e}")
172
+ return False
173
+
174
+ def main():
175
+ """Run all diagnostic checks"""
176
+ print("\n")
177
+ print("β•”" + "="*78 + "β•—")
178
+ print("β•‘" + " "*20 + "πŸ” COMPREHENSIVE PHASE 2 DIAGNOSTIC" + " "*24 + "β•‘")
179
+ print("β•š" + "="*78 + "╝")
180
+
181
+ checks = [
182
+ ("YAML Configuration", check_yaml_tasks),
183
+ ("Python Tasks & Graders", check_python_tasks_and_graders),
184
+ ("Score Ranges", check_score_ranges),
185
+ ("API Exports", check_api_exports),
186
+ ]
187
+
188
+ results = {}
189
+ for check_name, check_func in checks:
190
+ try:
191
+ results[check_name] = check_func()
192
+ except Exception as e:
193
+ print(f"\n❌ FATAL ERROR in {check_name}: {e}")
194
+ results[check_name] = False
195
+
196
+ # Summary
197
+ print("\n" + "="*80)
198
+ print("πŸ“‹ DIAGNOSTIC SUMMARY")
199
+ print("="*80)
200
+
201
+ for check_name, passed in results.items():
202
+ status = "βœ… PASSED" if passed else "❌ FAILED"
203
+ print(f"{status}: {check_name}")
204
+
205
+ all_passed = all(results.values())
206
+
207
+ print("\n" + "="*80)
208
+ if all_passed:
209
+ print("βœ… ALL CHECKS PASSED - READY FOR SUBMISSION")
210
+ print("="*80)
211
+ print("\n✨ Your submission meets all Phase 2 requirements:")
212
+ print(" βœ… At least 3 tasks with graders")
213
+ print(" βœ… All scores strictly between 0 and 1")
214
+ print(" βœ… GRADERS registry properly exposed")
215
+ print(" βœ… All APIs exported")
216
+ print("\nπŸš€ Ready to submit to Meta PyTorch Hackathon!\n")
217
+ return 0
218
+ else:
219
+ print("❌ SOME CHECKS FAILED - FIX ERRORS BEFORE SUBMISSION")
220
+ print("="*80)
221
+ print("\n⚠️ Please review the errors above and fix them.\n")
222
+ return 1
223
+
224
+ if __name__ == "__main__":
225
+ sys.exit(main())