mirror of
https://github.com/MLSysBook/TinyTorch.git
synced 2026-07-21 20:44:04 -05:00
- Removed 01_setup module (archived to archive/setup_module) - Renumbered all modules: tensor is now 01, activations is 02, etc. - Added tito setup command for environment setup and package installation - Added numeric shortcuts: tito 01, tito 02, etc. for quick module access - Fixed view command to find dev files correctly - Updated module dependencies and references - Improved user experience: immediate ML learning instead of boring setup
15 KiB
15 KiB
In [ ]:
#| default_exp core.setup
#| export
import sys
import platformIn [ ]:
#| export
def setup():
"""Install required packages for TinyTorch development.
TODO: Install NumPy and matplotlib using pip
APPROACH:
1. Use subprocess to run pip install commands
2. Install the essential packages we need
3. Print success message
EXAMPLE:
>>> setup()
✅ Packages installed successfully!
HINT: Use subprocess.run() with ["pip", "install", "package_name"]
"""
### BEGIN SOLUTION
import subprocess
# Install essential packages
packages = ["numpy", "matplotlib"]
print("📦 Installing TinyTorch dependencies...")
for package in packages:
print(f"Installing {package}...")
subprocess.run(["pip", "install", package], check=True)
print("✅ Packages installed successfully!")
### END SOLUTIONIn [ ]:
def test_unit_setup():
"""Test setup function."""
print("🔬 Unit Test: Package Installation...")
# Test that function exists and is callable
assert callable(setup), "setup should be callable"
# Run setup (should not crash)
setup()
print("✅ Setup function works!")
# Run the test immediately
test_unit_setup()In [ ]:
#| export
def check_versions():
"""Check versions of essential packages.
TODO: Import and display version information for key packages
APPROACH:
1. Try importing NumPy and display version
2. Show Python and platform information
3. Handle import errors gracefully
EXAMPLE:
>>> check_versions()
🐍 Python: 3.11
🔢 NumPy: 1.24.3
💻 Platform: Darwin
HINT: Use try/except to handle missing packages
"""
### BEGIN SOLUTION
try:
import numpy as np
print(f"🐍 Python: {sys.version_info.major}.{sys.version_info.minor}")
print(f"🔢 NumPy: {np.__version__}")
print(f"💻 Platform: {platform.system()}")
print("✅ All packages available!")
except ImportError as e:
print(f"❌ Missing package: {e}")
print("💡 Run setup() first to install packages")
### END SOLUTIONIn [ ]:
def test_unit_check_versions():
"""Test check_versions function."""
print("🔬 Unit Test: Version Check...")
# Test that function exists and is callable
assert callable(check_versions), "check_versions should be callable"
# Run version check (should not crash)
check_versions()
print("✅ Version check function works!")
# Run the test immediately
test_unit_check_versions()In [ ]:
#| export
def get_info():
"""Create a development profile with user and system information.
A development profile helps track:
- Who is working on the project (name, email)
- What system they're using (platform, Python version)
- When the environment was set up (timestamp)
TODO: Build a profile dictionary with user input and system detection
APPROACH:
1. Collect user identity (name and email for project attribution)
2. Detect system information (platform and Python version for compatibility)
3. Add timestamp (when this environment was configured)
4. Return complete profile dictionary
EXAMPLE:
>>> profile = get_info()
Your name: Alice Smith
Your email: alice@university.edu
>>> print(profile)
{'name': 'Alice Smith', 'email': 'alice@university.edu',
'platform': 'Darwin', 'python_version': '3.11', 'timestamp': '2024-01-15T10:30:00'}
HINT: Use input() for user data, platform/sys modules for system info, datetime for timestamp
"""
### BEGIN SOLUTION
import datetime
print("👋 Creating your TinyTorch development profile...")
print("This helps track who's working on projects and their system setup.")
# Get user information
name = input("Your name: ").strip()
if not name:
name = "TinyTorch Developer"
email = input("Your email: ").strip()
if not email:
email = "dev@tinytorch.local"
# Detect system information automatically
current_time = datetime.datetime.now().isoformat()
# Create comprehensive profile
profile = {
"name": name,
"email": email,
"platform": platform.system(),
"python_version": f"{sys.version_info.major}.{sys.version_info.minor}",
"timestamp": current_time,
"setup_complete": True
}
print(f"\n✅ Profile created for {profile['name']}")
print(f"📧 Email: {profile['email']}")
print(f"💻 Platform: {profile['platform']}")
print(f"🐍 Python: {profile['python_version']}")
print(f"⏰ Created: {profile['timestamp']}")
return profile
### END SOLUTIONIn [ ]:
def test_unit_get_info():
"""Test get_info function."""
print("🔬 Unit Test: User Information...")
# Test that function exists and is callable
assert callable(get_info), "get_info should be callable"
# Mock input to avoid interactive prompt in tests
import unittest.mock
with unittest.mock.patch('builtins.input', return_value=''):
profile = get_info()
# Verify profile structure
assert isinstance(profile, dict), "get_info should return a dictionary"
assert 'name' in profile, "Profile should have 'name' field"
assert 'platform' in profile, "Profile should have 'platform' field"
print("✅ User information function works!")
# Run the test immediately
test_unit_get_info()In [ ]:
def test_unit_all():
"""Run all unit tests for this module."""
print("🧪 Running all setup tests...")
test_unit_setup()
test_unit_check_versions()
test_unit_get_info()
print("✅ All tests passed! Setup module complete.")
# Run all tests
test_unit_all()