A grunk plugin that exposes
ADOL-C's tapeless adouble algorithmic
differentiation (AD) type as a native adolc.adouble Lua usertype: a value can flow
through a grunk recipe (dependency tracking, lazy evaluation, YAML serialization)
and still carry its AD derivative. Its C++ type is shared with any other native
grunk plugin that also names adtl::adouble - grunk-occt's own AD-enabled build
is one - so a derivative can flow straight through a mixed computation without any
conversion at the boundary. See DESIGN.md for how this repo relates to
grunk-occt and the design rationale behind the native-binding approach.
src/adolc_plugin.cpp is a thin entry point; generated/adouble.cpp (ADOL-C's
entire practically-relevant API, generated by grunk's own grunk.codegen - see
codegen/config.yml) is where almost everything actually is.
- CMake >= 3.15
- C++17 compiler
- Autotools (
autoreconf/automake/libtool) - needed to build ADOL-C itself below; not needed for anything else in this repo - pixi
pixi install
pixi run install_adolcDownloads, builds, and installs ADOL-C 2.7.2 into .deps/adolc (deliberately
outside the CMake build directory - see scripts/install_adolc.sh's own comment
for why: a routine rm -rf build must never force rebuilding ADOL-C from
scratch too) via scripts/install_adolc.sh - idempotent, safe to re-run. Needs
autoreconf/automake/libtool on PATH.
What this does, if you'd rather run it by hand (or it fails partway)
mkdir -p build/_deps && cd build/_deps
git clone https://github.com/coin-or/ADOL-C.git
cd ADOL-C
git checkout releases/2.7.2
mkdir -p ../../.deps/adolc
export ADOLC_PREFIX="$(cd ../../.deps/adolc && pwd)"
autoreconf -fi
./configure --prefix="$ADOLC_PREFIX" --enable-atrig-erf --with-boost=no
make -j
make install
cd ../../.. # back to this repo's own rootWhere ADOL-C actually installs its library (lib vs. lib64) depends on your
distro's own autotools defaults - CMakeLists.txt's own pkg_check_modules call
finds it either way (via adolc.pc), but if you ever need to know for the runtime
note below: ls "$ADOLC_PREFIX"/lib*.
Runtime note: adolc_plugin.so links directly against ADOL-C's own shared
library (libadolc.so, in .deps/adolc/lib or lib64) at runtime, not just at
link time - skipping this fails the plugin's dlopen outright with a "cannot open
shared object file: libadolc.so" error. pixi.toml already sets
LD_LIBRARY_PATH/PKG_CONFIG_PATH for every pixi run task
($PIXI_PROJECT_ROOT-based, see its own comment there) covering this exact
install path - nothing further to do for any pixi run task below. Installed
ADOL-C somewhere else, or running run_example.py/runUnitTests directly rather
than through pixi run? Export both yourself first:
export LD_LIBRARY_PATH="$ADOLC_PREFIX/lib64:$LD_LIBRARY_PATH" # or lib
export PKG_CONFIG_PATH="$ADOLC_PREFIX/lib64/pkgconfig:$PKG_CONFIG_PATH" # or libpixi run allOr step by step:
pixi run install_adolc # build/install ADOL-C, if not already done
pixi run install_grunk # build/install grunk into .deps/grunk, if not already done
pixi run configure # configure the CMake build
pixi run build # build adolc_plugin and the test harness
pixi run test # run the gtest suite (tests/test_load.cpp, tests/test_recipe.cpp)
pixi run run_examples # run examples/run_example.py against the built plugin
pixi run install # install adolc_plugin into build/install (see "Packaging / installing" below)
pixi run generate_code # regenerate generated/adouble.cpp from ADOL-C's own header
# (requires -D GRUNK_ADOLC_GENERATE_CODE=ON at configure time)install_adolc/install_grunk both also run automatically as part of configure (and hence
build/test/etc.) via its own dependency chain - spelled out above for visibility, and because
pixi run all runs them that way regardless. adolc_plugin links grunk dynamically (find_package (grunk) against .deps/grunk, not a vendored copy) - see DESIGN.md for why.
adolc_plugin is a runtime-loaded grunk plugin - a consuming application never links against it,
it dlopens it by path via grunk::plugin::load_native (matches grunk-occt's own occt_plugin -
see its README's identical section). So there's no CMake package config to find_package() here,
just the built shared library itself:
pixi run install # -> build/install/lib/libadolc_plugin.so
Point grunk::plugin::load_native (or its Python equivalent) at the installed path instead of a
path under build/ directly once you're consuming this outside the build tree - examples//
tests/ in this repo itself still reference the build tree directly, since they're meant to run
right after build, not install. CMAKE_INSTALL_PREFIX (set by the configure task,
build/install) can be overridden - either edit pixi.toml's own configure task, or run
cmake --install build --prefix <path> yourself.
libadolc_plugin.so itself dynamically links grunk's own shared libraries (.deps/grunk, an
absolute path baked in at build time - see DESIGN.md's "grunk: pre-built dependency, not
vendored") - loading it from a machine/directory that doesn't have that same .deps/grunk install
present needs grunk's own shared libraries reachable another way (e.g. LD_LIBRARY_PATH, or a
pixi run install_grunk of your own pointed at the same path) until this plugin ships as a real,
independently relocatable binary package.
When consumed via grunk-occt's own GRUNK_OCCT_ENABLE_AD build (FetchContent, pinned to a
specific commit), grunk-occt's own pixi run -e ad install picks this up too - see grunk-occt's
own DESIGN.md, "Packaging", for the details.
examples/test_adolc.grr.yml is a small, self-contained recipe (uses: adolc: 2.7.2, a recipe-local modules: block for its own me.seed helper - no external
plugin/module dependency beyond adolc itself) computing w = adolc.sin((x * y) * 6) with x seeded for forward-mode AD from a parameter. examples/run_example.py
loads the plugin, overrides the seed parameter, and checks both the resulting
value and derivative against the closed form (sin(102*x_val),
102*cos(102*x_val)) - see its own doc comment.
| Dependency | Source |
|---|---|
| ADOL-C | GitHub, built from source (pixi run install_adolc) |
| grunk | pinned commit, built and installed automatically into .deps/grunk (scripts/install_grunk.cmake); also provides the grunk Python package (the grunk codegen CLI, and its own libclang/pyyaml dependencies), needed only for codegen/ (opt-in) |
| libparametric, yaml-cpp, sol2, lua, taskflow, pkg-config | conda-forge |