Files
TinyTorch/tinytorch/core/utils.py
Vijay Janapa Reddi 9c3ee67beb Module 00_setup migration: Core functionality complete, NBGrader architecture issue discovered
 COMPLETED:
- Instructor solution executes perfectly
- NBDev export works (fixed import directives)
- Package functionality verified
- Student assignment generation works
- CLI integration complete
- Systematic testing framework established

⚠️ CRITICAL DISCOVERY:
- NBGrader requires cell metadata architecture changes
- Current generator creates content correctly but wrong cell types
- Would require major rework of assignment generation pipeline

📊 STATUS:
- Core TinyTorch functionality:  READY FOR STUDENTS
- NBGrader integration: Requires Phase 2 rework
- Ready to continue systematic testing of modules 01-06

🔧 FIXES APPLIED:
- Added #| export directive to imports in enhanced modules
- Fixed generator logic for student scaffolding
- Updated testing framework and documentation
2025-07-12 09:08:45 -04:00

302 lines
9.3 KiB
Python

# AUTOGENERATED! DO NOT EDIT! File to edit: ../../modules/00_setup/setup_dev_enhanced.ipynb.
# %% auto 0
__all__ = ['hello_tinytorch', 'add_numbers', 'SystemInfo', 'DeveloperProfile']
# %% ../../modules/00_setup/setup_dev_enhanced.ipynb 2
# Setup imports and environment
import sys
import platform
from datetime import datetime
import os
from pathlib import Path
print("🔥 TinyTorch Development Environment")
print(f"Python {sys.version}")
print(f"Platform: {platform.system()} {platform.release()}")
print(f"Started: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
# %% ../../modules/00_setup/setup_dev_enhanced.ipynb 4
def hello_tinytorch():
"""
A simple hello world function for TinyTorch.
Display TinyTorch ASCII art and welcome message.
Load the flame art from tinytorch_flame.txt file with graceful fallback.
"""
#| exercise_start
#| hint: Load ASCII art from tinytorch_flame.txt file with graceful fallback
#| solution_test: Function should display ASCII art and welcome message
#| difficulty: easy
#| points: 10
### BEGIN SOLUTION
try:
# Get the directory containing this file
current_dir = Path(__file__).parent
art_file = current_dir / "tinytorch_flame.txt"
if art_file.exists():
with open(art_file, 'r') as f:
ascii_art = f.read()
print(ascii_art)
print("Tiny🔥Torch")
print("Build ML Systems from Scratch!")
else:
print("🔥 TinyTorch 🔥")
print("Build ML Systems from Scratch!")
except NameError:
# Handle case when running in notebook where __file__ is not defined
try:
art_file = Path(os.getcwd()) / "tinytorch_flame.txt"
if art_file.exists():
with open(art_file, 'r') as f:
ascii_art = f.read()
print(ascii_art)
print("Tiny🔥Torch")
print("Build ML Systems from Scratch!")
else:
print("🔥 TinyTorch 🔥")
print("Build ML Systems from Scratch!")
except:
print("🔥 TinyTorch 🔥")
print("Build ML Systems from Scratch!")
### END SOLUTION
#| exercise_end
def add_numbers(a, b):
"""
Add two numbers together.
This is the foundation of all mathematical operations in ML.
"""
#| exercise_start
#| hint: Use the + operator to add two numbers
#| solution_test: add_numbers(2, 3) should return 5
#| difficulty: easy
#| points: 10
### BEGIN SOLUTION
return a + b
### END SOLUTION
#| exercise_end
# %% ../../modules/00_setup/setup_dev_enhanced.ipynb 8
class SystemInfo:
"""
Simple system information class.
Collects and displays Python version, platform, and machine information.
"""
def __init__(self):
"""
Initialize system information collection.
Collect Python version, platform, and machine information.
"""
#| exercise_start
#| hint: Use sys.version_info, platform.system(), and platform.machine()
#| solution_test: Should store Python version, platform, and machine info
#| difficulty: medium
#| points: 15
### BEGIN SOLUTION
self.python_version = sys.version_info
self.platform = platform.system()
self.machine = platform.machine()
### END SOLUTION
#| exercise_end
def __str__(self):
"""
Return human-readable system information.
Format system info as a readable string.
"""
#| exercise_start
#| hint: Format as "Python X.Y on Platform (Machine)"
#| solution_test: Should return formatted string with version and platform
#| difficulty: easy
#| points: 10
### BEGIN SOLUTION
return f"Python {self.python_version.major}.{self.python_version.minor} on {self.platform} ({self.machine})"
### END SOLUTION
#| exercise_end
def is_compatible(self):
"""
Check if system meets minimum requirements.
Check if Python version is >= 3.8
"""
#| exercise_start
#| hint: Compare self.python_version with (3, 8) tuple
#| solution_test: Should return True for Python >= 3.8
#| difficulty: medium
#| points: 10
### BEGIN SOLUTION
return self.python_version >= (3, 8)
### END SOLUTION
#| exercise_end
# %% ../../modules/00_setup/setup_dev_enhanced.ipynb 12
class DeveloperProfile:
"""
Developer profile for personalizing TinyTorch experience.
Stores and displays developer information with ASCII art.
"""
@staticmethod
def _load_default_flame():
"""
Load the default TinyTorch flame ASCII art from file.
Load from tinytorch_flame.txt with graceful fallback.
"""
#| exercise_start
#| hint: Use Path and file operations with try/except for fallback
#| solution_test: Should load ASCII art from file or provide fallback
#| difficulty: hard
#| points: 5
### BEGIN SOLUTION
try:
# Try to get the directory of the current file
try:
current_dir = os.path.dirname(__file__)
except NameError:
current_dir = os.getcwd()
flame_path = os.path.join(current_dir, 'tinytorch_flame.txt')
with open(flame_path, 'r', encoding='utf-8') as f:
flame_art = f.read()
return f"""{flame_art}
Tiny🔥Torch
Build ML Systems from Scratch!
"""
except (FileNotFoundError, IOError):
# Fallback to simple flame if file not found
return """
🔥 TinyTorch Developer 🔥
. . . . . .
. . . . . .
. . . . . . .
. . . . . . . .
. . . . . . . . .
. . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . . .
\\ \\ \\ \\ \\ \\ \\ \\ \\ / / / / / /
\\ \\ \\ \\ \\ \\ \\ \\ / / / / / /
\\ \\ \\ \\ \\ \\ \\ / / / / / /
\\ \\ \\ \\ \\ \\ / / / / / /
\\ \\ \\ \\ \\ / / / / / /
\\ \\ \\ \\ / / / / /
\\ \\ \\ / / / / / /
\\ \\ / / / / / /
\\ / / / / / /
\\/ / / / / /
\\/ / / / /
\\/ / / /
\\/ / /
\\/ /
\\/
Tiny🔥Torch
Build ML Systems from Scratch!
"""
### END SOLUTION
#| exercise_end
def __init__(self, name="Vijay Janapa Reddi", affiliation="Harvard University",
email="vj@eecs.harvard.edu", github_username="profvjreddi", ascii_art=None):
"""
Initialize developer profile.
Store developer information with sensible defaults.
"""
#| exercise_start
#| hint: Store all parameters as instance attributes, use _load_default_flame for ascii_art if None
#| solution_test: Should store all developer information
#| difficulty: medium
#| points: 15
### BEGIN SOLUTION
self.name = name
self.affiliation = affiliation
self.email = email
self.github_username = github_username
self.ascii_art = ascii_art or self._load_default_flame()
### END SOLUTION
#| exercise_end
def __str__(self):
"""
Return formatted developer information.
Format as professional signature.
"""
#| exercise_start
#| hint: Format as "👨‍💻 Name | Affiliation | @username"
#| solution_test: Should return formatted string with name, affiliation, and username
#| difficulty: easy
#| points: 5
### BEGIN SOLUTION
return f"👨‍💻 {self.name} | {self.affiliation} | @{self.github_username}"
### END SOLUTION
#| exercise_end
def get_signature(self):
"""
Get a short signature for code headers.
Return concise signature like "Built by Name (@github)"
"""
#| exercise_start
#| hint: Format as "Built by Name (@username)"
#| solution_test: Should return signature with name and username
#| difficulty: easy
#| points: 5
### BEGIN SOLUTION
return f"Built by {self.name} (@{self.github_username})"
### END SOLUTION
#| exercise_end
def get_ascii_art(self):
"""
Get ASCII art for the profile.
Return custom ASCII art or default flame.
"""
#| exercise_start
#| hint: Simply return self.ascii_art
#| solution_test: Should return stored ASCII art
#| difficulty: easy
#| points: 5
### BEGIN SOLUTION
return self.ascii_art
### END SOLUTION
#| exercise_end