| |
| """ |
| Setup script for minimoX - automates the installation and setup process. |
| Similar to run_eval.py but for initial setup. |
| """ |
|
|
| import subprocess |
| import os |
| import time |
| from pathlib import Path |
|
|
| |
|
|
| |
| REPO_URL = "https://github.com/ayush1801/minimoX.git" |
| CLONE_DIR = Path.home() / "minimoX" |
| ENV_NAME = "minimo_new" |
| PYTHON_VERSION = "3.11.10" |
| REDIS_PORT = 6379 |
| NUM_GPUS = 4 |
| WORKER_CONCURRENCY = 4 |
| WORKER_PREFETCH_MULTIPLIER = 1 |
|
|
| |
| LEARNING_DIR = None |
| ENVIRONMENT_DIR = None |
|
|
| |
|
|
| def run(cmd: list[str], check: bool = True, cwd: Path | None = None, shell: bool = False): |
| """Run a command and optionally check for errors.""" |
| print(f"[RUNNING] {' '.join(cmd) if isinstance(cmd, list) else cmd}") |
| if shell: |
| result = subprocess.run(cmd, shell=True, check=check, cwd=cwd) |
| else: |
| result = subprocess.run(cmd, check=check, cwd=cwd) |
| return result |
|
|
| def run_shell(cmd: str, check: bool = True, cwd: Path | None = None): |
| """Run a shell command.""" |
| return run(cmd, check=check, cwd=cwd, shell=True) |
|
|
| def has_session(name: str) -> bool: |
| """Check if a tmux session exists.""" |
| return subprocess.run(["tmux", "has-session", "-t", name], |
| stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode == 0 |
|
|
| def kill_session(name: str): |
| """Kill a tmux session if it exists.""" |
| if has_session(name): |
| print(f"[KILLING] tmux session: {name}") |
| run(["tmux", "kill-session", "-t", name]) |
|
|
| def create_tmux_session(name: str, command: str): |
| """Create a tmux session with a command.""" |
| if has_session(name): |
| print(f"[SKIPPING] tmux session {name} already exists") |
| return |
| print(f"[CREATING] tmux session: {name}") |
| run(["tmux", "new-session", "-d", "-s", name, "bash", "-lc", command]) |
|
|
| def check_command_exists(cmd: str) -> bool: |
| """Check if a command exists in PATH.""" |
| return subprocess.run(["which", cmd], |
| stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode == 0 |
|
|
| def main(): |
| |
| global LEARNING_DIR, ENVIRONMENT_DIR |
| LEARNING_DIR = CLONE_DIR / "learning" |
| ENVIRONMENT_DIR = CLONE_DIR / "environment" |
| |
| print("=" * 60) |
| print("minimoX Setup Script") |
| print("=" * 60) |
| print(f"Repository: {REPO_URL}") |
| print(f"Clone directory: {CLONE_DIR}") |
| print(f"Conda environment: {ENV_NAME}") |
| print(f"Python version: {PYTHON_VERSION}") |
| print(f"Number of GPU workers: {NUM_GPUS}") |
| print("=" * 60) |
| |
| |
| if not CLONE_DIR.exists(): |
| print("\n[STEP 1] Cloning repository...") |
| CLONE_DIR.parent.mkdir(parents=True, exist_ok=True) |
| run(["git", "clone", REPO_URL, str(CLONE_DIR)]) |
| else: |
| print(f"\n[STEP 1] Repository already exists at {CLONE_DIR}, skipping clone") |
| print(" (To re-clone, delete the directory first)") |
| |
| |
| print("\n[STEP 2] Setting up conda environment...") |
| if not check_command_exists("conda"): |
| raise RuntimeError("conda not found in PATH. Please install conda/miniconda first.") |
| |
| |
| env_check = subprocess.run( |
| ["conda", "env", "list", "--json"], |
| capture_output=True, |
| text=True |
| ) |
| env_exists = ENV_NAME in env_check.stdout |
| |
| if not env_exists: |
| print(f"Creating conda environment: {ENV_NAME}") |
| run(["conda", "create", "-n", ENV_NAME, f"python={PYTHON_VERSION}", "-y"]) |
| else: |
| print(f"Conda environment {ENV_NAME} already exists, skipping creation") |
| |
| |
| print("\n[STEP 3] Installing maturin and rust...") |
| |
| run(["conda", "run", "-n", ENV_NAME, "pip", "install", "maturin"]) |
| run(["conda", "install", "-c", "conda-forge", "rust", "-y"]) |
| |
| |
| print("\n[STEP 4] Building Rust components...") |
| if not (ENVIRONMENT_DIR / "target" / "release" / "peano").exists(): |
| print("Building with maturin...") |
| run(["conda", "run", "-n", ENV_NAME, "maturin", "dev", "--release"], cwd=ENVIRONMENT_DIR) |
| |
| print("Building peano binary...") |
| run(["cargo", "build", "--bin", "peano", "--release"], cwd=ENVIRONMENT_DIR) |
| |
| |
| print("Testing peano binary...") |
| peano_bin = ENVIRONMENT_DIR / "target" / "release" / "peano" |
| if peano_bin.exists(): |
| result = run_shell( |
| f"{peano_bin} theories/natural_number_game.p t_example1", |
| cwd=ENVIRONMENT_DIR, |
| check=False |
| ) |
| if result.returncode == 0: |
| print("[SUCCESS] Peano binary test passed") |
| else: |
| print("[WARNING] Peano binary test failed, but continuing...") |
| else: |
| print("[ERROR] Peano binary not found after build") |
| else: |
| print("Rust components already built, skipping...") |
| |
| |
| print("\n[STEP 5] Installing Python requirements...") |
| requirements_file = LEARNING_DIR / "requirements.txt" |
| if requirements_file.exists(): |
| run(["conda", "run", "-n", ENV_NAME, "pip", "install", "-r", str(requirements_file)]) |
| else: |
| print(f"[WARNING] requirements.txt not found at {requirements_file}") |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| if __name__ == "__main__": |
| main() |
|
|