-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
227 lines (187 loc) · 8.86 KB
/
Dockerfile
File metadata and controls
227 lines (187 loc) · 8.86 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
FROM python:3.11-slim AS qgraf-builder
WORKDIR /build
RUN apt-get update && apt-get install -y --no-install-recommends \
gfortran \
&& rm -rf /var/lib/apt/lists/*
COPY feynman_engine/resources/qgraf/qgraf-3.6.10.tgz ./
RUN mkdir -p src out \
&& tar -xzf qgraf-3.6.10.tgz -C src \
&& gfortran -O2 -o out/qgraf src/qgraf-3.6.10.f08 \
&& chmod +x out/qgraf
# ─── FORM builder ───────────────────────────────────────────────────────────
FROM python:3.11-slim AS form-builder
WORKDIR /build
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
g++ \
libc6-dev \
libstdc++-12-dev \
make \
&& rm -rf /var/lib/apt/lists/*
COPY feynman_engine/resources/form/form-5.0.0.tar.gz ./
RUN mkdir -p src \
&& tar -xzf form-5.0.0.tar.gz -C src \
&& cd src/form-* \
&& ./configure --disable-float --disable-parform \
&& make -j1 \
&& cp sources/form /build/form \
&& chmod +x /build/form
# ─── LoopTools builder ───────────────────────────────────────────────────────
FROM python:3.11-slim AS looptools-builder
WORKDIR /build
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
g++ \
libc6-dev \
libstdc++-12-dev \
gfortran \
make \
&& rm -rf /var/lib/apt/lists/*
COPY feynman_engine/resources/looptools/LoopTools-2.16.tar ./
RUN set -ex \
&& mkdir -p src \
&& tar -xf LoopTools-2.16.tar -C src \
&& cd src/LoopTools-2.16 \
&& export FFLAGS="-fPIC -O2" \
&& export CFLAGS="-fPIC -O2" \
&& export CC=gcc \
&& ./configure --prefix=/build/install \
&& make -j1 \
&& ls -la build/libooptools.a \
&& gfortran -shared \
-o /build/liblooptools.so \
-Wl,--whole-archive,$(pwd)/build/libooptools.a,--no-whole-archive \
-lgfortran -lm
# ─── LHAPDF builder ──────────────────────────────────────────────────────────
# LHAPDF is the standard PDF library (Buckley et al., EPJ C 75 (2015) 132).
# We compile the C++ library + Python bindings against the same Python that
# the production image uses (3.11) and install to /opt/lhapdf so it's
# auto-discovered by feynman_engine.amplitudes.pdf at runtime.
FROM python:3.11-slim AS lhapdf-builder
WORKDIR /build
RUN apt-get update && apt-get install -y --no-install-recommends \
g++ \
libc6-dev \
libstdc++-12-dev \
make \
curl \
ca-certificates \
python3-dev \
&& rm -rf /var/lib/apt/lists/*
COPY feynman_engine/resources/lhapdf/LHAPDF-6.5.5.tar.gz ./
RUN set -ex \
&& mkdir -p src \
&& tar -xzf LHAPDF-6.5.5.tar.gz -C src \
&& cd src/LHAPDF-6.5.5 \
&& PYTHON=$(which python) ./configure --prefix=/opt/lhapdf \
&& make -j2 \
&& make install
# Bundle a default PDF set (CT18LO). We try to download it during build;
# if the build host lacks internet, the stage still produces a usable
# LHAPDF install and users can run `feynman install-pdf-set CT18LO` later.
RUN mkdir -p /opt/lhapdf/share/LHAPDF \
&& cd /opt/lhapdf/share/LHAPDF \
&& (curl -fsL "http://lhapdfsets.web.cern.ch/lhapdfsets/current/CT18LO.tar.gz" -o CT18LO.tar.gz \
&& tar xzf CT18LO.tar.gz && rm CT18LO.tar.gz \
&& echo "CT18LO bundled" \
|| echo "WARNING: CT18LO download failed during build; install via feynman install-pdf-set CT18LO")
# ─── OpenLoops builder ───────────────────────────────────────────────────────
# OpenLoops 2 (Buccioni et al., EPJ C 79 (2019) 866, arXiv:1907.13071) is the
# automated tree + one-loop amplitude generator used by FeynmanEngine for
# generic NLO over arbitrary processes. Build the framework + bundle a
# minimal process library (ppllj = Drell-Yan + jet) so the production image
# can compute generic NLO out of the box.
FROM python:3.11-slim AS openloops-builder
WORKDIR /build
RUN apt-get update && apt-get install -y --no-install-recommends \
gfortran \
make \
python3-dev \
&& rm -rf /var/lib/apt/lists/*
COPY feynman_engine/resources/openloops/OpenLoops-OpenLoops-2.1.4.tar.gz ./
RUN set -ex \
&& mkdir -p src \
&& tar -xzf OpenLoops-OpenLoops-2.1.4.tar.gz -C src \
&& mv src/OpenLoops-OpenLoops-2.1.4 src/openloops \
&& cd src/openloops \
&& PYTHON=$(which python) ./scons \
&& mkdir -p /opt/openloops \
# Copy each OpenLoops tree entry that actually exists in this release.
# Mirrors the defensive `if src.exists(): copy` logic in
# feynman_engine/openloops.py:_install_openloops() — OpenLoops 2.1.4
# does NOT ship a top-level `config/` directory (the runtime config
# lives in openloops.cfg.tmpl); some entries appear only post-build.
&& for entry in openloops openloops.cfg.tmpl scons SConstruct \
lib pyol lib_src include scons-local config examples; do \
if [ -e "$entry" ]; then cp -r "$entry" /opt/openloops/; fi; \
done \
&& chmod +x /opt/openloops/openloops /opt/openloops/scons \
&& mkdir -p /opt/openloops/proclib
# Bundle a curated process pack covering the major LHC analyses + Path-A EW NLO:
# ppllj — Drell-Yan + jet (QCD NLO)
# pptt — top pair (NLO QCD)
# pph — gluon-fusion Higgs (loop-induced)
# eell_ew — e+e-→l+l- with EW NLO (Path-A finite virtual)
# eella_ew — e+e-→l+l-+γ with EW NLO (Path-A real-photon emission)
# Each ~50-100 MB compiled. Other libraries (pphtt, ppvv, pphjj, pphh, ppllj_ew)
# are user-installed on demand via `feynman install-process <name>`.
RUN cd /opt/openloops \
&& for proc in ppllj pptt pph eell_ew eella_ew; do \
(./openloops libinstall "$proc" \
&& echo "$proc bundled") \
|| echo "WARNING: $proc download failed during build; install via feynman install-process $proc"; \
done
# ─── Production image ────────────────────────────────────────────────────────
FROM python:3.11-slim
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PORT=10000
WORKDIR /app
# LaTeX + SVG rendering stack.
# texlive-science ships tikz-feynman on Debian 12 (Bookworm).
# texlive-plain-generic provides many .sty files required by standalone.
# texlive-fonts-recommended prevents missing font warnings that abort lualatex.
RUN apt-get update && apt-get install -y --no-install-recommends \
pdf2svg \
texlive-luatex \
texlive-pictures \
texlive-latex-extra \
texlive-science \
texlive-fonts-recommended \
texlive-plain-generic \
libgfortran5 \
&& rm -rf /var/lib/apt/lists/*
# Install Python deps before copying app code so this layer is cached
# across code-only changes.
COPY pyproject.toml README.md ./
COPY feynman_engine/ ./feynman_engine/
RUN pip install --upgrade pip && pip install --no-cache-dir .
# Copy remaining sources (frontend, contrib, tests, etc.)
COPY . .
# Drop in the Linux QGRAF binary compiled in the builder stage.
# (The bin/ directory may contain a macOS binary from development — overwrite it.)
COPY --from=qgraf-builder /build/out/qgraf ./bin/qgraf
RUN chmod +x ./bin/qgraf \
&& { [ -f ./bin/qgraf_pipe ] && chmod +x ./bin/qgraf_pipe || true; }
# Drop in the Linux LoopTools shared library compiled in the builder stage.
COPY --from=looptools-builder /build/liblooptools.so ./bin/liblooptools.so
# Drop in the Linux FORM binary compiled in the builder stage.
COPY --from=form-builder /build/form ./bin/form
RUN chmod +x ./bin/form
# Drop in the LHAPDF install + default PDF set from the builder stage.
# feynman_engine.amplitudes.pdf auto-discovers /opt/lhapdf and configures
# sys.path + LHAPDF_DATA_PATH + LD_LIBRARY_PATH at module import — no env
# vars needed. Also probe /tmp/lhapdf-install (legacy/dev location).
COPY --from=lhapdf-builder /opt/lhapdf /opt/lhapdf
# Drop in the OpenLoops install + bundled textbook + lhc + ee-future process
# libraries (ppllj, pptt, pph, eell_ew, eella_ew) from the builder stage.
# feynman_engine.amplitudes.openloops_bridge auto-discovers /opt/openloops at
# import. We need libgfortran5 (already installed above) for the Fortran
# shared libraries to load.
COPY --from=openloops-builder /opt/openloops /opt/openloops
ENV LHAPDF_DATA_PATH=/opt/lhapdf/share/LHAPDF \
LD_LIBRARY_PATH=/opt/lhapdf/lib:/opt/openloops/lib:/opt/openloops/proclib \
PYTHONPATH=/opt/lhapdf/lib/python3.11/site-packages:/opt/openloops/pyol/tools \
OPENLOOPS_PREFIX=/opt/openloops
EXPOSE ${PORT:-10000}
CMD ["sh", "-c", "uvicorn feynman_engine.api.app:app --host 0.0.0.0 --port ${PORT:-10000}"]