-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreate_env.sh
More file actions
executable file
·81 lines (71 loc) · 3.02 KB
/
Copy pathcreate_env.sh
File metadata and controls
executable file
·81 lines (71 loc) · 3.02 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
#!/usr/bin/env bash
# ---------------------------------------------------------------------------
# create_env.sh — create the "sage" conda environment from scratch
#
# Usage:
# bash create_env.sh
#
# What it does:
# 1. Creates the conda env from environment.yml (conda-forge packages)
# 2. pip-installs PyTorch with CUDA 11.8 wheels (not on conda-forge)
# 3. pip-installs sage in editable mode
# 4. Registers the env as a Jupyter kernel
# ---------------------------------------------------------------------------
set -euo pipefail
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd) # utils/
REPO=$(cd "${SCRIPT_DIR}/.." && pwd) # repo root (one level up)
# Auto-detect conda; fall back to explicit path if not on PATH
if command -v conda &>/dev/null; then
CONDA=conda
else
CONDA=/home/neuweiler/miniforge3/bin/conda
fi
ENV_NAME=sage
ENV_DIR="${HOME}/.conda/envs/${ENV_NAME}"
echo "=== Sage environment setup ==="
echo " Repo : ${REPO}"
echo " Env dir : ${ENV_DIR}"
echo " Conda : $($CONDA --version)"
echo
# ---------------------------------------------------------------------------
# Step 1 — create / update the conda environment
# ---------------------------------------------------------------------------
if $CONDA env list | grep -q "^${ENV_NAME} "; then
echo "[1/4] Updating existing env '${ENV_NAME}' ..."
$CONDA env update --name "${ENV_NAME}" --file "${SCRIPT_DIR}/environment.yml" --prune
else
echo "[1/4] Creating env '${ENV_NAME}' in ${ENV_DIR} ..."
$CONDA env create --name "${ENV_NAME}" --file "${SCRIPT_DIR}/environment.yml"
fi
PIP="${ENV_DIR}/bin/pip"
PYTHON="${ENV_DIR}/bin/python"
# ---------------------------------------------------------------------------
# Step 2 — PyTorch (CUDA 11.8)
# conda-forge only carries cu120+ builds; the cu118 wheel must come from
# the official PyTorch index, matching the cu118 build in the niamh env.
# ---------------------------------------------------------------------------
echo
echo "[2/4] Installing PyTorch (cu118) via pip ..."
"${PIP}" install \
torch torchvision \
--index-url https://download.pytorch.org/whl/cu118 \
--upgrade
# ---------------------------------------------------------------------------
# Step 3 — Sage (editable install)
# ---------------------------------------------------------------------------
echo
echo "[3/4] Installing sage in editable mode ..."
"${PIP}" install -e "${REPO}"
# ---------------------------------------------------------------------------
# Step 4 — Register as a Jupyter kernel so notebooks can pick it up
# ---------------------------------------------------------------------------
echo
echo "[4/4] Registering Jupyter kernel '${ENV_NAME}' ..."
"${PYTHON}" -m ipykernel install --user --name "${ENV_NAME}" --display-name "Python (sage)"
echo
echo "=== Done ==="
echo " Activate : conda activate ${ENV_NAME}"
echo " Jupyter : jupyter lab (kernel → 'Python (sage)')"
echo
echo " Smoke test:"
echo " ${PYTHON} -c \"import lalsimulation, pycbc, torch, sage; print('all imports OK')\""