Files
ocp/scripts/_env.sh
stroblme 4bb4805ccb n3xd_ocp.measure: every face's area and centroid in one call
BRepGProp.SurfaceProperties is the hottest kernel call the app makes — 94 % of
face_candidate_anchors, 0.99 s of 1.05 s for 690 faces — not because the kernel
is slow but because it is reached once per face from Python, so a rebuild pays
the round-trip hundreds of times per feature over a growing shape.

face_surface_props(shape, *, parallel=True, eps=None) runs the whole scan
C++-side with the GIL released, optionally over OSD_Parallel, and returns
(areas[F], centroids[F,3]) in MapShapes(FACE) order — the face identity the
topology layer already keys on, so a caller indexes straight into it. A face
OCCT cannot integrate reports zeros, matching what the app's own try/except
substitutes.

Tested against the same stock-recorded per-face reference the Inc 1 gate uses,
and against the one-call-per-face loop it replaces. Parallel and serial are
compared with array_equal rather than approx: the parallel path shares one
TopoDS_Shape across threads, so an exact match is the evidence that nothing
reachable from it gets mutated while measuring.

Backend adoption comes after the cutover, so this changes nothing yet.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DfriM8XUkn7uYf5Dwe2xo6
2026-08-10 20:37:01 +02:00

31 lines
1.2 KiB
Bash
Executable File

# Shared environment for the in-container scripts. Sourced, not executed.
#
# Everything expensive or bulky (ccache, the CMake tree, pip's cache, the build
# venv) lives under $CACHE, which the Makefile bind-mounts from outside the
# repo — the root filesystem on this host has little headroom, and these
# survive between runs to keep the inner loop incremental.
CACHE="${CACHE_ROOT:-/cache}"
export CCACHE_DIR="$CACHE/ccache"
export PIP_CACHE_DIR="$CACHE/pip"
export HOME="$CACHE" # containers run as the host uid; /root is not ours
export CMAKE_C_COMPILER_LAUNCHER=ccache
export CMAKE_CXX_COMPILER_LAUNCHER=ccache
export CMAKE_PREFIX_PATH=/opt/occt
export LD_LIBRARY_PATH=/opt/occt/lib
export SKBUILD_BUILD_DIR="$CACHE/skbuild/{wheel_tag}"
mkdir -p "$CCACHE_DIR" "$PIP_CACHE_DIR"
VENV="$CACHE/venv"
if [ ! -x "$VENV/bin/python" ]; then
echo "--- creating build venv at $VENV ---"
/opt/python/cp312-cp312/bin/python -m venv "$VENV"
"$VENV/bin/pip" install -q --upgrade pip
# numpy is a test dependency only: the n3xd_ocp bulk APIs hand back
# ndarrays, so their tests need it to check the results.
"$VENV/bin/pip" install -q build nanobind scikit-build-core pytest numpy
fi
PY="$VENV/bin/python"
export PY VENV CACHE