{ "cells": [ { "cell_type": "markdown", "id": "acd902d3", "metadata": { "cell_marker": "\"\"\"" }, "source": [ "# Setup - Building Your ML Development Foundation\n", "\n", "Welcome to TinyTorch Setup! You'll configure your development environment for machine learning.\n", "\n", "## ๐Ÿ”— Building on Previous Learning\n", "**What You Need**:\n", "- Python 3.8+ installed on your system\n", "- Basic command line familiarity\n", "\n", "**What's Working**: You have Python installed and ready to go.\n", "\n", "**The Gap**: Raw Python isn't sufficient for ML computation - we need optimized libraries.\n", "\n", "**This Module's Solution**: Set up NumPy foundation and validate your environment.\n", "\n", "**Connection Map**:\n", "```\n", "Python โ†’ Setup โ†’ Tensor\n", "(base) (tools) (computation)\n", "```\n", "\n", "## Learning Objectives\n", "1. **Environment Setup**: Install and validate ML dependencies\n", "2. **Basic Validation**: Check versions and system compatibility \n", "3. **Development Profile**: Create user configuration for projects\n", "4. **Testing Skills**: Validate setup with immediate feedback\n", "\n", "## Build โ†’ Test โ†’ Use\n", "1. **Build**: Install packages and create validation functions\n", "2. **Test**: Verify each function works correctly\n", "3. **Use**: Apply setup in real ML development workflow" ] }, { "cell_type": "code", "execution_count": null, "id": "5ce2c751", "metadata": { "nbgrader": { "grade": false, "grade_id": "setup-imports", "locked": false, "schema_version": 3, "solution": false, "task": false } }, "outputs": [], "source": [ "#| default_exp core.setup\n", "\n", "#| export\n", "import sys\n", "import platform" ] }, { "cell_type": "markdown", "id": "33843476", "metadata": { "cell_marker": "\"\"\"", "lines_to_next_cell": 1 }, "source": [ "## Step 1: Package Installation ๐Ÿ“ฆ\n", "\n", "Install the essential packages for ML development." ] }, { "cell_type": "code", "execution_count": null, "id": "a3628b22", "metadata": { "lines_to_next_cell": 1, "nbgrader": { "grade": false, "grade_id": "setup-function", "locked": false, "schema_version": 3, "solution": true, "task": false } }, "outputs": [], "source": [ "#| export\n", "def setup():\n", " \"\"\"Install required packages for TinyTorch development.\n", " \n", " TODO: Install NumPy and matplotlib using pip\n", " \n", " APPROACH:\n", " 1. Use subprocess to run pip install commands\n", " 2. Install the essential packages we need\n", " 3. Print success message\n", " \n", " EXAMPLE:\n", " >>> setup()\n", " โœ… Packages installed successfully!\n", " \n", " HINT: Use subprocess.run() with [\"pip\", \"install\", \"package_name\"]\n", " \"\"\"\n", " ### BEGIN SOLUTION\n", " import subprocess\n", " \n", " # Install essential packages\n", " packages = [\"numpy\", \"matplotlib\"]\n", " \n", " print(\"๐Ÿ“ฆ Installing TinyTorch dependencies...\")\n", " for package in packages:\n", " print(f\"Installing {package}...\")\n", " subprocess.run([\"pip\", \"install\", package], check=True)\n", " \n", " print(\"โœ… Packages installed successfully!\")\n", " ### END SOLUTION" ] }, { "cell_type": "markdown", "id": "f9fc3860", "metadata": { "cell_marker": "\"\"\"", "lines_to_next_cell": 1 }, "source": [ "### ๐Ÿงช Unit Test: Package Installation\n", "\n", "This test validates the setup function works correctly." ] }, { "cell_type": "code", "execution_count": null, "id": "2582b38f", "metadata": { "nbgrader": { "grade": true, "grade_id": "test-setup", "locked": true, "points": 5, "schema_version": 3, "solution": false, "task": false } }, "outputs": [], "source": [ "def test_unit_setup():\n", " \"\"\"Test setup function.\"\"\"\n", " print(\"๐Ÿ”ฌ Unit Test: Package Installation...\")\n", " \n", " # Test that function exists and is callable\n", " assert callable(setup), \"setup should be callable\"\n", " \n", " # Run setup (should not crash)\n", " setup()\n", " \n", " print(\"โœ… Setup function works!\")\n", "\n", "# Run the test immediately\n", "test_unit_setup()" ] }, { "cell_type": "markdown", "id": "bd4cd99e", "metadata": { "cell_marker": "\"\"\"", "lines_to_next_cell": 1 }, "source": [ "## Step 2: Version Checking โœ…\n", "\n", "Verify that essential packages are installed and working." ] }, { "cell_type": "code", "execution_count": null, "id": "1f69ad55", "metadata": { "lines_to_next_cell": 1, "nbgrader": { "grade": false, "grade_id": "check-versions", "locked": false, "schema_version": 3, "solution": true, "task": false } }, "outputs": [], "source": [ "#| export\n", "def check_versions():\n", " \"\"\"Check versions of essential packages.\n", " \n", " TODO: Import and display version information for key packages\n", " \n", " APPROACH:\n", " 1. Try importing NumPy and display version\n", " 2. Show Python and platform information\n", " 3. Handle import errors gracefully\n", " \n", " EXAMPLE:\n", " >>> check_versions()\n", " ๐Ÿ Python: 3.11\n", " ๐Ÿ”ข NumPy: 1.24.3\n", " ๐Ÿ’ป Platform: Darwin\n", " \n", " HINT: Use try/except to handle missing packages\n", " \"\"\"\n", " ### BEGIN SOLUTION\n", " try:\n", " import numpy as np\n", " print(f\"๐Ÿ Python: {sys.version_info.major}.{sys.version_info.minor}\")\n", " print(f\"๐Ÿ”ข NumPy: {np.__version__}\")\n", " print(f\"๐Ÿ’ป Platform: {platform.system()}\")\n", " print(\"โœ… All packages available!\")\n", " except ImportError as e:\n", " print(f\"โŒ Missing package: {e}\")\n", " print(\"๐Ÿ’ก Run setup() first to install packages\")\n", " ### END SOLUTION" ] }, { "cell_type": "markdown", "id": "a315b996", "metadata": { "cell_marker": "\"\"\"", "lines_to_next_cell": 1 }, "source": [ "### ๐Ÿงช Unit Test: Version Check\n", "\n", "This test validates the version checking function." ] }, { "cell_type": "code", "execution_count": null, "id": "156aba8d", "metadata": { "nbgrader": { "grade": true, "grade_id": "test-versions", "locked": true, "points": 5, "schema_version": 3, "solution": false, "task": false } }, "outputs": [], "source": [ "def test_unit_check_versions():\n", " \"\"\"Test check_versions function.\"\"\"\n", " print(\"๐Ÿ”ฌ Unit Test: Version Check...\")\n", " \n", " # Test that function exists and is callable\n", " assert callable(check_versions), \"check_versions should be callable\"\n", " \n", " # Run version check (should not crash)\n", " check_versions()\n", " \n", " print(\"โœ… Version check function works!\")\n", "\n", "# Run the test immediately\n", "test_unit_check_versions()" ] }, { "cell_type": "markdown", "id": "28163ece", "metadata": { "cell_marker": "\"\"\"", "lines_to_next_cell": 1 }, "source": [ "## Step 3: User Information ๐Ÿ‘‹\n", "\n", "Create a development profile for project tracking." ] }, { "cell_type": "code", "execution_count": null, "id": "a9c1d167", "metadata": { "lines_to_next_cell": 1, "nbgrader": { "grade": false, "grade_id": "user-info", "locked": false, "schema_version": 3, "solution": true, "task": false } }, "outputs": [], "source": [ "#| export\n", "def get_info():\n", " \"\"\"Create a development profile with user and system information.\n", " \n", " A development profile helps track:\n", " - Who is working on the project (name, email)\n", " - What system they're using (platform, Python version)\n", " - When the environment was set up (timestamp)\n", " \n", " TODO: Build a profile dictionary with user input and system detection\n", " \n", " APPROACH:\n", " 1. Collect user identity (name and email for project attribution)\n", " 2. Detect system information (platform and Python version for compatibility)\n", " 3. Add timestamp (when this environment was configured)\n", " 4. Return complete profile dictionary\n", " \n", " EXAMPLE:\n", " >>> profile = get_info()\n", " Your name: Alice Smith\n", " Your email: alice@university.edu\n", " >>> print(profile)\n", " {'name': 'Alice Smith', 'email': 'alice@university.edu', \n", " 'platform': 'Darwin', 'python_version': '3.11', 'timestamp': '2024-01-15T10:30:00'}\n", " \n", " HINT: Use input() for user data, platform/sys modules for system info, datetime for timestamp\n", " \"\"\"\n", " ### BEGIN SOLUTION\n", " import datetime\n", " \n", " print(\"๐Ÿ‘‹ Creating your TinyTorch development profile...\")\n", " print(\"This helps track who's working on projects and their system setup.\")\n", " \n", " # Get user information\n", " name = input(\"Your name: \").strip()\n", " if not name:\n", " name = \"TinyTorch Developer\"\n", " \n", " email = input(\"Your email: \").strip() \n", " if not email:\n", " email = \"dev@tinytorch.local\"\n", " \n", " # Detect system information automatically\n", " current_time = datetime.datetime.now().isoformat()\n", " \n", " # Create comprehensive profile\n", " profile = {\n", " \"name\": name,\n", " \"email\": email,\n", " \"platform\": platform.system(),\n", " \"python_version\": f\"{sys.version_info.major}.{sys.version_info.minor}\",\n", " \"timestamp\": current_time,\n", " \"setup_complete\": True\n", " }\n", " \n", " print(f\"\\nโœ… Profile created for {profile['name']}\")\n", " print(f\"๐Ÿ“ง Email: {profile['email']}\")\n", " print(f\"๐Ÿ’ป Platform: {profile['platform']}\")\n", " print(f\"๐Ÿ Python: {profile['python_version']}\")\n", " print(f\"โฐ Created: {profile['timestamp']}\")\n", " \n", " return profile\n", " ### END SOLUTION" ] }, { "cell_type": "markdown", "id": "48019e3a", "metadata": { "cell_marker": "\"\"\"", "lines_to_next_cell": 1 }, "source": [ "### ๐Ÿงช Unit Test: User Information\n", "\n", "This test validates the user information function." ] }, { "cell_type": "code", "execution_count": null, "id": "08221b2c", "metadata": { "nbgrader": { "grade": true, "grade_id": "test-info", "locked": true, "points": 5, "schema_version": 3, "solution": false, "task": false } }, "outputs": [], "source": [ "def test_unit_get_info():\n", " \"\"\"Test get_info function.\"\"\"\n", " print(\"๐Ÿ”ฌ Unit Test: User Information...\")\n", " \n", " # Test that function exists and is callable\n", " assert callable(get_info), \"get_info should be callable\"\n", " \n", " # Mock input to avoid interactive prompt in tests\n", " import unittest.mock\n", " with unittest.mock.patch('builtins.input', return_value=''):\n", " profile = get_info()\n", " \n", " # Verify profile structure\n", " assert isinstance(profile, dict), \"get_info should return a dictionary\"\n", " assert 'name' in profile, \"Profile should have 'name' field\"\n", " assert 'platform' in profile, \"Profile should have 'platform' field\"\n", " \n", " print(\"โœ… User information function works!\")\n", "\n", "# Run the test immediately\n", "test_unit_get_info()" ] }, { "cell_type": "markdown", "id": "7f91cd3f", "metadata": { "cell_marker": "\"\"\"", "lines_to_next_cell": 1 }, "source": [ "## ๐Ÿงช Complete Module Testing\n", "\n", "Let's run all tests to ensure everything works together." ] }, { "cell_type": "code", "execution_count": null, "id": "6a7efc46", "metadata": { "lines_to_next_cell": 2 }, "outputs": [], "source": [ "def test_unit_all():\n", " \"\"\"Run all unit tests for this module.\"\"\"\n", " print(\"๐Ÿงช Running all setup tests...\")\n", " \n", " test_unit_setup()\n", " test_unit_check_versions() \n", " test_unit_get_info()\n", " \n", " print(\"โœ… All tests passed! Setup module complete.\")\n", "\n", "# Run all tests\n", "test_unit_all()" ] }, { "cell_type": "markdown", "id": "e110b229", "metadata": { "cell_marker": "\"\"\"" }, "source": [ "## ๐ŸŽฏ MODULE SUMMARY: Setup Complete!\n", "\n", "Congratulations! You've successfully configured your ML development environment!\n", "\n", "### What You've Accomplished\n", "โœ… **Package Installation**: Automated setup with error handling\n", "โœ… **Environment Validation**: Version checking and compatibility testing \n", "โœ… **Development Profile**: User configuration for project tracking\n", "โœ… **Testing Framework**: Immediate validation with clear feedback\n", "\n", "### Key Learning Outcomes\n", "- **Environment Management**: Install and validate ML dependencies\n", "- **Error Handling**: Graceful failure management with helpful messages\n", "- **System Information**: Platform and version detection techniques\n", "- **Testing Patterns**: Immediate validation after each implementation\n", "\n", "### Ready for Next Steps\n", "Your setup implementation now enables:\n", "- **Immediate Application**: Ready for ML development with NumPy foundation\n", "- **Next Module Preparation**: Solid environment for tensor operations\n", "- **Real-World Connection**: Professional development workflow patterns\n", "\n", "### Next Steps\n", "1. **Export your module**: `tito module complete 01_setup`\n", "2. **Validate integration**: `tito test --module setup` \n", "3. **Ready for Module 02**: Tensor operations build on this foundation\n", "\n", "**Your environment is ready - let's start building ML systems!** ๐Ÿš€" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" } }, "nbformat": 4, "nbformat_minor": 5 }