-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path00_setup.bash
More file actions
executable file
·108 lines (86 loc) · 3.73 KB
/
Copy path00_setup.bash
File metadata and controls
executable file
·108 lines (86 loc) · 3.73 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
#!/usr/bin/env bash
# Bootstrap a fully self-contained Python environment for the paper code.
# Everything (miniforge + conda env) lives under code/.
#
# Usage: bash setup.bash
# Re-run is safe — existing installations are detected and skipped.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
MINIFORGE_VERSION="26.1.1-3"
MINIFORGE_DIR=".miniforge3"
ENV_DIR=".conda_env"
LOCKFILE="conda-linux-64.lock"
INSTALLER="Miniforge3-${MINIFORGE_VERSION}-Linux-x86_64.sh"
INSTALLER_URL="https://github.com/conda-forge/miniforge/releases/download/${MINIFORGE_VERSION}/Miniforge3-Linux-x86_64.sh"
if [[ -t 1 ]]; then
_green=$'\033[32m' _yellow=$'\033[33m' _red=$'\033[31m'
_bold=$'\033[1m' _reset=$'\033[0m'
else
_green="" _yellow="" _red="" _bold="" _reset=""
fi
log() { echo "${_green}:: $*${_reset}"; }
die() { echo "${_red}:: [ERROR] $*${_reset}" >&2; exit 1; }
step() { echo "${_bold}${_green}:: $*${_reset}"; }
# -- Preflight checks ----------------------------------------------------
[[ "$(uname -s)" == "Linux" ]] || die "This script requires Linux (got: $(uname -s))."
[[ "$(uname -m)" == "x86_64" ]] || die "This script requires x86_64 (got: $(uname -m))."
command -v curl >/dev/null 2>&1 || command -v wget >/dev/null 2>&1 \
|| die "Neither curl nor wget found. Install one of them and retry."
# -- 1. Install Miniforge locally ----------------------------------------
if [[ -x "${MINIFORGE_DIR}/bin/conda" ]]; then
log "Miniforge already installed at ${MINIFORGE_DIR}/, skipping."
else
step "Downloading Miniforge ${MINIFORGE_VERSION}..."
if command -v curl >/dev/null 2>&1; then
curl -fSL -o "$INSTALLER" "$INSTALLER_URL"
else
wget -q -O "$INSTALLER" "$INSTALLER_URL"
fi
step "Installing Miniforge to ${MINIFORGE_DIR}/..."
bash "$INSTALLER" -b -p "./${MINIFORGE_DIR}"
rm -f "$INSTALLER"
log "Miniforge installed."
fi
# -- 2. Activate conda ---------------------------------------------------
log "Activating conda..."
eval "$("./${MINIFORGE_DIR}/bin/conda" shell.bash hook)"
# -- 3. Create environment from lockfile ----------------------------------
if [[ -d "$ENV_DIR" ]]; then
log "Environment ${ENV_DIR}/ already exists, skipping."
log " To recreate: conda env remove --prefix ./${ENV_DIR} && bash setup.bash"
else
step "Creating environment from ${LOCKFILE} (this may take a few minutes)..."
conda create --yes --prefix "./${ENV_DIR}" --file "$LOCKFILE"
log "Environment created."
fi
# -- 4. Activate and verify ----------------------------------------------
log "Activating environment..."
conda activate "./${ENV_DIR}"
log "Verifying installation..."
python -c "
import dolfinx, pymor, torch, sklearn
print(f' DOLFINx {dolfinx.__version__}')
print(f' pyMOR {pymor.__version__}')
print(f' PyTorch {torch.__version__}')
print(f' sklearn {sklearn.__version__}')
"
# -- 5. Install pip-only dependencies ------------------------------------
#
# Adding pytest to the environment.yml broke the portable lockfile.
# As pinning pytest is not required for the numerical experiments,
# we can also just simply pip-install it after creating the env.
# The same applies to reuse, used to lint REUSE/SPDX license compliance.
log "Installing pip-only dependencies (pytest, reuse)..."
pip install --quiet pytest reuse
# -- 6. Create .pth file for code/ directory -----------------------------
log "Adding code/ to PYTHONPATH..."
SITE_PACKAGES="$(python -c "import site; print(site.getsitepackages()[0])")"
PTH_FILE="${SITE_PACKAGES}/code-path.pth"
echo "${SCRIPT_DIR}/code" > "$PTH_FILE"
log "Created .pth file at ${PTH_FILE}"
step "Setup complete."
echo " To activate in a new shell:"
echo ""
echo " cd $(pwd)"
echo " source 01_activate_env.bash"