From dd2e02aa6dddc00c83f56d5ca49c471899d2d6dd Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Wed, 13 Aug 2025 11:37:54 +0530 Subject: [PATCH] Add a script to run the experimentation notebook --- EXPERIMENT.md | 36 +++++++++------------------ lockdrop-calculations.ipynb | 44 ++++----------------------------- lockdrop_calculations.py | 36 ++++++++++++++++++++++++++- run_experiment.sh | 49 +++++++++++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+), 65 deletions(-) create mode 100755 run_experiment.sh diff --git a/EXPERIMENT.md b/EXPERIMENT.md index 38dcc41..d352b44 100644 --- a/EXPERIMENT.md +++ b/EXPERIMENT.md @@ -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 - -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 diff --git a/lockdrop-calculations.ipynb b/lockdrop-calculations.ipynb index 003af76..50bbb28 100644 --- a/lockdrop-calculations.ipynb +++ b/lockdrop-calculations.ipynb @@ -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" }, diff --git a/lockdrop_calculations.py b/lockdrop_calculations.py index 08c7c21..03c610e 100644 --- a/lockdrop_calculations.py +++ b/lockdrop_calculations.py @@ -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 diff --git a/run_experiment.sh b/run_experiment.sh new file mode 100755 index 0000000..7618081 --- /dev/null +++ b/run_experiment.sh @@ -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."