Datasets:
Modalities:
Image
Formats:
imagefolder
Languages:
English
Size:
< 1K
Tags:
Large Language Models
LLM Evaluation
Sequential Reasoning
Scaling Laws
Synthetic Benchmarks
Commonsense Reasoning
License:
| #!/usr/bin/env python3 | |
| """ | |
| Maze Visualization Utility | |
| This script provides easy-to-use functions for visualizing mazes with optimal paths | |
| and model solutions. Supports multiple visualization modes: | |
| - Empty maze (just structure) | |
| - Optimal path only | |
| - Model path only | |
| - Side-by-side comparison | |
| Usage Examples: | |
| # Side-by-side comparison (default) | |
| python maze_visualizer_utility.py --maze_id 91 --result_file results/.../91_run3.json | |
| # Individual plots | |
| python maze_visualizer_utility.py --maze_id 91 --mode empty | |
| python maze_visualizer_utility.py --maze_id 91 --mode optimal | |
| python maze_visualizer_utility.py --maze_id 91 --result_file results/.../91_run3.json --mode model | |
| """ | |
| import sys | |
| import os | |
| sys.path.append(os.path.join(os.path.dirname(__file__), '..')) | |
| sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'core')) | |
| import json | |
| import ast | |
| import argparse | |
| from pathlib import Path | |
| from core.maze_loader import MazeLoader | |
| from plot import pretty_plot_maze | |
| def load_maze_data(maze_id, data_dir="data/emnlp/maze_40_40_2_True"): | |
| """Load maze data from pickle file.""" | |
| maze_file = os.path.join(data_dir, f"{maze_id}.pkl") | |
| if not os.path.exists(maze_file): | |
| raise FileNotFoundError(f"Maze file not found: {maze_file}") | |
| loader = MazeLoader(maze_file, removed_key_count=0) | |
| return loader, maze_file | |
| def get_optimal_solution_room_names(loader): | |
| """Get optimal solution in room name format (the correct format for plot.py).""" | |
| return loader.solution_with_room_names | |
| def load_model_solution_from_json(json_file): | |
| """Load model solution from JSON result file (already in room name format).""" | |
| with open(json_file, 'r') as f: | |
| result_data = json.load(f) | |
| solution_str = result_data['response'] | |
| solution_list = ast.literal_eval(solution_str) | |
| return solution_list, result_data | |
| def visualize_maze(maze_id, result_file=None, output_path=None, mode="comparison", data_dir="data/emnlp/maze_40_40_2_True"): | |
| """ | |
| Main visualization function with support for different modes. | |
| Args: | |
| maze_id: ID of the maze (e.g., '91') | |
| result_file: Path to JSON result file with model solution | |
| output_path: Where to save the visualization (auto-generated if None) | |
| mode: Visualization mode ("comparison", "empty", "optimal", "model") | |
| data_dir: Directory containing maze .pkl files | |
| """ | |
| print(f"Loading maze {maze_id}...") | |
| loader, maze_file = load_maze_data(maze_id, data_dir) | |
| print(f"Getting optimal solution...") | |
| optimal_solution = get_optimal_solution_room_names(loader) | |
| model_solution = None | |
| model_info = "optimal_only" | |
| if result_file and mode in ["comparison", "model"]: | |
| print(f"Loading model solution from {result_file}...") | |
| model_solution, result_data = load_model_solution_from_json(result_file) | |
| provider = result_data.get('provider', 'unknown') | |
| model_name = result_data.get('model_name', 'unknown') | |
| model_info = f"{provider}_{model_name}" | |
| # Generate output path if not provided | |
| if output_path is None: | |
| if mode == "empty": | |
| output_path = f"maze_{maze_id}_empty.png" | |
| elif mode == "optimal": | |
| output_path = f"maze_{maze_id}_optimal.png" | |
| elif mode == "model": | |
| output_path = f"maze_{maze_id}_model_{model_info}.png" | |
| else: # comparison | |
| output_path = f"maze_{maze_id}_comparison_{model_info}.png" | |
| print(f"Creating {mode} visualization...") | |
| print(f" • Maze: {maze_id}") | |
| print(f" • Mode: {mode}") | |
| print(f" • Start: {loader.data['start_room']} ({loader.room_name[loader.data['start_room']]})") | |
| print(f" • End: {loader.data['end_room']} ({loader.room_name[loader.data['end_room']]})") | |
| if mode in ["comparison", "optimal"]: | |
| print(f" • Optimal steps: {len(optimal_solution)}") | |
| if mode in ["comparison", "model"] and model_solution: | |
| print(f" • Model steps: {len(model_solution)}") | |
| pretty_plot_maze( | |
| loader, | |
| save_path=output_path, | |
| model_solution=model_solution, | |
| ground_truth_solution=optimal_solution, | |
| mode=mode | |
| ) | |
| print(f"Visualization saved: {output_path}") | |
| return output_path | |
| # Convenience functions for each mode | |
| def plot_empty_maze(maze_id, output_path=None, data_dir="data/emnlp/maze_40_40_2_True"): | |
| """Plot just the maze structure without any paths.""" | |
| return visualize_maze(maze_id, mode="empty", output_path=output_path, data_dir=data_dir) | |
| def plot_optimal_path(maze_id, output_path=None, data_dir="data/emnlp/maze_40_40_2_True"): | |
| """Plot maze with optimal path only.""" | |
| return visualize_maze(maze_id, mode="optimal", output_path=output_path, data_dir=data_dir) | |
| def plot_model_path(maze_id, result_file, output_path=None, data_dir="data/emnlp/maze_40_40_2_True"): | |
| """Plot maze with model path only.""" | |
| return visualize_maze(maze_id, result_file=result_file, mode="model", output_path=output_path, data_dir=data_dir) | |
| def plot_comparison(maze_id, result_file, output_path=None, data_dir="data/emnlp/maze_40_40_2_True"): | |
| """Plot side-by-side comparison of optimal vs model paths.""" | |
| return visualize_maze(maze_id, result_file=result_file, mode="comparison", output_path=output_path, data_dir=data_dir) | |
| def main(): | |
| parser = argparse.ArgumentParser(description="Visualize maze solutions with different modes") | |
| parser.add_argument("--maze_id", required=True, help="Maze ID (e.g., '91')") | |
| parser.add_argument("--result_file", help="Path to JSON result file") | |
| parser.add_argument("--output_path", help="Output path for visualization") | |
| parser.add_argument("--mode", default="comparison", | |
| choices=["comparison", "empty", "optimal", "model"], | |
| help="Visualization mode") | |
| parser.add_argument("--data_dir", default="data/emnlp/maze_40_40_2_True", | |
| help="Directory containing maze files") | |
| args = parser.parse_args() | |
| # Validate mode requirements | |
| if args.mode == "model" and not args.result_file: | |
| print("Error: --result_file is required for 'model' mode") | |
| return | |
| if args.mode == "comparison" and not args.result_file: | |
| print("Error: --result_file is required for 'comparison' mode") | |
| return | |
| visualize_maze( | |
| maze_id=args.maze_id, | |
| result_file=args.result_file, | |
| output_path=args.output_path, | |
| mode=args.mode, | |
| data_dir=args.data_dir | |
| ) | |
| if __name__ == "__main__": | |
| main() | |
| # Convenience functions for interactive use | |
| def quick_visualize(maze_id, result_file=None, mode="comparison"): | |
| """Quick visualization function for interactive use.""" | |
| return visualize_maze(maze_id, result_file, mode=mode) | |
| def show_available_mazes(data_dir="data/emnlp/maze_40_40_2_True"): | |
| """List available maze IDs.""" | |
| maze_files = list(Path(data_dir).glob("*.pkl")) | |
| maze_ids = [f.stem for f in maze_files] | |
| return sorted(maze_ids, key=int) | |
| def demo_all_modes(): | |
| """Demonstrate all visualization modes.""" | |
| print("MAZE VISUALIZATION MODES DEMO") | |
| print("=" * 50) | |
| maze_id = "91" | |
| result_file = "results/openai_gpt5_3shot_guided_cot_effectiveB2_origB2/maze_40_40_2_True/openai/gpt-5/91_removed_keys0_locked_doors2_shuffle0.0_noise0.0_run3.json" | |
| modes = ["empty", "optimal", "model", "comparison"] | |
| for mode in modes: | |
| print(f"\nCreating {mode} visualization...") | |
| try: | |
| if mode in ["model", "comparison"] and not os.path.exists(result_file): | |
| print(f" Skipping {mode} - result file not found") | |
| continue | |
| output_path = visualize_maze(maze_id, result_file if mode in ["model", "comparison"] else None, mode=mode) | |
| print(f" Created: {output_path}") | |
| except Exception as e: | |
| print(f" Error: {e}") | |
| print(f"\nDemo completed!") | |
| if __name__ == "__main__": | |
| if len(sys.argv) == 1: | |
| print("\n" + "=" * 50) | |
| demo_all_modes() | |
| else: | |
| main() |