Add a script to run the experimentation notebook

This commit is contained in:
Prathamesh Musale 2025-08-13 11:37:54 +05:30
parent 331b4ac761
commit dd2e02aa6d
4 changed files with 100 additions and 65 deletions

View File

@ -5,8 +5,9 @@ This guide explains how to use the interactive notebook to experiment with diffe
## Prerequisites
- Python 3.x
- pip
## Setup
## Quick Start
1. **Clone and Navigate to Directory**
@ -15,36 +16,21 @@ This guide explains how to use the interactive notebook to experiment with diffe
cd lockdrop-simulation
```
2. **Create Virtual Environment**
2. **Run the Experimentation Script**
```bash
python3 -m venv venv
source venv/bin/activate
./run_experiment.sh
```
3. **Install Dependencies**
This script will:
- Automatically create a Python virtual environment
- Install all required dependencies
- Launch Jupyter notebook with the experimentation interface
- Open your browser to the interactive notebook
```bash
pip install -r requirements.txt
```
3. **Use the Interactive Interface**
## Running the Experimental Notebook
1. **Start Jupyter Notebook Server**
```bash
jupyter notebook
```
This opens your browser to <http://localhost:8888>
2. **Open the Experimental Notebook**
Navigate to and open `lockdrop-calculations.ipynb`
3. **Execute the Notebook**
Run cells in order by clicking "Run All" from `Run` tab or execute individually with Shift+Enter
The notebook will open automatically in your browser. Execute the cells in order to start experimenting with different participation scenarios.
## Using the Interactive Interface

View File

@ -25,16 +25,9 @@
"source": [
"# Import shared calculation module\n",
"from lockdrop_calculations import (\n",
" configure_matplotlib, print_constants_summary, calculate_dynamic_allocations,\n",
" calculate_bonus_pools, calculate_final_allocations, generate_test_output,\n",
" print_analysis_tables, create_visualization, PENALTY_RATES, NUM_STARS, NUM_GALAXIES,\n",
" create_experiment_widgets, create_calculate_function, create_scenario_loader, create_export_function,\n",
" SCENARIOS\n",
" configure_matplotlib, print_constants_summary,\n",
" create_experimental_interface\n",
")\n",
"import json\n",
"from decimal import Decimal\n",
"import pandas as pd\n",
"from IPython.display import display, clear_output\n",
"\n",
"# Configure matplotlib\n",
"configure_matplotlib()"
@ -68,35 +61,8 @@
"metadata": {},
"outputs": [],
"source": [
"# Create experiment widgets using refactored function\n",
"widget_dict = create_experiment_widgets()\n",
"\n",
"# Create calculation function using refactored approach\n",
"calculate_and_display = create_calculate_function(widget_dict)\n",
"\n",
"# Connect button to calculation function\n",
"widget_dict['calculate_button'].on_click(calculate_and_display)\n",
"\n",
"# Display widgets\n",
"print(\"🎯 PARTICIPATION INPUT CONTROLS\")\n",
"print(\"=\"*50)\n",
"\n",
"print(\"\\n⭐ STAR PARTICIPATION\")\n",
"display(widget_dict['star_controls'])\n",
"\n",
"print(\"\\n🌌 GALAXY PARTICIPATION\")\n",
"display(widget_dict['galaxy_controls'])\n",
"\n",
"print(\"\\n🎮 PRESET SCENARIOS\")\n",
"display(widget_dict['scenario_dropdown'])\n",
"\n",
"# Action buttons\n",
"import ipywidgets as widgets\n",
"buttons_box = widgets.HBox([widget_dict['calculate_button'], widget_dict['export_button']])\n",
"display(buttons_box)\n",
"\n",
"# Output area\n",
"display(widget_dict['output_area'])"
"# Create complete experimental interface\n",
"create_experimental_interface()"
]
},
{
@ -110,7 +76,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "venv",
"language": "python",
"name": "python3"
},

View File

@ -19,7 +19,7 @@ from decimal import Decimal, ROUND_DOWN, getcontext
from collections import defaultdict
from tabulate import tabulate
from datetime import datetime
from IPython.display import clear_output
from IPython.display import display, clear_output
# Configure decimal precision
getcontext().prec = 28
@ -1041,3 +1041,37 @@ def run_simulation_analysis(generated_dir=None):
except Exception as e:
print(f"❌ Error during simulation analysis: {e}")
return None
def create_experimental_interface():
"""Create complete experimental interface with widgets and handlers."""
# Create widgets
widget_dict = create_experiment_widgets()
# Create calculation function
calculate_and_display = create_calculate_function(widget_dict)
# Connect button to calculation function
widget_dict['calculate_button'].on_click(calculate_and_display)
# Display interface
print("🎯 PARTICIPATION INPUT CONTROLS")
print("="*50)
print("\n🎮 PRESET SCENARIOS")
display(widget_dict['scenario_dropdown'])
print("\n⭐ STAR PARTICIPATION")
display(widget_dict['star_controls'])
print("\n🌌 GALAXY PARTICIPATION")
display(widget_dict['galaxy_controls'])
# Action buttons
buttons_box = widgets.HBox([widget_dict['calculate_button'], widget_dict['export_button']])
display(buttons_box)
# Output area
display(widget_dict['output_area'])
return None

49
run_experiment.sh Executable file
View File

@ -0,0 +1,49 @@
#!/bin/bash
# Lockdrop Allocation Experimentation Launcher
# This script automatically sets up the environment and launches the experimental notebook
set -e
echo "🚀 Starting Lockdrop Experimentation Environment..."
# Check if Python 3 is available
if ! command -v python3 &> /dev/null; then
echo "❌ Python 3 is required but not installed. Please install Python 3."
exit 1
fi
# Create virtual environment if it doesn't exist
if [ ! -d "venv" ]; then
echo "📦 Creating Python virtual environment..."
python3 -m venv venv
fi
# Activate virtual environment
echo "🔧 Activating virtual environment..."
source venv/bin/activate
# Install/upgrade dependencies
echo "📚 Installing dependencies..."
pip install -q --upgrade pip
pip install -q -r requirements.txt
# Check if Jupyter is working
if ! command -v jupyter &> /dev/null; then
echo "❌ Jupyter installation failed. Please check your Python environment."
exit 1
fi
echo "✅ Environment ready!"
echo ""
echo "🎯 Opening lockdrop experimentation notebook..."
echo " The notebook will open in your default browser at http://localhost:8888"
echo ""
echo "📝 To stop the notebook server later, press Ctrl+C in this terminal"
echo ""
# Launch Jupyter notebook
jupyter notebook lockdrop-calculations.ipynb
echo ""
echo "👋 Experimentation session ended."