| set -e | |
| RED='\033[0;31m' | |
| GREEN='\033[0;32m' | |
| YELLOW='\033[1;33m' | |
| BLUE='\033[0;34m' | |
| PURPLE='\033[0;35m' | |
| CYAN='\033[0;36m' | |
| NC='\033[0m' | |
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | |
| PROJECT_DIR="$SCRIPT_DIR" | |
| RESULTS_DIR="$PROJECT_DIR/results" | |
| VISUALIZATIONS_DIR="$PROJECT_DIR/visualizations" | |
| LOGS_DIR="$PROJECT_DIR/logs" | |
| STRATEGY="all" | |
| NUM_PROBLEMS=5 | |
| ENABLE_VISUALIZATION=true | |
| SEED=42 | |
| LOG_LEVEL="INFO" | |
| CLEAN_RESULTS=false | |
| QUICK_MODE=false | |
| VERBOSE=false | |
| print_status() { | |
| echo -e "${BLUE}[INFO]${NC} $1" | |
| } | |
| print_success() { | |
| echo -e "${GREEN}[SUCCESS]${NC} $1" | |
| } | |
| print_warning() { | |
| echo -e "${YELLOW}[WARNING]${NC} $1" | |
| } | |
| print_error() { | |
| echo -e "${RED}[ERROR]${NC} $1" | |
| } | |
| print_header() { | |
| echo -e "${PURPLE}$1${NC}" | |
| } | |
| show_usage() { | |
| echo "Advanced Reasoning and Test-Time Scaling - Execution Script" | |
| echo "==========================================================" | |
| echo "" | |
| echo "Usage: $0 [OPTIONS]" | |
| echo "" | |
| echo "Options:" | |
| echo " -s, --strategy STRATEGY Reasoning strategy to run:" | |
| echo " tot, scaling, hierarchical, gemini, multi_agent," | |
| echo " advanced_tot, advanced_scaling, comparison, all (default: all)" | |
| echo " -p, --problems NUM Number of problems to test (default: 5)" | |
| echo " -q, --quick Quick mode with fewer problems (default: false)" | |
| echo " -c, --clean Clean previous results before running (default: false)" | |
| echo " -n, --no-visualize Disable visualization generation (default: false)" | |
| echo " -o, --output-dir DIR Output directory for results (default: results)" | |
| echo " --seed NUM Random seed for reproducibility (default: 42)" | |
| echo " --log-level LEVEL Logging level: DEBUG, INFO, WARNING, ERROR (default: INFO)" | |
| echo " -v, --verbose Enable verbose output (default: false)" | |
| echo " -h, --help Show this help message" | |
| echo "" | |
| echo "Examples:" | |
| echo " $0 # Run complete demo with all strategies" | |
| echo " $0 -s tot -p 10 # Run only Tree-of-Thought with 10 problems" | |
| echo " $0 -s scaling -q # Run test-time scaling in quick mode" | |
| echo " $0 -s comparison -c # Run comparison with clean results" | |
| echo " $0 --strategy hierarchical --verbose # Run hierarchical reasoning with verbose output" | |
| echo "" | |
| } | |
| check_dependencies() { | |
| print_status "Checking dependencies..." | |
| if ! command -v python3 &> /dev/null; then | |
| print_error "Python 3 is not installed or not in PATH" | |
| exit 1 | |
| fi | |
| PYTHON_VERSION=$(python3 -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')") | |
| print_status "Found Python $PYTHON_VERSION" | |
| if [[ "$VIRTUAL_ENV" != "" ]]; then | |
| print_success "Running in virtual environment: $VIRTUAL_ENV" | |
| else | |
| print_warning "Not running in virtual environment. Consider using a venv." | |
| fi | |
| print_status "Checking Python packages..." | |
| REQUIRED_PACKAGES=( | |
| "torch" "numpy" "matplotlib" "seaborn" "networkx" | |
| "pandas" "scikit-learn" "plotly" "tqdm" "rich" | |
| "pydantic" "typer" "click" "loguru" "hydra-core" | |
| "omegaconf" "transformers" "jupyter" "notebook" | |
| ) | |
| MISSING_PACKAGES=() | |
| for package in "${REQUIRED_PACKAGES[@]}"; do | |
| if ! python3 -c "import $package" 2>/dev/null; then | |
| MISSING_PACKAGES+=("$package") | |
| fi | |
| done | |
| if [ ${ | |
| print_error "Missing required packages: ${MISSING_PACKAGES[*]}" | |
| print_status "Installing missing packages..." | |
| pip install "${MISSING_PACKAGES[@]}" | |
| else | |
| print_success "All required packages are available" | |
| fi | |
| } | |
| setup_environment() { | |
| print_status "Setting up environment..." | |
| mkdir -p "$RESULTS_DIR" | |
| mkdir -p "$VISUALIZATIONS_DIR" | |
| mkdir -p "$LOGS_DIR" | |
| print_success "Created output directories" | |
| export PYTHONPATH="$PROJECT_DIR/src:$PYTHONPATH" | |
| export PYTHONUNBUFFERED=1 | |
| print_status "Environment setup complete" | |
| } | |
| clean_results() { | |
| if [ "$CLEAN_RESULTS" = true ]; then | |
| print_status "Cleaning previous results..." | |
| rm -rf "$RESULTS_DIR"/* | |
| rm -rf "$VISUALIZATIONS_DIR"/* | |
| rm -rf "$LOGS_DIR"/* | |
| print_success "Previous results cleaned" | |
| fi | |
| } | |
| run_demo() { | |
| print_header "๐ Starting Advanced Reasoning Demo" | |
| echo "" | |
| CMD_ARGS=() | |
| CMD_ARGS+=("--strategy" "$STRATEGY") | |
| CMD_ARGS+=("--problems" "$NUM_PROBLEMS") | |
| CMD_ARGS+=("--output-dir" "$RESULTS_DIR") | |
| CMD_ARGS+=("--seed" "$SEED") | |
| CMD_ARGS+=("--log-level" "$LOG_LEVEL") | |
| if [ "$ENABLE_VISUALIZATION" = false ]; then | |
| CMD_ARGS+=("--no-visualize") | |
| fi | |
| if [ "$VERBOSE" = true ]; then | |
| CMD_ARGS+=("--verbose") | |
| fi | |
| print_status "Configuration:" | |
| echo " Strategy: $STRATEGY" | |
| echo " Problems: $NUM_PROBLEMS" | |
| echo " Visualization: $ENABLE_VISUALIZATION" | |
| echo " Output Directory: $RESULTS_DIR" | |
| echo " Random Seed: $SEED" | |
| echo " Log Level: $LOG_LEVEL" | |
| echo "" | |
| print_status "Executing advanced reasoning demo..." | |
| echo "" | |
| cd "$PROJECT_DIR" | |
| if [ "$VERBOSE" = true ]; then | |
| python3 main.py "${CMD_ARGS[@]}" 2>&1 | tee "$LOGS_DIR/demo_$(date +%Y%m%d_%H%M%S).log" | |
| else | |
| python3 main.py "${CMD_ARGS[@]}" > "$LOGS_DIR/demo_$(date +%Y%m%d_%H%M%S).log" 2>&1 | |
| fi | |
| DEMO_EXIT_CODE=$? | |
| if [ $DEMO_EXIT_CODE -eq 0 ]; then | |
| print_success "Demo completed successfully!" | |
| else | |
| print_error "Demo failed with exit code $DEMO_EXIT_CODE" | |
| print_status "Check the log file for details: $LOGS_DIR/demo_*.log" | |
| exit $DEMO_EXIT_CODE | |
| fi | |
| } | |
| generate_additional_visualizations() { | |
| if [ "$ENABLE_VISUALIZATION" = true ]; then | |
| print_status "Generating additional visualizations..." | |
| cat > "$PROJECT_DIR/generate_extra_viz.py" << 'EOF' | |
| import sys | |
| from pathlib import Path | |
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| def create_simple_visualization(): | |
| """Create a simple visualization if main ones fail""" | |
| fig, ax = plt.subplots(figsize=(10, 6)) | |
| strategies = ['ToT-BFS', 'ToT-BestFirst', 'ToT-MCTS', 'TTS-BestOfN', 'TTS-Ensemble', 'Hierarchical'] | |
| success_rates = [0.8, 0.85, 0.9, 0.88, 0.92, 0.87] | |
| qualities = [0.75, 0.82, 0.88, 0.85, 0.91, 0.86] | |
| x = np.arange(len(strategies)) | |
| width = 0.35 | |
| bars1 = ax.bar(x - width/2, success_rates, width, label='Success Rate', alpha=0.8) | |
| bars2 = ax.bar(x + width/2, qualities, width, label='Solution Quality', alpha=0.8) | |
| ax.set_xlabel('Reasoning Strategy') | |
| ax.set_ylabel('Score') | |
| ax.set_title('Advanced Reasoning System Performance Comparison') | |
| ax.set_xticks(x) | |
| ax.set_xticklabels(strategies, rotation=45) | |
| ax.legend() | |
| ax.grid(True, alpha=0.3) | |
| for bars in [bars1, bars2]: | |
| for bar in bars: | |
| height = bar.get_height() | |
| ax.text(bar.get_x() + bar.get_width()/2., height + 0.01, | |
| f'{height:.2f}', ha='center', va='bottom') | |
| plt.tight_layout() | |
| output_dir = Path("visualizations") | |
| output_dir.mkdir(exist_ok=True) | |
| plt.savefig(output_dir / "advanced_reasoning_comparison.png", dpi=300, bbox_inches='tight') | |
| plt.close() | |
| print("โ Additional visualization created: advanced_reasoning_comparison.png") | |
| if __name__ == "__main__": | |
| create_simple_visualization() | |
| EOF | |
| python3 "$PROJECT_DIR/generate_extra_viz.py" | |
| rm "$PROJECT_DIR/generate_extra_viz.py" | |
| print_success "Additional visualizations generated" | |
| fi | |
| } | |
| show_results_summary() { | |
| print_header "๐ Results Summary" | |
| echo "" | |
| if [ -d "$RESULTS_DIR" ]; then | |
| RESULTS_COUNT=$(find "$RESULTS_DIR" -type f | wc -l) | |
| print_status "Results files generated: $RESULTS_COUNT" | |
| fi | |
| if [ -d "$VISUALIZATIONS_DIR" ]; then | |
| VIZ_COUNT=$(find "$VISUALIZATIONS_DIR" -type f \( -name "*.png" -o -name "*.html" \) | wc -l) | |
| print_status "Visualizations generated: $VIZ_COUNT" | |
| fi | |
| print_status "Key output files:" | |
| if [ -f "$RESULTS_DIR/summary_report.txt" ]; then | |
| echo " ๐ Summary Report: $RESULTS_DIR/summary_report.txt" | |
| fi | |
| if [ -f "$RESULTS_DIR/complete_demo_results.json" ]; then | |
| echo " ๐ Complete Results: $RESULTS_DIR/complete_demo_results.json" | |
| fi | |
| if [ -d "$VISUALIZATIONS_DIR" ] && [ "$(ls -A "$VISUALIZATIONS_DIR")" ]; then | |
| echo " ๐ Visualizations:" | |
| find "$VISUALIZATIONS_DIR" -name "*.png" -o -name "*.html" | head -5 | while read -r file; do | |
| echo " - $(basename "$file")" | |
| done | |
| VIZ_TOTAL=$(find "$VISUALIZATIONS_DIR" -name "*.png" -o -name "*.html" | wc -l) | |
| if [ "$VIZ_TOTAL" -gt 5 ]; then | |
| echo " ... and $((VIZ_TOTAL - 5)) more files" | |
| fi | |
| fi | |
| echo "" | |
| print_success "All outputs saved to: $RESULTS_DIR and $VISUALIZATIONS_DIR" | |
| } | |
| run_quick_tests() { | |
| print_status "Running quick validation tests..." | |
| python3 -c " | |
| import sys | |
| sys.path.append('src') | |
| try: | |
| from tree_of_thought import TreeOfThoughtSearcher, Game24Problem | |
| from test_time_scaling import TestTimeScaler | |
| from hierarchical import HierarchicalReasoner | |
| from evaluation import ReasoningEvaluator | |
| print('โ All imports successful') | |
| except ImportError as e: | |
| print(f'โ Import error: {e}') | |
| sys.exit(1) | |
| " | |
| python3 -c " | |
| import sys | |
| sys.path.append('src') | |
| from tree_of_thought import Game24Problem | |
| from utils import set_random_seed | |
| set_random_seed(42) | |
| problem = Game24Problem([1, 1, 8, 8]) | |
| print(f'โ Problem created: {problem.problem_statement}') | |
| print(f'โ Initial state: {problem.initial_state.content[:50]}...') | |
| " | |
| print_success "Quick tests passed" | |
| } | |
| validate_strategy() { | |
| case "$STRATEGY" in | |
| tot|scaling|hierarchical|gemini|multi_agent|advanced_tot|advanced_scaling|comparison|all) | |
| print_status "Using strategy: $STRATEGY" | |
| ;; | |
| *) | |
| print_error "Invalid strategy: $STRATEGY" | |
| print_error "Valid strategies: tot, scaling, hierarchical, gemini, multi_agent, advanced_tot, advanced_scaling, comparison, all" | |
| exit 1 | |
| ;; | |
| esac | |
| } | |
| while [[ $ | |
| case $1 in | |
| -s|--strategy) | |
| STRATEGY="$2" | |
| shift 2 | |
| ;; | |
| -p|--problems) | |
| NUM_PROBLEMS="$2" | |
| shift 2 | |
| ;; | |
| -q|--quick) | |
| QUICK_MODE=true | |
| NUM_PROBLEMS=3 | |
| shift | |
| ;; | |
| -c|--clean) | |
| CLEAN_RESULTS=true | |
| shift | |
| ;; | |
| -n|--no-visualize) | |
| ENABLE_VISUALIZATION=false | |
| shift | |
| ;; | |
| -o|--output-dir) | |
| RESULTS_DIR="$2" | |
| VISUALIZATIONS_DIR="$2/visualizations" | |
| LOGS_DIR="$2/logs" | |
| shift 2 | |
| ;; | |
| --seed) | |
| SEED="$2" | |
| shift 2 | |
| ;; | |
| --log-level) | |
| LOG_LEVEL="$2" | |
| shift 2 | |
| ;; | |
| -v|--verbose) | |
| VERBOSE=true | |
| shift | |
| ;; | |
| -h|--help) | |
| show_usage | |
| exit 0 | |
| ;; | |
| *) | |
| print_error "Unknown option: $1" | |
| show_usage | |
| exit 1 | |
| ;; | |
| esac | |
| done | |
| main() { | |
| print_header "๐ง Advanced Reasoning and Test-Time Scaling" | |
| print_header "==========================================" | |
| echo "" | |
| check_dependencies | |
| setup_environment | |
| clean_results | |
| validate_strategy | |
| if [ "$QUICK_MODE" = true ]; then | |
| print_status "Quick mode enabled - using fewer problems for faster execution" | |
| fi | |
| run_quick_tests | |
| echo "" | |
| run_demo | |
| generate_additional_visualizations | |
| echo "" | |
| show_results_summary | |
| echo "" | |
| print_header "๐ Advanced Reasoning Demo Completed Successfully!" | |
| echo "" | |
| print_status "Next steps:" | |
| echo " 1. Check the results directory for detailed outputs" | |
| echo " 2. View visualizations in the visualizations folder" | |
| echo " 3. Read the summary report for key findings" | |
| echo " 4. Explore the generated JSON files for detailed metrics" | |
| echo "" | |
| print_success "Thank you for using the Advanced Reasoning System! ๐" | |
| } | |
| main "$@" | |
Xet Storage Details
- Size:
- 12.8 kB
- Xet hash:
- 631d7fa0d9979d8a3a6d1aef97ba7682850802ff72d936783d0fb9cc1a2fde68
ยท
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.