-
Notifications
You must be signed in to change notification settings - Fork 0
Restore set.ipynb (setup.ipynb) #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| { | ||
| "cells": [ | ||
| { | ||
| "cell_type": "markdown", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "# MindMutant Colab Setup\n", | ||
| "\n", | ||
| "Run this notebook to set up the MindMutant environment in Google Colab.\n", | ||
| "This script handles:\n", | ||
| "1. Google Drive mounting for data persistence\n", | ||
| "2. Repository cloning\n", | ||
| "3. Swapping to Colab-optimized source code (`src-colab`)\n", | ||
| "4. Dependency installation" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "# 1. Mount Google Drive\n", | ||
| "from google.colab import drive\n", | ||
| "drive.mount('/content/drive')" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "# 2. Clone Repository\n", | ||
| "import os\n", | ||
| "\n", | ||
| "if not os.path.exists('MindMutant'):\n", | ||
| " !git clone https://github.com/bonsai/MindMutant.git\n", | ||
| " %cd MindMutant\n", | ||
| "else:\n", | ||
| " %cd MindMutant\n", | ||
| " !git pull" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "# 3. Setup Data Persistence\n", | ||
| "import os\n", | ||
| "\n", | ||
| "# Define Drive data path\n", | ||
| "drive_data_path = '/content/drive/MyDrive/MindMutant/data'\n", | ||
| "\n", | ||
| "# Create directory in Drive if it doesn't exist\n", | ||
| "if not os.path.exists(drive_data_path):\n", | ||
| " os.makedirs(drive_data_path)\n", | ||
| " print(f\"Created {drive_data_path}\")\n", | ||
| "\n", | ||
| "# Link local data directory to Drive\n", | ||
| "# We remove the local 'data' folder (from git) and replace it with a symlink to Drive\n", | ||
| "if os.path.exists('data'):\n", | ||
| " if not os.path.islink('data'):\n", | ||
| " !rm -rf data\n", | ||
| " print(\"Removed default data folder\")\n", | ||
| "\n", | ||
| "if not os.path.exists('data'):\n", | ||
| " !ln -s \"$drive_data_path\" data\n", | ||
| " print(f\"Linked data directory to {drive_data_path}\")\n", | ||
|
Comment on lines
+69
to
+71
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The Useful? React with 👍 / 👎. |
||
| "else:\n", | ||
| " print(\"Data directory already linked\")" | ||
|
Comment on lines
+64
to
+73
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current logic for creating the data symlink has a bug when |
||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "# 4. Switch to Colab-Optimized Code\n", | ||
| "# We replace the standard 'src' directory with 'src-colab' to use the optimized version\n", | ||
| "if os.path.exists('src-colab'):\n", | ||
| " if os.path.exists('src'):\n", | ||
| " !rm -rf src\n", | ||
| " !mv src-colab src\n", | ||
| " print(\"Switched to Colab-optimized source code (src-colab -> src)\")\n", | ||
| "else:\n", | ||
| " print(\"src-colab not found (already switched?)\")" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "# 5. Install Dependencies\n", | ||
| "!pip install -r set/colab/requirements.txt" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "# 6. Download Spacy Model\n", | ||
| "!python -m spacy download ja_core_news_md" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "# 7. Verify Setup\n", | ||
| "import spacy\n", | ||
| "from src.deap.evolution import Evolution\n", | ||
| "\n", | ||
| "nlp = spacy.load(\"ja_core_news_md\")\n", | ||
| "print(\"✅ Spacy model loaded successfully!\")\n", | ||
| "print(\"✅ MindMutant modules importable!\")" | ||
| ] | ||
| } | ||
| ], | ||
| "metadata": { | ||
| "kernelspec": { | ||
| "display_name": "Python 3", | ||
| "language": "python", | ||
| "name": "python3" | ||
| }, | ||
| "language_info": { | ||
| "codemirror_mode": { | ||
| "name": "ipython", | ||
| "version": 3 | ||
| }, | ||
| "file_extension": ".py", | ||
| "mimetype": "text/x-python", | ||
| "name": "python", | ||
| "nbconvert_exporter": "python", | ||
| "pygments_lexer": "ipython3", | ||
| "version": "3.8.5" | ||
| } | ||
| }, | ||
| "nbformat": 4, | ||
| "nbformat_minor": 4 | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current logic for cloning the repository is not idempotent. If this cell is run a second time, the current working directory will likely be inside the repository, causing
os.path.exists('MindMutant')to beFalseand the script to erroneously attempt to clone the repository inside itself. Using absolute paths makes the script more robust and ensures it behaves correctly on subsequent runs.