-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_mac.sh
More file actions
344 lines (301 loc) · 10.1 KB
/
Copy pathsetup_mac.sh
File metadata and controls
344 lines (301 loc) · 10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
#!/usr/bin/env bash
# setup_mac.sh — one-shot macOS setup for the GP AutoML project
#
# Usage (from repo root):
# chmod +x setup_mac.sh
# ./setup_mac.sh
#
# Options (environment variables):
# VENV_DIR=./automl_env_310 — virtualenv location (default)
# PYTHON=python3.11 — force a specific Python binary
# SKIP_DATASETS=1 — skip downloading sample CSVs
# SKIP_VERIFY=1 — skip import smoke tests
#
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$REPO_ROOT"
VENV_DIR="${VENV_DIR:-$REPO_ROOT/automl_env_310}"
REQ_FILE="$REPO_ROOT/requirements-mac.txt"
PYTHON_BIN=""
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
info() { echo -e "${BLUE}[setup]${NC} $*"; }
ok() { echo -e "${GREEN}[setup]${NC} $*"; }
warn() { echo -e "${YELLOW}[setup]${NC} $*"; }
fail() { echo -e "${RED}[setup]${NC} $*" >&2; exit 1; }
is_yes() {
case "$(echo "$1" | tr '[:upper:]' '[:lower:]')" in
y|yes) return 0 ;;
*) return 1 ;;
esac
}
header() {
echo ""
echo "============================================================"
echo " GP AutoML — macOS setup"
echo " Repo: $REPO_ROOT"
echo "============================================================"
}
# ---------------------------------------------------------------------------
# 1. macOS + architecture
# ---------------------------------------------------------------------------
check_macos() {
if [[ "$(uname -s)" != "Darwin" ]]; then
warn "This script is tuned for macOS. Continuing anyway..."
return
fi
local arch
arch="$(uname -m)"
if [[ "$arch" == "arm64" ]]; then
ok "Apple Silicon detected ($arch)"
else
ok "Intel Mac detected ($arch)"
fi
}
# ---------------------------------------------------------------------------
# 2. Homebrew system libraries (optional but recommended)
# ---------------------------------------------------------------------------
check_brew_deps() {
if ! command -v brew >/dev/null 2>&1; then
warn "Homebrew not found. Install from https://brew.sh for best results."
warn "Some packages (XGBoost/LightGBM) work better with: brew install libomp"
return
fi
local missing=()
for pkg in libomp graphviz; do
if ! brew list "$pkg" &>/dev/null; then
missing+=("$pkg")
fi
done
if ((${#missing[@]} > 0)); then
warn "Recommended Homebrew packages missing: ${missing[*]}"
if [[ "${NONINTERACTIVE:-0}" == "1" ]]; then
warn "NONINTERACTIVE=1 — skipping brew install"
else
read -r -p "Install via Homebrew now? [y/N] " ans
if is_yes "$ans"; then
brew install "${missing[@]}"
ok "Installed: ${missing[*]}"
else
warn "Skipped. You can install later: brew install libomp graphviz"
fi
fi
else
ok "Homebrew deps present (libomp, graphviz)"
fi
}
# ---------------------------------------------------------------------------
# 3. Python 3.10–3.12 (reject 3.13+)
# ---------------------------------------------------------------------------
python_version_ok() {
local ver="$1"
local major minor
major="$(echo "$ver" | cut -d. -f1)"
minor="$(echo "$ver" | cut -d. -f2)"
[[ "$major" -eq 3 && "$minor" -ge 10 && "$minor" -le 12 ]]
}
find_python() {
if [[ -n "${PYTHON:-}" ]]; then
echo "$PYTHON"
return
fi
local candidates=(
python3.12 python3.11 python3.10
/opt/homebrew/bin/python3.12 /opt/homebrew/bin/python3.11 /opt/homebrew/bin/python3.10
/usr/local/bin/python3.12 /usr/local/bin/python3.11 /usr/local/bin/python3.10
python3
)
for bin in "${candidates[@]}"; do
if command -v "$bin" >/dev/null 2>&1; then
local ver
ver="$("$bin" -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")' 2>/dev/null || true)"
if [[ -n "$ver" ]] && python_version_ok "$ver"; then
echo "$bin"
return
fi
fi
done
echo ""
}
setup_venv() {
local py_bin="$1"
local ver
ver="$("$py_bin" -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}")')"
if ! python_version_ok "$(echo "$ver" | cut -d. -f1-2)"; then
fail "Need Python 3.10–3.12. Found $py_bin ($ver). Python 3.13+ breaks some deps (LangChain/Pydantic)."
fi
ok "Using $py_bin (Python $ver)"
if [[ -d "$VENV_DIR" ]]; then
warn "Virtualenv already exists: $VENV_DIR"
if [[ "${NONINTERACTIVE:-0}" == "1" ]]; then
info "NONINTERACTIVE=1 — keeping existing venv"
else
read -r -p "Recreate it? This deletes the old env. [y/N] " ans
if is_yes "$ans"; then
rm -rf "$VENV_DIR"
fi
fi
fi
if [[ ! -d "$VENV_DIR" ]]; then
info "Creating virtualenv at $VENV_DIR"
"$py_bin" -m venv "$VENV_DIR"
fi
PYTHON_BIN="$VENV_DIR/bin/python"
if [[ ! -x "$PYTHON_BIN" ]]; then
fail "Venv python not found at $PYTHON_BIN"
fi
ok "Using venv python: $PYTHON_BIN ($("$PYTHON_BIN" --version))"
}
install_packages() {
info "Upgrading pip..."
"$PYTHON_BIN" -m pip install --upgrade pip setuptools wheel
if [[ ! -f "$REQ_FILE" ]]; then
fail "Missing $REQ_FILE"
fi
info "Installing Python packages (this may take several minutes)..."
info " • Core ML stack (numpy, pandas, sklearn, xgboost, lightgbm)"
info " • AutoGluon tabular"
info " • LangChain / LangGraph"
info " • Dask, Optuna, OpenML"
# Stage installs — helps when wheels fail mid-way
"$PYTHON_BIN" -m pip install "numpy>=1.26.0,<2.2" "pandas>=2.1.0" "scipy>=1.11.0"
"$PYTHON_BIN" -m pip install -r "$REQ_FILE"
ok "Python packages installed"
}
setup_env_file() {
if [[ -f "$REPO_ROOT/.env" ]]; then
ok ".env already exists"
return
fi
if [[ -f "$REPO_ROOT/.env.example" ]]; then
cp "$REPO_ROOT/.env.example" "$REPO_ROOT/.env"
warn "Created .env from .env.example — add your GOOGLE_API_KEY before running LLM steps"
else
cat > "$REPO_ROOT/.env" <<'EOF'
GOOGLE_API_KEY=your_google_api_key_here
EOF
warn "Created .env — add your GOOGLE_API_KEY"
fi
}
download_datasets() {
if [[ "${SKIP_DATASETS:-0}" == "1" ]]; then
info "Skipping sample dataset download (SKIP_DATASETS=1)"
return
fi
info "Downloading / creating sample datasets..."
"$PYTHON_BIN" <<PY
from pathlib import Path
root = Path("${REPO_ROOT}")
cls_dir = root / "assets" / "data" / "Datasets" / "Classification Datasets"
reg_dir = root / "assets" / "data" / "Datasets" / "Regression Datasets"
cls_dir.mkdir(parents=True, exist_ok=True)
reg_dir.mkdir(parents=True, exist_ok=True)
def save(df, path):
if not path.exists():
df.to_csv(path, index=False)
print(f" created {path}")
else:
print(f" exists {path}")
from sklearn.datasets import load_iris, load_wine, load_diabetes, fetch_california_housing
iris = load_iris(as_frame=True)
df = iris.frame.rename(columns={"target": "species"})
save(df, cls_dir / "Iris.csv")
wine = load_wine(as_frame=True)
save(wine.frame, cls_dir / "wine.csv")
diabetes = load_diabetes(as_frame=True)
save(diabetes.frame, reg_dir / "diabetes.csv")
housing = fetch_california_housing(as_frame=True)
save(housing.frame.rename(columns={"MedHouseVal": "median_house_value"}), reg_dir / "California Housing Prices.csv")
fallback = root / "output" / "test_pipeline" / "iris_sample.csv"
fallback.parent.mkdir(parents=True, exist_ok=True)
if not fallback.exists():
df.to_csv(fallback, index=False)
print(f" created {fallback}")
PY
ok "Sample datasets ready under assets/data/Datasets/"
}
verify_install() {
if [[ "${SKIP_VERIFY:-0}" == "1" ]]; then
return
fi
info "Verifying imports..."
"$PYTHON_BIN" <<'PY'
import sys
errors = []
def check(label, fn):
try:
fn()
print(f" OK {label}")
except Exception as exc:
print(f" FAIL {label}: {exc}")
errors.append(label)
check("numpy", lambda: __import__("numpy"))
check("pandas", lambda: __import__("pandas"))
check("sklearn", lambda: __import__("sklearn"))
check("optuna", lambda: __import__("optuna"))
check("xgboost", lambda: __import__("xgboost"))
check("lightgbm", lambda: __import__("lightgbm"))
check("dask", lambda: __import__("dask"))
check("langchain_core", lambda: __import__("langchain_core"))
check("langgraph", lambda: __import__("langgraph"))
check("langchain_google_genai", lambda: __import__("langchain_google_genai"))
check("openml", lambda: __import__("openml"))
check("autogluon.tabular", lambda: __import__("autogluon.tabular"))
check("AutoGluon TabularPredictor", lambda: __import__("autogluon.tabular", fromlist=["TabularPredictor"]))
check("torch (NN_TORCH)", lambda: __import__("torch"))
check("fastai (FASTAI)", lambda: __import__("fastai"))
if errors:
print("\nSome packages failed:", ", ".join(errors))
sys.exit(1)
print("\nAll core imports passed.")
PY
ok "Verification passed"
}
print_next_steps() {
echo ""
echo "============================================================"
echo -e "${GREEN}Setup complete!${NC}"
echo "============================================================"
echo ""
echo "1. Activate the environment:"
echo " source $VENV_DIR/bin/activate"
echo " # or run directly: $PYTHON_BIN"
echo ""
echo "2. Add your Gemini API key to .env:"
echo " GOOGLE_API_KEY=..."
echo ""
echo "3. Test the training pipeline (LLM picks models, you approve):"
echo " python src/test_tools_pipeline.py --mode manual --data iris"
echo ""
echo "4. Non-interactive quick test:"
echo " python src/test_tools_pipeline.py --mode manual --no-prompts"
echo ""
echo "5. OpenML benchmark:"
echo " python benchmark/openml_benchmark.py"
echo ""
echo "Tip: always use 'python' from the venv, not system 'python3'."
echo "============================================================"
}
# ---------------------------------------------------------------------------
# Run setup
# ---------------------------------------------------------------------------
header
check_macos
check_brew_deps
PY_BIN="$(find_python)"
if [[ -z "$PY_BIN" ]]; then
fail "No suitable Python 3.10–3.12 found.
Install one with Homebrew:
brew install python@3.11
Then re-run:
PYTHON=python3.11 ./setup_mac.sh"
fi
setup_venv "$PY_BIN"
install_packages
setup_env_file
download_datasets
verify_install
print_next_steps