Skip to content

Commit 4ce28f0

Browse files
jeremymanningclaude
andcommitted
Reorganize cost monitoring documentation and fix GCP tutorial formatting
- Create dedicated Cost Monitoring Tutorial under Cloud Platform Tutorials - Move all cost analysis functions from individual cloud tutorials to centralized tutorial - Fix formatting errors in GCP tutorial (Python code appearing as markdown) - Update GCP tutorial to remove all cost-related sections - Add comprehensive cost monitoring examples for AWS, GCP, Azure, Lambda Cloud - Include visualizations and real-world optimization examples - Fix notebook validation errors for documentation build - Update documentation index to include new cost monitoring tutorial The cost monitoring tutorial now provides: - Basic and advanced cost tracking features - Multi-cloud pricing comparisons - Spot/preemptible instance analysis - Reserved instance optimization strategies - Workload-specific recommendations - Visual cost analysis charts - Real-world pipeline examples with budget controls 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 9624add commit 4ce28f0

File tree

89 files changed

+17417
-3843
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+17417
-3843
lines changed

clustrix.egg-info/PKG-INFO

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,12 @@ Clustrix is a Python package that enables seamless distributed computing on clus
9898
## Features
9999

100100
- **Simple Decorator Interface**: Just add `@cluster` to any function
101+
- **Interactive Jupyter Widget**: `%%clusterfy` magic command with GUI configuration manager
101102
- **Multiple Cluster Support**: SLURM, PBS, SGE, Kubernetes, and SSH
102103
- **Automatic Dependency Management**: Captures and replicates your exact Python environment
104+
- **Native Cost Monitoring**: Built-in cost tracking for all major cloud providers
103105
- **Loop Parallelization**: Automatically distributes loops across cluster nodes
104-
- **Flexible Configuration**: Easy setup with config files or environment variables
106+
- **Flexible Configuration**: Easy setup with config files, environment variables, or interactive widget
105107
- **Error Handling**: Comprehensive error reporting and job monitoring
106108

107109
## Quick Start
@@ -146,6 +148,33 @@ result = expensive_computation(data, iterations=10000)
146148
print(f"Result: {result}")
147149
```
148150

151+
### Jupyter Notebook Integration
152+
153+
Clustrix provides seamless integration with Jupyter notebooks through an interactive widget:
154+
155+
```python
156+
import clustrix # Auto-loads the magic command
157+
158+
# Use the %%clusterfy magic command to open the configuration widget
159+
```
160+
161+
```jupyter
162+
%%clusterfy
163+
# Interactive widget appears with:
164+
# - Dropdown to select configurations
165+
# - Forms to create/edit cluster setups
166+
# - One-click configuration application
167+
# - Save/load configurations to files
168+
```
169+
170+
The widget includes pre-built templates for:
171+
- **Local Development**: Run jobs on your local machine
172+
- **AWS GPU Instances**: p3.2xlarge, p3.8xlarge templates
173+
- **Google Cloud**: CPU and GPU instance configurations
174+
- **Azure**: Virtual machine templates with GPU support
175+
- **SLURM HPC**: University cluster configurations
176+
- **Kubernetes**: Container-based execution
177+
149178
### Configuration File
150179

151180
Create a `clustrix.yml` file in your project directory:
@@ -178,6 +207,32 @@ environment_variables:
178207

179208
## Advanced Usage
180209

210+
### Cost Monitoring
211+
212+
Clustrix includes built-in cost monitoring for cloud providers:
213+
214+
```python
215+
from clustrix import cost_tracking_decorator, get_cost_monitor
216+
217+
# Automatic cost tracking with decorator
218+
@cost_tracking_decorator('aws', 'p3.2xlarge')
219+
@cluster(cores=8, memory='60GB')
220+
def expensive_training():
221+
# Your training code here
222+
pass
223+
224+
# Manual cost monitoring
225+
monitor = get_cost_monitor('gcp')
226+
cost_estimate = monitor.estimate_cost('n2-standard-4', hours_used=2.0)
227+
print(f"Estimated cost: ${cost_estimate.estimated_cost:.2f}")
228+
229+
# Get pricing information
230+
pricing = monitor.get_pricing_info()
231+
recommendations = monitor.get_cost_optimization_recommendations()
232+
```
233+
234+
Supported cloud providers: **AWS**, **Google Cloud**, **Azure**, **Lambda Cloud**
235+
181236
### Custom Resource Requirements
182237

183238
```python

clustrix.egg-info/SOURCES.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ clustrix/__init__.py
55
clustrix/cli.py
66
clustrix/cloud_providers.py
77
clustrix/config.py
8+
clustrix/cost_monitoring.py
89
clustrix/decorator.py
910
clustrix/executor.py
1011
clustrix/local_executor.py
1112
clustrix/loop_analysis.py
13+
clustrix/notebook_magic.py
14+
clustrix/notebook_magic_backup.py
1215
clustrix/utils.py
1316
clustrix.egg-info/PKG-INFO
1417
clustrix.egg-info/SOURCES.txt
@@ -17,16 +20,24 @@ clustrix.egg-info/entry_points.txt
1720
clustrix.egg-info/not-zip-safe
1821
clustrix.egg-info/requires.txt
1922
clustrix.egg-info/top_level.txt
23+
clustrix/cost_providers/__init__.py
24+
clustrix/cost_providers/aws.py
25+
clustrix/cost_providers/azure.py
26+
clustrix/cost_providers/gcp.py
27+
clustrix/cost_providers/lambda_cloud.py
2028
tests/__init__.py
2129
tests/conftest.py
2230
tests/test_cli.py
2331
tests/test_cloud_providers.py
2432
tests/test_config.py
33+
tests/test_cost_monitoring.py
2534
tests/test_decorator.py
2635
tests/test_enhanced_features.py
2736
tests/test_executor.py
37+
tests/test_github_actions_compat.py
2838
tests/test_integration.py
2939
tests/test_kubernetes_integration.py
3040
tests/test_local_executor.py
3141
tests/test_loop_analysis.py
42+
tests/test_notebook_magic.py
3243
tests/test_utils.py
Binary file not shown.
2.46 KB
Binary file not shown.
42.9 KB
Binary file not shown.
231 KB
Binary file not shown.

docs/build/doctrees/index.doctree

2.76 KB
Binary file not shown.
2.39 KB
Binary file not shown.

docs/build/doctrees/nbsphinx/notebooks/aws_cloud_tutorial.ipynb

Lines changed: 135 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -708,43 +708,145 @@
708708
"metadata": {},
709709
"outputs": [],
710710
"source": [
711-
"# Example spot instance configuration\n",
712-
"def configure_spot_instances():\n",
713-
" \"\"\"Example of using spot instances for cost savings.\"\"\"\n",
714-
" configure(\n",
715-
" cluster_type=\"ssh\",\n",
716-
" cluster_host=\"your-spot-instance-ip\",\n",
717-
" username=\"ec2-user\",\n",
718-
" key_file=\"~/.ssh/aws-clustrix-key\",\n",
719-
" remote_work_dir=\"/tmp/clustrix\",\n",
720-
" # Spot instances can be terminated, so use short timeouts\n",
721-
" default_time=\"00:30:00\",\n",
722-
" job_poll_interval=60, # Check more frequently\n",
723-
" cleanup_on_success=True # Clean up quickly\n",
724-
" )\n",
725-
" print(\"✓ Configured for spot instances with appropriate timeouts.\")\n",
726-
" return \"Spot instance configuration completed.\"\n",
727-
"\n",
728-
"# Example function to check current spot prices\n",
729-
"def check_spot_prices(instance_types=['t3.large', 't3.xlarge', 'c5.large'], region='us-east-1'):\n",
730-
" \"\"\"Check current spot prices for different instance types.\"\"\"\n",
731-
" ec2 = boto3.client('ec2', region_name=region)\n",
711+
"# Import Clustrix cost monitoring for AWS\n",
712+
"from clustrix import cost_tracking_decorator, get_cost_monitor, generate_cost_report, get_pricing_info\n",
713+
"\n",
714+
"# Example 1: Cost tracking with AWS instances\n",
715+
"@cost_tracking_decorator('aws', 'p3.2xlarge')\n",
716+
"@cluster(cores=8, memory=\"60GB\")\n",
717+
"def aws_training_with_cost_tracking():\n",
718+
" \"\"\"Example training function with AWS cost tracking.\"\"\"\n",
719+
" import time\n",
720+
" import numpy as np\n",
732721
" \n",
733-
" try:\n",
734-
" response = ec2.describe_spot_price_history(\n",
735-
" InstanceTypes=instance_types,\n",
736-
" MaxResults=len(instance_types),\n",
737-
" ProductDescriptions=['Linux/UNIX']\n",
738-
" )\n",
722+
" print(\"Starting AWS training with cost monitoring...\")\n",
723+
" time.sleep(3) # Simulate training\n",
724+
" \n",
725+
" # Simulate GPU workload\n",
726+
" data = np.random.randn(2000, 2000)\n",
727+
" result = np.linalg.svd(data)\n",
728+
" \n",
729+
" print(\"Training completed!\")\n",
730+
" return {'accuracy': 0.92, 'epochs': 50}\n",
731+
"\n",
732+
"# Example 2: Compare AWS pricing\n",
733+
"def compare_aws_pricing():\n",
734+
" \"\"\"Compare AWS EC2 pricing for different instance types.\"\"\"\n",
735+
" pricing = get_pricing_info('aws')\n",
736+
" if pricing:\n",
737+
" print(\"AWS EC2 On-Demand Pricing (USD/hour):\")\n",
738+
" \n",
739+
" # Group by category\n",
740+
" gpu_instances = {k: v for k, v in pricing.items() if k.startswith(('p3', 'p4d', 'g4dn'))}\n",
741+
" compute_instances = {k: v for k, v in pricing.items() if k.startswith('c5')}\n",
742+
" memory_instances = {k: v for k, v in pricing.items() if k.startswith('r5')}\n",
743+
" \n",
744+
" print(\"\\nGPU Instances:\")\n",
745+
" for instance, price in sorted(gpu_instances.items(), key=lambda x: x[1]):\n",
746+
" print(f\" {instance:<20}: ${price:.3f}/hour\")\n",
747+
" \n",
748+
" print(\"\\nCompute Optimized:\")\n",
749+
" for instance, price in sorted(compute_instances.items(), key=lambda x: x[1]):\n",
750+
" print(f\" {instance:<20}: ${price:.3f}/hour\")\n",
739751
" \n",
740-
" for price in response['SpotPriceHistory']:\n",
741-
" print(f\"{price['InstanceType']}: ${price['SpotPrice']}/hour in {price['AvailabilityZone']}\")\n",
752+
" print(\"\\nMemory Optimized:\")\n",
753+
" for instance, price in sorted(memory_instances.items(), key=lambda x: x[1]):\n",
754+
" print(f\" {instance:<20}: ${price:.3f}/hour\")\n",
755+
"\n",
756+
"# Example 3: AWS Spot vs On-Demand cost analysis\n",
757+
"def aws_spot_cost_analysis():\n",
758+
" \"\"\"Analyze potential savings with AWS Spot instances.\"\"\"\n",
759+
" monitor = get_cost_monitor('aws')\n",
760+
" if monitor:\n",
761+
" print(\"AWS Spot Instance Savings Analysis:\")\n",
762+
" print(\"-\" * 40)\n",
763+
" \n",
764+
" instance_types = ['p3.2xlarge', 'p3.8xlarge', 'g4dn.xlarge', 'c5.large']\n",
765+
" \n",
766+
" for instance in instance_types:\n",
767+
" on_demand = monitor.estimate_cost(instance, 1.0, use_spot=False)\n",
768+
" spot = monitor.estimate_cost(instance, 1.0, use_spot=True)\n",
769+
" savings = ((on_demand.hourly_rate - spot.hourly_rate) / on_demand.hourly_rate) * 100\n",
742770
" \n",
743-
" except Exception as e:\n",
744-
" print(f\"✗ Error checking spot prices: {e}\")\n",
771+
" print(f\"{instance}:\")\n",
772+
" print(f\" On-Demand: ${on_demand.hourly_rate:.3f}/hour\")\n",
773+
" print(f\" Spot: ${spot.hourly_rate:.3f}/hour\")\n",
774+
" print(f\" Savings: {savings:.1f}%\")\n",
775+
" print()\n",
776+
"\n",
777+
"# Example 4: AWS Batch cost estimation\n",
778+
"def estimate_aws_batch_costs():\n",
779+
" \"\"\"Estimate costs for AWS Batch workloads.\"\"\"\n",
780+
" monitor = get_cost_monitor('aws')\n",
781+
" if monitor:\n",
782+
" batch_estimate = monitor.estimate_batch_cost(\n",
783+
" job_queue=\"clustrix-batch-queue\",\n",
784+
" compute_environment=\"clustrix-compute-env\",\n",
785+
" estimated_jobs=100,\n",
786+
" avg_job_duration_hours=0.25\n",
787+
" )\n",
788+
" \n",
789+
" print(\"AWS Batch Cost Estimation:\")\n",
790+
" print(f\" Job Queue: {batch_estimate['job_queue']}\")\n",
791+
" print(f\" Total Jobs: {batch_estimate['estimated_jobs']}\")\n",
792+
" print(f\" Avg Duration: {batch_estimate['avg_job_duration_hours']} hours\")\n",
793+
" print(f\" Total Compute Hours: {batch_estimate['total_compute_hours']}\")\n",
794+
" print(f\" Estimated Cost: ${batch_estimate['estimated_cost']:.2f}\")\n",
795+
" print(f\" Cost per Job: ${batch_estimate['cost_per_job']:.4f}\")\n",
796+
"\n",
797+
"# Example 5: Regional pricing comparison\n",
798+
"def compare_aws_regions():\n",
799+
" \"\"\"Compare AWS pricing across different regions.\"\"\"\n",
800+
" monitor = get_cost_monitor('aws')\n",
801+
" if monitor:\n",
802+
" print(\"AWS Regional Pricing Comparison for p3.2xlarge:\")\n",
803+
" print(\"-\" * 50)\n",
804+
" \n",
805+
" regional_pricing = monitor.get_region_pricing_comparison('p3.2xlarge')\n",
806+
" for region, pricing_info in regional_pricing.items():\n",
807+
" print(f\"{region}:\")\n",
808+
" print(f\" On-Demand: ${pricing_info['on_demand_hourly']:.3f}/hour\")\n",
809+
" print(f\" Est. Spot: ${pricing_info['estimated_spot_hourly']:.3f}/hour\")\n",
810+
" print()\n",
811+
"\n",
812+
"# Example 6: Real-time AWS cost monitoring\n",
813+
"def monitor_aws_costs():\n",
814+
" \"\"\"Monitor current AWS resource usage and costs.\"\"\"\n",
815+
" report = generate_cost_report('aws', 'p3.2xlarge')\n",
816+
" if report:\n",
817+
" print(\"Current AWS Resource Status:\")\n",
818+
" print(f\" CPU Usage: {report['resource_usage']['cpu_percent']:.1f}%\")\n",
819+
" print(f\" Memory Usage: {report['resource_usage']['memory_percent']:.1f}%\")\n",
820+
" if report['resource_usage']['gpu_stats']:\n",
821+
" print(f\" GPU Count: {len(report['resource_usage']['gpu_stats'])}\")\n",
822+
" print(f\" Hourly Rate: ${report['cost_estimate']['hourly_rate']:.3f}\")\n",
823+
" \n",
824+
" if report['recommendations']:\n",
825+
" print(\"\\nCost Optimization Recommendations:\")\n",
826+
" for rec in report['recommendations']:\n",
827+
" print(f\" • {rec}\")\n",
828+
"\n",
829+
"# Run examples\n",
830+
"print(\"AWS Cost Monitoring Examples:\")\n",
831+
"print(\"=\" * 40)\n",
832+
"\n",
833+
"print(\"\\n1. AWS Pricing Comparison:\")\n",
834+
"compare_aws_pricing()\n",
835+
"\n",
836+
"print(\"\\n2. Spot Instance Savings Analysis:\")\n",
837+
"aws_spot_cost_analysis()\n",
838+
"\n",
839+
"print(\"\\n3. AWS Batch Cost Estimation:\")\n",
840+
"estimate_aws_batch_costs()\n",
841+
"\n",
842+
"print(\"\\n4. Regional Pricing Comparison:\")\n",
843+
"compare_aws_regions()\n",
844+
"\n",
845+
"print(\"\\n5. Current AWS Status:\")\n",
846+
"monitor_aws_costs()\n",
745847
"\n",
746-
"# Uncomment to check current spot prices:\n",
747-
"# check_spot_prices()"
848+
"print(\"\\n✅ AWS cost monitoring examples ready!\")\n",
849+
"print(\"💡 Use @cost_tracking_decorator('aws', 'instance_type') for automatic cost tracking\")"
748850
]
749851
},
750852
{

0 commit comments

Comments
 (0)