-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigrate.sh
More file actions
300 lines (251 loc) · 9.03 KB
/
migrate.sh
File metadata and controls
300 lines (251 loc) · 9.03 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
#!/bin/bash
# ============================================================
# W.I.N.G.S. Repository Migration Script
# ============================================================
#
# Restructures the flat repository into a proper Python package.
# Run from the repository root:
# cd /path/to/WINGS
# bash migrate.sh
#
# Safe to run: uses git mv (preserves history), won't overwrite
# existing files, and prints what it's doing.
#
# After running:
# git add -A
# git commit -m "refactor: restructure into wings/ package"
# ============================================================
set -euo pipefail
# Check we're in the right place
if [ ! -f "Beetle.py" ] || [ ! -d "gpu" ]; then
echo "ERROR: Run this from the WINGS repository root (where Beetle.py lives)"
exit 1
fi
# Detect whether to use 'git mv' or plain 'mv'
if git rev-parse --git-dir > /dev/null 2>&1; then
MV="git mv"
echo " Using 'git mv' (preserves history)"
else
MV="mv"
echo " Using 'mv' (not a git repo)"
fi
echo ""
echo "============================================"
echo " W.I.N.G.S. Repository Migration"
echo "============================================"
echo ""
# ── Step 1: Create directory structure ──────────────────────
echo " [1/8] Creating directory structure..."
mkdir -p wings/models/cpu
mkdir -p wings/analysis
mkdir -p slurm
mkdir -p scripts
mkdir -p docs
mkdir -p envs
echo " ✓ wings/models/cpu/"
echo " ✓ wings/analysis/"
echo " ✓ slurm/"
echo " ✓ scripts/"
echo " ✓ docs/"
echo " ✓ envs/"
# ── Step 2: Move core model files ───────────────────────────
echo ""
echo " [2/8] Moving core models..."
$MV Beetle.py wings/models/cpu/beetle.py
$MV Environment.py wings/models/cpu/environment.py
$MV Reproduction.py wings/models/cpu/reproduction.py
$MV ParameterSet.py wings/models/cpu/parameters.py
echo " ✓ CPU model → wings/models/cpu/"
$MV gpu/gpu_simulation.py wings/models/gpu_abm.py
$MV gpu/fixed_generation_sim.py wings/models/wfm.py
echo " ✓ GPU ABM → wings/models/gpu_abm.py"
echo " ✓ WFM → wings/models/wfm.py"
# ── Step 3: Move analysis files ─────────────────────────────
echo ""
echo " [3/8] Moving analysis & plotting..."
$MV ingest_data.py wings/analysis/ingest.py
$MV gpu/ingest_delta_p.py wings/analysis/ingest_delta_p.py
$MV plot_wings.py wings/analysis/plot_wings.py
$MV gpu/plot_delta_p.py wings/analysis/plot_delta_p.py
# Keep the better version of run_analysis (scripts/ has scipy.stats)
if [ -f "scripts/run_analysis.py" ]; then
$MV scripts/run_analysis.py wings/analysis/stats.py
fi
echo " ✓ Analysis scripts → wings/analysis/"
# ── Step 4: Move SLURM scripts ──────────────────────────────
echo ""
echo " [4/8] Moving SLURM scripts..."
$MV gpu/submit_wings.sh slurm/submit_abm.sh
$MV gpu/run_abm_05.sh slurm/submit_abm_05.sh
$MV gpu/submit_fixed.sh slurm/submit_wfm.sh
$MV gpu/submit_delta_p.sh slurm/submit_delta_p.sh
$MV gpu/rerun_missing.sh slurm/rerun_missing.sh
echo " ✓ SLURM scripts → slurm/"
# ── Step 5: Move scripts & utilities ────────────────────────
echo ""
echo " [5/8] Moving scripts & utilities..."
# Keep the scripts/ versions (they have better defaults)
if [ -f "scripts/run_simulation.py" ]; then
$MV scripts/run_simulation.py scripts/run_simulation.py 2>/dev/null || true
fi
if [ -f "scripts/run_multiple_simulations.py" ]; then
$MV scripts/run_multiple_simulations.py scripts/run_batch.py
fi
$MV gpu/benchmark_gpu.py scripts/benchmark_gpu.py
echo " ✓ Scripts → scripts/"
# Move documentation
$MV gpu/WINGS_scaling_guide.md docs/scaling_guide.md
echo " ✓ Scaling guide → docs/"
# Move conda envs
$MV wings.yml envs/wings_cpu.yml
$MV wings_gpu.yml envs/wings_gpu.yml
echo " ✓ Conda envs → envs/"
# ── Step 6: Create __init__.py files ────────────────────────
echo ""
echo " [6/8] Creating __init__.py files..."
cat > wings/__init__.py << 'PYEOF'
"""
W.I.N.G.S. — Wolbachia Infection Numerical Growth Simulation.
A spatially explicit agent-based model of Wolbachia spread in
Tribolium beetle populations, with GPU acceleration.
"""
__version__ = "0.2.0"
PYEOF
cat > wings/models/__init__.py << 'PYEOF'
"""Simulation engines: CPU ABM, GPU ABM, and Wright-Fisher model."""
PYEOF
cat > wings/models/cpu/__init__.py << 'PYEOF'
"""Original CPU-based agent-based model (per-beetle Python loops)."""
from .environment import Environment
from .beetle import Beetle
from .reproduction import Reproduction
from .parameters import ParameterSet
PYEOF
cat > wings/analysis/__init__.py << 'PYEOF'
"""Post-simulation data ingestion, analysis, and figure generation."""
PYEOF
echo " ✓ __init__.py files created"
# ── Step 7: Fix internal imports in CPU model ───────────────
echo ""
echo " [7/8] Fixing CPU model imports..."
# environment.py: from Reproduction import → from .reproduction import
sed -i 's/^from Reproduction import Reproduction/from .reproduction import Reproduction/' \
wings/models/cpu/environment.py
sed -i 's/^from Beetle import Beetle/from .beetle import Beetle/' \
wings/models/cpu/environment.py
# reproduction.py: from Beetle import → from .beetle import
sed -i 's/^from Beetle import Beetle/from .beetle import Beetle/' \
wings/models/cpu/reproduction.py
echo " ✓ Imports updated to relative"
# ── Step 8: Create pyproject.toml ───────────────────────────
echo ""
echo " [8/8] Creating pyproject.toml..."
cat > pyproject.toml << 'TOMLEOF'
[build-system]
requires = ["setuptools>=68.0", "wheel"]
build-backend = "setuptools.build_meta"
[project]
name = "wings"
version = "0.2.0"
description = "Wolbachia Infection Numerical Growth Simulation"
readme = "README.md"
license = {text = "MIT"}
requires-python = ">=3.9"
authors = [
{name = "Bart Geurten"},
{name = "Christoph Bleidorn"},
{name = "Yeganeh Zare"},
]
dependencies = [
"numpy",
"pandas",
"matplotlib",
"tqdm",
"scipy",
]
[project.optional-dependencies]
gpu = ["torch>=2.0"]
dev = ["seaborn", "pytest"]
[tool.setuptools.packages.find]
include = ["wings*"]
TOMLEOF
echo " ✓ pyproject.toml created"
# ── Update .gitignore ───────────────────────────────────────
cat > .gitignore << 'GIEOF'
# Python
__pycache__/
*.pyc
*.pyo
*.egg-info/
dist/
build/
# Data (large CSVs not in repo)
data/*.csv
*.csv
# Figures (regenerated from data)
figures*/
*.log
# IDE
.vscode/
.idea/
*.swp
# OS
.DS_Store
Thumbs.db
GIEOF
echo ""
echo " ✓ .gitignore updated"
# ── Fix SLURM script paths ──────────────────────────────────
echo ""
echo " [9/9] Fixing SLURM script paths..."
# gpu/gpu_simulation.py → wings/models/gpu_abm.py
sed -i 's|gpu/gpu_simulation\.py|wings/models/gpu_abm.py|g' slurm/*.sh
# gpu/fixed_generation_sim.py → wings/models/wfm.py
sed -i 's|gpu/fixed_generation_sim\.py|wings/models/wfm.py|g' slurm/*.sh
echo " ✓ SLURM scripts now point to wings/models/"
# ── Report superfluous files to delete ──────────────────────
echo ""
echo "============================================"
echo " Migration complete!"
echo "============================================"
echo ""
echo " The following SUPERFLUOUS files should be deleted:"
echo " (review, then delete manually or run the commands below)"
echo ""
SUPERFLUOUS=(
"ingest_data_old.py"
"read_results.py"
"plot_results.py"
"run_multiple_simulations.py"
"run_analysis.py"
"scripts/run_plots.py"
"scripts/run_ingestion.py"
"scripts/run_ana_plots.sh"
"data/diff_names.sh"
)
for f in "${SUPERFLUOUS[@]}"; do
if [ -e "$f" ]; then
echo " $MV $f → DELETE"
fi
done
echo ""
echo " To delete them:"
echo " git rm ${SUPERFLUOUS[*]}"
echo ""
echo " Clean up empty gpu/ directory:"
echo " rm -rf gpu/__pycache__"
echo " rmdir gpu 2>/dev/null || echo ' gpu/ not empty, check manually'"
echo ""
echo " Then commit:"
echo " git add -A"
echo " git commit -m 'refactor: restructure into wings/ Python package'"
echo ""
echo " New structure:"
echo " wings/models/cpu/ — CPU ABM (beetle, environment, reproduction, parameters)"
echo " wings/models/ — GPU ABM (gpu_abm.py) + WFM (wfm.py)"
echo " wings/analysis/ — ingestion, plotting, statistics"
echo " slurm/ — all SLURM submission scripts"
echo " scripts/ — entry points, demos, benchmarks"
echo " docs/ — documentation"
echo " envs/ — conda environment definitions"
echo "============================================"