Add multiple solution blocks example to NBGrader assignment

- Add complex_calculation() function demonstrating multiple solution blocks within single function
- Shows how NBGrader can guide students through step-by-step implementation
- Each solution block replaced with '# YOUR CODE HERE' + 'raise NotImplementedError()' in student version
- Update total points from 85 to 95 to account for new 10-point problem
- Add comprehensive test coverage for multi-step function
- Demonstrate educational pattern: Step 1 → Step 2 → Step 3 within one function
- Perfect example of NBGrader's guided learning capabilities
This commit is contained in:
Vijay Janapa Reddi
2025-07-12 12:47:30 -04:00
parent 3d81f76897
commit 84c4f54dd5
6 changed files with 1044 additions and 171 deletions

View File

@@ -174,5 +174,7 @@ d = { 'settings': { 'branch': 'main',
'tinytorch/core/utils.py'),
'tinytorch.core.utils.add_numbers': ( '00_setup/setup_dev.html#add_numbers',
'tinytorch/core/utils.py'),
'tinytorch.core.utils.complex_calculation': ( '00_setup/setup_dev.html#complex_calculation',
'tinytorch/core/utils.py'),
'tinytorch.core.utils.hello_tinytorch': ( '00_setup/setup_dev.html#hello_tinytorch',
'tinytorch/core/utils.py')}}}

View File

@@ -1,7 +1,7 @@
# AUTOGENERATED! DO NOT EDIT! File to edit: ../../assignments/source/00_setup/setup_dev.ipynb.
# %% auto 0
__all__ = ['hello_tinytorch', 'add_numbers', 'SystemInfo', 'DeveloperProfile']
__all__ = ['hello_tinytorch', 'complex_calculation', 'add_numbers', 'SystemInfo', 'DeveloperProfile']
# %% ../../assignments/source/00_setup/setup_dev.ipynb 2
# Required imports for TinyTorch utilities
@@ -23,11 +23,56 @@ def hello_tinytorch():
4. Handle any exceptions gracefully
"""
### BEGIN SOLUTION
# YOUR CODE HERE
raise NotImplementedError()
try:
# Try to read the ASCII art file
flame_file = Path('tinytorch_flame.txt')
if flame_file.exists():
print(flame_file.read_text().strip())
else:
print("TinyTorch")
except (FileNotFoundError, OSError, UnicodeDecodeError):
# If file doesn't exist or can't be read, show simple banner
print("TinyTorch")
# Always print the tagline
print("Build ML Systems from Scratch!")
### END SOLUTION
# %% ../../assignments/source/00_setup/setup_dev.ipynb 5
# %% ../../assignments/source/00_setup/setup_dev.ipynb 6
def complex_calculation(a, b):
"""
Perform a multi-step calculation with guided implementation.
Args:
a: First number
b: Second number
Returns:
Result of multi-step calculation
"""
# Step 1: Add 2 to each input variable
# a_plus_2 = ...
### BEGIN SOLUTION
a_plus_2 = a + 2
b_plus_2 = b + 2
### END SOLUTION
# Step 2: Sum everything
# everything_summed = ...
### BEGIN SOLUTION
everything_summed = a_plus_2 + b_plus_2
### END SOLUTION
# Step 3: Multiply your previous result by 10
# Hint: you can use np.multiply if you want people to hate you
# everything_summed_times_10 = ...
### BEGIN SOLUTION
everything_summed_times_10 = everything_summed * 10
### END SOLUTION
return everything_summed_times_10
# %% ../../assignments/source/00_setup/setup_dev.ipynb 8
def add_numbers(a, b):
"""
Add two numbers together.
@@ -40,11 +85,10 @@ def add_numbers(a, b):
Sum of a and b
"""
### BEGIN SOLUTION
# YOUR CODE HERE
raise NotImplementedError()
return a + b
### END SOLUTION
# %% ../../assignments/source/00_setup/setup_dev.ipynb 6
# %% ../../assignments/source/00_setup/setup_dev.ipynb 10
class SystemInfo:
"""
A class for collecting and displaying system information.
@@ -56,8 +100,15 @@ class SystemInfo:
Collect Python version, platform, and machine information.
"""
### BEGIN SOLUTION
# YOUR CODE HERE
raise NotImplementedError()
# Get Python version info
version_info = sys.version_info
self.python_version = f"{version_info.major}.{version_info.minor}.{version_info.micro}"
# Get platform information
self.platform = platform.system()
# Get machine architecture
self.machine = platform.machine()
### END SOLUTION
def __str__(self):
@@ -66,8 +117,7 @@ class SystemInfo:
Format: "Python X.Y.Z on Platform (Architecture)"
"""
### BEGIN SOLUTION
# YOUR CODE HERE
raise NotImplementedError()
return f"Python {self.python_version} on {self.platform} ({self.machine})"
### END SOLUTION
def is_compatible(self):
@@ -76,11 +126,10 @@ class SystemInfo:
Returns True if compatible, False otherwise.
"""
### BEGIN SOLUTION
# YOUR CODE HERE
raise NotImplementedError()
return sys.version_info[:2] >= (3, 8)
### END SOLUTION
# %% ../../assignments/source/00_setup/setup_dev.ipynb 7
# %% ../../assignments/source/00_setup/setup_dev.ipynb 12
class DeveloperProfile:
"""
A class representing a developer profile.
@@ -97,8 +146,10 @@ class DeveloperProfile:
specialization: Developer's area of specialization
"""
### BEGIN SOLUTION
# YOUR CODE HERE
raise NotImplementedError()
self.name = name
self.email = email
self.affiliation = affiliation
self.specialization = specialization
### END SOLUTION
def __str__(self):
@@ -107,8 +158,7 @@ class DeveloperProfile:
Format: "Name (email)"
"""
### BEGIN SOLUTION
# YOUR CODE HERE
raise NotImplementedError()
return f"{self.name} ({self.email})"
### END SOLUTION
def get_signature(self):
@@ -117,8 +167,7 @@ class DeveloperProfile:
Should include name, affiliation, and specialization.
"""
### BEGIN SOLUTION
# YOUR CODE HERE
raise NotImplementedError()
return f"{self.name}\n{self.affiliation}\nSpecialization: {self.specialization}"
### END SOLUTION
def get_profile_info(self):
@@ -126,6 +175,10 @@ class DeveloperProfile:
Return comprehensive profile information as a dictionary.
"""
### BEGIN SOLUTION
# YOUR CODE HERE
raise NotImplementedError()
### END SOLUTION
return {
'name': self.name,
'email': self.email,
'affiliation': self.affiliation,
'specialization': self.specialization
}
### END SOLUTION