Files
TinyTorch/scripts/check_compliance.py
Vijay Janapa Reddi 8cccf322b5 Add progressive demo system with repository reorganization
Implements comprehensive demo system showing AI capabilities unlocked by each module export:
- 8 progressive demos from tensor math to language generation
- Complete tito demo CLI integration with capability matrix
- Real AI demonstrations including XOR solving, computer vision, attention mechanisms
- Educational explanations connecting implementations to production ML systems

Repository reorganization:
- demos/ directory with all demo files and comprehensive README
- docs/ organized by category (development, nbgrader, user guides)
- scripts/ for utility and testing scripts
- Clean root directory with only essential files

Students can now run 'tito demo' after each module export to see their framework's
growing intelligence through hands-on demonstrations.
2025-09-18 17:36:32 -04:00

88 lines
3.6 KiB
Python

#!/usr/bin/env python3
"""Check NBGrader style guide compliance across all modules."""
import os
import re
from pathlib import Path
def analyze_module_compliance(filepath):
with open(filepath, 'r') as f:
content = f.read()
# Count solution blocks
solution_blocks = len(re.findall(r'### BEGIN SOLUTION', content))
# Check for required sections
has_todo = 'TODO:' in content
has_step_by_step = 'STEP-BY-STEP IMPLEMENTATION:' in content
has_example_usage = 'EXAMPLE USAGE:' in content or 'EXAMPLE:' in content
has_hints = 'IMPLEMENTATION HINTS:' in content or 'HINTS:' in content
has_connections = 'LEARNING CONNECTIONS:' in content or 'LEARNING CONNECTION:' in content
# Check for alternative patterns (older style)
has_approach = 'APPROACH:' in content
has_your_code_here = 'YOUR CODE HERE' in content
has_raise_notimpl = 'raise NotImplementedError' in content
compliance_score = sum([has_todo, has_step_by_step, has_example_usage, has_hints, has_connections])
return {
'solution_blocks': solution_blocks,
'compliance_score': compliance_score,
'has_todo': has_todo,
'has_step_by_step': has_step_by_step,
'has_example_usage': has_example_usage,
'has_hints': has_hints,
'has_connections': has_connections,
'has_old_patterns': has_approach or has_your_code_here or has_raise_notimpl
}
# Analyze all modules
modules_dir = Path('modules/source')
results = {}
for module_dir in sorted(modules_dir.iterdir()):
if module_dir.is_dir() and module_dir.name != 'utils':
py_files = list(module_dir.glob('*_dev.py'))
if py_files:
module_file = py_files[0]
results[module_dir.name] = analyze_module_compliance(module_file)
# Report results
print('=== NBGrader Style Guide Compliance Report ===\n')
print('Module | Blocks | Score | TODO | STEP | EXAM | HINT | CONN | Old? |')
print('-' * 78)
for module_name in sorted(results.keys()):
r = results[module_name]
status_emoji = '' if r['compliance_score'] == 5 else '⚠️' if r['compliance_score'] >= 3 else ''
print(f"{module_name:16} | {r['solution_blocks']:6} | {status_emoji} {r['compliance_score']}/5 | "
f"{'' if r['has_todo'] else '':^4} | "
f"{'' if r['has_step_by_step'] else '':^4} | "
f"{'' if r['has_example_usage'] else '':^4} | "
f"{'' if r['has_hints'] else '':^4} | "
f"{'' if r['has_connections'] else '':^4} | "
f"{'⚠️' if r['has_old_patterns'] else '':^4} |")
# Summary
fully_compliant = sum(1 for r in results.values() if r['compliance_score'] == 5)
needs_update = sum(1 for r in results.values() if r['compliance_score'] < 5)
has_old_patterns = sum(1 for r in results.values() if r['has_old_patterns'])
print('\n=== Summary ===')
print(f'Fully Compliant: {fully_compliant}/{len(results)}')
print(f'Needs Update: {needs_update}/{len(results)}')
print(f'Has Old Patterns: {has_old_patterns}/{len(results)}')
# List modules needing updates
print('\n=== Modules Needing Updates ===')
for module_name, r in sorted(results.items()):
if r['compliance_score'] < 5:
missing = []
if not r['has_todo']: missing.append('TODO')
if not r['has_step_by_step']: missing.append('STEP-BY-STEP')
if not r['has_example_usage']: missing.append('EXAMPLE USAGE')
if not r['has_hints']: missing.append('HINTS')
if not r['has_connections']: missing.append('CONNECTIONS')
print(f"{module_name}: Missing {', '.join(missing)}")