-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
156 lines (124 loc) · 6.03 KB
/
Dockerfile
File metadata and controls
156 lines (124 loc) · 6.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
FROM python:3.11-bookworm
# ── System dependencies ─────────────────────────────────────────────
# EPOCH: gfortran + OpenMPI
# Euler 2D: cmake + build-essential + Eigen3 + TBB
# FEM 2D: g++ (included in build-essential)
# General: git
RUN apt-get update && \
apt-get install -y --no-install-recommends \
gfortran \
openmpi-bin libopenmpi-dev \
cmake build-essential \
libeigen3-dev libtbb-dev \
git && \
rm -rf /var/lib/apt/lists/*
WORKDIR /app
# ── Install Poetry + export plugin (used only for exporting deps) ──
RUN pip install --no-cache-dir poetry poetry-plugin-export
# ── Dependency layer caching ────────────────────────────────────────
# Export from poetry.lock → requirements.txt, then install with pip
# This avoids Poetry 2.x installer bugs with system site-packages
COPY pyproject.toml poetry.lock ./
RUN poetry export -f requirements.txt --without-hashes -o requirements.txt && \
pip install --no-cache-dir -r requirements.txt && \
rm requirements.txt
# ── Copy project source ────────────────────────────────────────────
COPY . .
# ── Compile EPOCH (2nd, 3rd, 5th order binaries) ───────────────────
RUN <<'BASH'
set -eux
# 2nd
python - <<'PY'
import re
import pathlib
mf = pathlib.Path("costsci_tools/solvers/epoch/epoch1d/Makefile")
def modify(order: str) -> None:
c = mf.read_text()
# comment out both
c = re.sub(r'^(\s*DEFINES\s*\+=\s*\$\(D\)PARTICLE_SHAPE_TOPHAT.*)$', r'#\1', c, flags=re.MULTILINE)
c = re.sub(r'^(\s*DEFINES\s*\+=\s*\$\(D\)PARTICLE_SHAPE_BSPLINE3.*)$', r'#\1', c, flags=re.MULTILINE)
# enable chosen
if order == "2nd":
c = re.sub(r'^#(\s*DEFINES\s*\+=\s*\$\(D\)PARTICLE_SHAPE_TOPHAT.*)$', r'\1', c, flags=re.MULTILINE)
elif order == "5th":
c = re.sub(r'^#(\s*DEFINES\s*\+=\s*\$\(D\)PARTICLE_SHAPE_BSPLINE3.*)$', r'\1', c, flags=re.MULTILINE)
elif order == "3rd":
pass
else:
raise ValueError(order)
mf.write_text(c)
modify("2nd")
PY
make COMPILER=gfortran -C costsci_tools/solvers/epoch/epoch1d
cp costsci_tools/solvers/epoch/epoch1d/bin/epoch1d costsci_tools/solvers/epoch/epoch1d/bin/epoch1d_2nd
make clean -C costsci_tools/solvers/epoch/epoch1d
# 3rd
python - <<'PY'
import re
import pathlib
mf = pathlib.Path("costsci_tools/solvers/epoch/epoch1d/Makefile")
def modify(order: str) -> None:
c = mf.read_text()
c = re.sub(r'^(\s*DEFINES\s*\+=\s*\$\(D\)PARTICLE_SHAPE_TOPHAT.*)$', r'#\1', c, flags=re.MULTILINE)
c = re.sub(r'^(\s*DEFINES\s*\+=\s*\$\(D\)PARTICLE_SHAPE_BSPLINE3.*)$', r'#\1', c, flags=re.MULTILINE)
if order == "2nd":
c = re.sub(r'^#(\s*DEFINES\s*\+=\s*\$\(D\)PARTICLE_SHAPE_TOPHAT.*)$', r'\1', c, flags=re.MULTILINE)
elif order == "5th":
c = re.sub(r'^#(\s*DEFINES\s*\+=\s*\$\(D\)PARTICLE_SHAPE_BSPLINE3.*)$', r'\1', c, flags=re.MULTILINE)
elif order == "3rd":
pass
else:
raise ValueError(order)
mf.write_text(c)
modify("3rd")
PY
make COMPILER=gfortran -C costsci_tools/solvers/epoch/epoch1d
cp costsci_tools/solvers/epoch/epoch1d/bin/epoch1d costsci_tools/solvers/epoch/epoch1d/bin/epoch1d_3rd
make clean -C costsci_tools/solvers/epoch/epoch1d
# 5th
python - <<'PY'
import re
import pathlib
mf = pathlib.Path("costsci_tools/solvers/epoch/epoch1d/Makefile")
def modify(order: str) -> None:
c = mf.read_text()
c = re.sub(r'^(\s*DEFINES\s*\+=\s*\$\(D\)PARTICLE_SHAPE_TOPHAT.*)$', r'#\1', c, flags=re.MULTILINE)
c = re.sub(r'^(\s*DEFINES\s*\+=\s*\$\(D\)PARTICLE_SHAPE_BSPLINE3.*)$', r'#\1', c, flags=re.MULTILINE)
if order == "2nd":
c = re.sub(r'^#(\s*DEFINES\s*\+=\s*\$\(D\)PARTICLE_SHAPE_TOPHAT.*)$', r'\1', c, flags=re.MULTILINE)
elif order == "5th":
c = re.sub(r'^#(\s*DEFINES\s*\+=\s*\$\(D\)PARTICLE_SHAPE_BSPLINE3.*)$', r'\1', c, flags=re.MULTILINE)
elif order == "3rd":
pass
else:
raise ValueError(order)
mf.write_text(c)
modify("5th")
PY
make COMPILER=gfortran -C costsci_tools/solvers/epoch/epoch1d
cp costsci_tools/solvers/epoch/epoch1d/bin/epoch1d costsci_tools/solvers/epoch/epoch1d/bin/epoch1d_5th
make clean -C costsci_tools/solvers/epoch/epoch1d
BASH
# ── Symlink so that runner-relative paths (solvers/...) resolve inside the container
RUN ln -s /app/costsci_tools/solvers /app/solvers
# ── Compile Euler 2D ────────────────────────────────────────────────
RUN mkdir -p costsci_tools/solvers/euler_2d_utils/CSMPM_BOW/build && \
cd costsci_tools/solvers/euler_2d_utils/CSMPM_BOW/build && \
cmake .. -DCMAKE_BUILD_TYPE=Release && \
make -j"$(nproc)"
# ── Compile FEM 2D (FastIPC wrapper) ────────────────────────────────
RUN cd costsci_tools/solvers/fastipc_utils/common/math/wrapper && \
g++ -shared -fPIC -mavx -mfma -mavx2 \
-I. -I./Eigen -I./EVCTCD \
-o a.so wrapper.cpp EVCTCD/CTCD.cpp
# ── Update input.deck physics_table_location to container path ──────
RUN sed -i 's|physics_table_location\s*=\s*.*|physics_table_location = /app/costsci_tools/solvers/epoch/epoch1d/src/physics_packages/TABLES/|' \
costsci_tools/runners/input.deck
# ── Environment variables ──────────────────────────────────────────
ENV PYTHONPATH=/app
ENV OMPI_ALLOW_RUN_AS_ROOT=1
ENV OMPI_ALLOW_RUN_AS_ROOT_CONFIRM=1
ENV MPLBACKEND=Agg
# ── Declare output volumes ─────────────────────────────────────────
VOLUME ["/app/sim_res", "/app/eval_results", "/app/results_model_attempt", "/app/log_model_tool_call"]
CMD ["bash"]