Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/bundle_with_dakota_caller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ env:
ERT_SHOW_BACKTRACE: 1
NO_PROJECT_RES: 1
BOOST_VERSION: 1.87.0
DAKOTA_VERSION: 6.21.0
DAKOTA_VERSION: 6.23.0
INSTALL_DIR: local
NEEDS_REBUILD: true

Expand Down
9 changes: 0 additions & 9 deletions .github/workflows/bundle_with_dakota_macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,8 @@ jobs:

cd dakota-${{ inputs.DAKOTA_VERSION }}-public-src-cli

patch -p1 < $CAROLINA_DIR/dakota_manylinux_install_files/workdirhelper_boost_filesystem.patch
patch -p1 < $CAROLINA_DIR/dakota_manylinux_install_files/CMakeLists_includes.patch

# Fix JEGA keyed_registry.hpp.inl bug (upstream fix: dakota-packages commit b837a87)
JEGA_KEYED_REG=$(find . -path '*/JEGA/eddy/utilities/include/inline/keyed_registry.hpp.inl')
if [ -n "$JEGA_KEYED_REG" ]; then
echo "Applying JEGA keyed_registry fix to $JEGA_KEYED_REG ..."
sed -i '' 's/const KeyType& value/const KeyType\& key/' "$JEGA_KEYED_REG"
sed -i '' 's/this->find(this->key)/this->find(key)/' "$JEGA_KEYED_REG"
fi

PYTHON_INCLUDE_DIR="$(python -c "from sysconfig import get_paths as gp; g=gp(); print(f\"{g['include']} \")")"

mkdir -p build
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![PyPI version](https://img.shields.io/pypi/v/Carolina)](https://badge.fury.io/py/carolina)
[![Platform](https://img.shields.io/badge/platform-macos%20%7C%20linux-lightgrey)](https://img.shields.io/badge/platform-macos%20%7C%20linux-lightgrey)

Carolina is a [pyDAKOTA](https://github.com/wisdem/pyDAKOTA) fork maintained by Equinor. Its raison d'être is to have easier building of a Python [Dakota](https://dakota.sandia.gov/) wrapper, without any MPI support. Carolina supports Python version 3.11, 3.12
Carolina is a [pyDAKOTA](https://github.com/wisdem/pyDAKOTA) fork maintained by Equinor. Its raison d'être is to have easier building of a Python [Dakota](https://dakota.sandia.gov/) wrapper, without any MPI support. Carolina supports Python version 3.11, 3.12, 3.13 and 3.14.

## Installation
For Linux and MacOS:
Expand Down
21 changes: 3 additions & 18 deletions dakota_manylinux_install_files/build_deps_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fi
PYTHON_VERSION_ARG="$1"

BOOST_VERSION="1.87.0"
DAKOTA_VERSION="6.21.0"
DAKOTA_VERSION="6.23.0"

cd /tmp
INSTALL_DIR=/tmp/INSTALL_DIR
Expand Down Expand Up @@ -103,24 +103,8 @@ cd "dakota-${DAKOTA_VERSION}-public-src-cli"

echo "Applying patches ..."
patch -p1 < "$CAROLINA_DIR/dakota_manylinux_install_files/CMakeLists.txt.patch"
patch -p1 < "$CAROLINA_DIR/dakota_manylinux_install_files/DakotaFindPython.cmake.patch"
patch -p1 < "$CAROLINA_DIR/dakota_manylinux_install_files/workdirhelper_boost_filesystem.patch"
patch -p1 < "$CAROLINA_DIR/dakota_manylinux_install_files/CMakeLists_includes.patch"

# FIX: GCC 14 no longer transitively provides std::uint32_t etc. via <string>.
# Trilinos's Teuchos_BigUIntDecl.hpp needs an explicit #include <cstdint>.
echo "Applying GCC 14 compatibility fix (cstdint) ..."
sed -i '/#ifndef TEUCHOS_BIG_UINT_DECL_HPP/a #include <cstdint>' \
packages/external/trilinos/packages/teuchos/core/src/Teuchos_BigUIntDecl.hpp

# Fix JEGA keyed_registry.hpp.inl bug (upstream fix: dakota-packages commit b837a87)
JEGA_KEYED_REG=$(find . -path '*/JEGA/eddy/utilities/include/inline/keyed_registry.hpp.inl')
if [ -n "$JEGA_KEYED_REG" ]; then
echo "Applying JEGA keyed_registry fix to $JEGA_KEYED_REG ..."
sed -i 's/const KeyType& value/const KeyType\& key/' "$JEGA_KEYED_REG"
sed -i 's/this->find(this->key)/this->find(key)/' "$JEGA_KEYED_REG"
fi

mkdir build
cd build

Expand Down Expand Up @@ -153,7 +137,7 @@ echo "export CMAKE_LIBRARY_PATH=\"$CMAKE_LIBRARY_PATH\"" >> "$WORKSPACE/trace/en
echo "export PYTHON_LIBRARIES=\"$PYTHON_LIBRARIES\"" >> "$WORKSPACE/trace/env"
echo "export PYTHON_INCLUDE_DIR=\"$PYTHON_INCLUDE_DIR\"" >> "$WORKSPACE/trace/env"

echo "Boostrapping Dakota ..."
echo "Bootstrapping Dakota ..."
cmake \
-DCMAKE_CXX_STANDARD=17 \
-DBUILD_SHARED_LIBS=ON \
Expand All @@ -167,6 +151,7 @@ cmake \
-DCMAKE_BUILD_TYPE="Release" \
-DDAKOTA_NO_FIND_TRILINOS:BOOL=TRUE \
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
-DCMAKE_INSTALL_LIBDIR=lib \
-DPYTHON_LIBRARIES="$PYTHON_LIBRARIES" \
-DCMAKE_EXE_LINKER_FLAGS="-L${PYTHON_LIBRARIES} -lpython${PYTHON_VERSION_ARG} -lpthread" \
-DTHREADS_PREFER_PTHREAD_FLAG=ON \
Expand Down
17 changes: 1 addition & 16 deletions dakota_manylinux_install_files/build_deps_gha.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,8 @@ cd "dakota-${DAKOTA_VERSION}-public-src-cli"

echo "Applying patches ..."
patch -p1 < "$CAROLINA_DIR/dakota_manylinux_install_files/CMakeLists.txt.patch"
patch -p1 < "$CAROLINA_DIR/dakota_manylinux_install_files/DakotaFindPython.cmake.patch"
patch -p1 < "$CAROLINA_DIR/dakota_manylinux_install_files/workdirhelper_boost_filesystem.patch"
patch -p1 < "$CAROLINA_DIR/dakota_manylinux_install_files/CMakeLists_includes.patch"

# FIX: GCC 14 no longer transitively provides std::uint32_t etc. via <string>.
# Trilinos's Teuchos_BigUIntDecl.hpp needs an explicit #include <cstdint>.
echo "Applying GCC 14 compatibility fix (cstdint) ..."
sed -i '/#ifndef TEUCHOS_BIG_UINT_DECL_HPP/a #include <cstdint>' \
packages/external/trilinos/packages/teuchos/core/src/Teuchos_BigUIntDecl.hpp

# Fix JEGA keyed_registry.hpp.inl bug (upstream fix: dakota-packages commit b837a87)
JEGA_KEYED_REG=$(find . -path '*/JEGA/eddy/utilities/include/inline/keyed_registry.hpp.inl')
if [ -n "$JEGA_KEYED_REG" ]; then
echo "Applying JEGA keyed_registry fix to $JEGA_KEYED_REG ..."
sed -i 's/const KeyType& value/const KeyType\& key/' "$JEGA_KEYED_REG"
sed -i 's/this->find(this->key)/this->find(key)/' "$JEGA_KEYED_REG"
fi

mkdir build
cd build

Expand Down Expand Up @@ -148,6 +132,7 @@ cmake \
-DCMAKE_BUILD_TYPE="Release" \
-DDAKOTA_NO_FIND_TRILINOS:BOOL=TRUE \
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
-DCMAKE_INSTALL_LIBDIR=lib \
-DPYTHON_LIBRARIES="$PYTHON_LIBRARIES" \
-DCMAKE_EXE_LINKER_FLAGS="-L${PYTHON_LIBRARIES} -lpython${PYTHON_VERSION_ARG} -lpthread" \
-DTHREADS_PREFER_PTHREAD_FLAG=ON \
Expand Down
11 changes: 1 addition & 10 deletions script/build_boost_dakota.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -eu


BOOST_VERSION="1.87.0"
DAKOTA_VERSION="6.21.0"
DAKOTA_VERSION="6.23.0"

BOOST_VER_NODOTS=$(echo "$BOOST_VERSION" | sed 's/\./_/g')

Expand Down Expand Up @@ -115,17 +115,8 @@ tar xf "$CACHE_DIR"/$dakota_file

cd "dakota-${DAKOTA_VERSION}-public-src-cli"

patch -p1 < ../../../dakota_manylinux_install_files/workdirhelper_boost_filesystem.patch
patch -p1 < ../../../dakota_manylinux_install_files/CMakeLists_includes.patch

# Fix JEGA keyed_registry.hpp.inl bug (upstream fix: dakota-packages commit b837a87)
JEGA_KEYED_REG=$(find . -path '*/JEGA/eddy/utilities/include/inline/keyed_registry.hpp.inl')
if [ -n "$JEGA_KEYED_REG" ]; then
echo "Applying JEGA keyed_registry fix to $JEGA_KEYED_REG ..."
sed -i '' 's/const KeyType& value/const KeyType\& key/' "$JEGA_KEYED_REG"
sed -i '' 's/this->find(this->key)/this->find(key)/' "$JEGA_KEYED_REG"
fi

mkdir -p build
cd build

Expand Down
99 changes: 57 additions & 42 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import platform
import sys
import shutil
from pathlib import Path

import numpy

Expand All @@ -19,7 +20,7 @@

DAKOTA_EXEC = shutil.which("dakota")
if not DAKOTA_EXEC:
exit('Unable to find dakota executable.')
sys.exit("Unable to find dakota executable.")


def get_default_boost_python():
Expand All @@ -34,42 +35,49 @@ def get_numpy_include():
def find_dakota_paths():
"""Assuming standard prefix-based install."""
dakota_install = os.path.dirname(os.path.dirname(DAKOTA_EXEC))
dakota_bin = os.path.join(dakota_install, 'bin')
dakota_include = os.path.join(dakota_install, 'include')
dakota_lib = os.path.join(dakota_install, 'lib')
eigen_include = os.path.join(dakota_include, 'eigen3')
dakota_bin = os.path.join(dakota_install, "bin")
dakota_include = os.path.join(dakota_install, "include")
dakota_lib = os.path.join(dakota_install, "lib")
eigen_include = os.path.join(dakota_include, "eigen3")
req = (dakota_bin, dakota_include, dakota_lib)
if not all(map(os.path.exists, req)):
exit("Can't find %s or %s or %s, bummer" % req)
sys.exit("Can't find %s or %s or %s, bummer" % req)
return dakota_install, dakota_bin, dakota_include, dakota_lib, eigen_include


def read_dakota_macros(install_path):
"""Read make macros from `install_path`/include/Makefile.export.Dakota."""
dakota_macros = {}
with open(os.path.join(install_path, 'include',
'Makefile.export.Dakota'), 'r') as inp:
with open(
os.path.join(install_path, "include", "Makefile.export.Dakota"), "r"
) as inp:
for line in inp:
line = line.strip()
if not line or line.startswith('#'):
if not line or line.startswith("#"):
continue
name, _, value = line.partition('=')
name, _, value = line.partition("=")
dakota_macros[name.strip()] = value.strip().split()
return dakota_macros


def get_dakota_libs(macros):
"""Drop '-l' from Dakota_LIBRARIES if necessary."""
libs = macros['Dakota_LIBRARIES']
libs = [name[2:] if name.startswith('-l') else name for name in libs]
"""Drop '-l' from Dakota_LIBRARIES if necessary.

Also strip CMake namespace prefixes
(e.g. 'TeuchosCore::teuchoscore' -> 'teuchoscore')
"""
libs = macros["Dakota_LIBRARIES"]
libs = [name[2:] if name.startswith("-l") else name for name in libs]
libs = [name.split("::")[-1] if "::" in name else name for name in libs]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only significant change in this file. Apparently some autoformatting.

return libs


def get_define_macros(macros):
"""Drop '-D' from Dakota_DEFINES."""
define_macros = [(name[2:], None) for name in macros['Dakota_DEFINES']]
define_macros = [(name[2:], None) for name in macros["Dakota_DEFINES"]]
return define_macros


def get_boost_inc_lib():
"""BOOST_ROOT is expected to be set if a certain boost build is required.

Expand All @@ -79,35 +87,36 @@ def get_boost_inc_lib():

"""

boost_root = os.getenv('BOOST_ROOT', None)
boost_root = os.getenv("BOOST_ROOT", None)

boost_inc_dir = None
boost_lib_dir = None
if boost_root:
boost_inc_dir = os.path.join(boost_root, 'include')
boost_lib_dir = os.path.join(boost_root, 'lib')
boost_inc_dir = os.path.join(boost_root, "include")
boost_lib_dir = os.path.join(boost_root, "lib")

boost_python = os.getenv('BOOST_PYTHON', get_default_boost_python())
boost_python = os.getenv("BOOST_PYTHON", get_default_boost_python())

if not boost_lib_dir:
return boost_inc_dir, None, None, boost_python

return boost_inc_dir, boost_lib_dir, boost_lib_dir+'64', boost_python
return boost_inc_dir, boost_lib_dir, boost_lib_dir + "64", boost_python


def get_macros_include_library():
"""Get the dakota macros, include and library dirs."""
dakota_install, dakota_bin, dakota_include, dakota_lib, eigen_include = find_dakota_paths()
dakota_install, dakota_bin, dakota_include, dakota_lib, eigen_include = (
find_dakota_paths()
)
dakota_macros = read_dakota_macros(dakota_install)

inc = [dakota_include, eigen_include, get_numpy_include()]
lib = [dakota_lib, dakota_bin]
return dakota_macros, inc, lib

def get_carolina_extension():
"""Setup everything and make an Extension for Carolina!

"""
def get_carolina_extension():
"""Setup everything and make an Extension for Carolina!"""

dakota_macros, include_dirs, library_dirs = get_macros_include_library()

Expand All @@ -118,12 +127,16 @@ def get_carolina_extension():
library_dirs.append(boost_lib)
library_dirs.append(boost_lib64)

sources = ["src/dakface.cpp", "src/dakota_python_binding.cpp"]

sources = ['src/dakface.cpp', 'src/dakota_python_binding.cpp']


external_libs = ['boost_regex', 'boost_filesystem', 'boost_serialization',
'boost_system', 'boost_program_options', boost_python]
external_libs = [
"boost_regex",
"boost_filesystem",
"boost_serialization",
"boost_system",
"boost_program_options",
boost_python,
]

print(boost_python)

Expand All @@ -134,19 +147,21 @@ def get_carolina_extension():

if "Darwin" in platform.system():
# Reserve header space for install_name_tool rewrites by delocate
extra_link_args = ['-Wl,-headerpad_max_install_names']
extra_link_args = ["-Wl,-headerpad_max_install_names"]
else:
extra_link_args = ['-Wl,-z,origin']

carolina = Extension(name='carolina',
sources=sources,
include_dirs=include_dirs,
define_macros=define_macros,
extra_link_args=extra_link_args,
extra_compile_args=['-std=c++17'],
library_dirs=library_dirs,
libraries=libraries,
language='c++')
extra_link_args = ["-Wl,-z,origin"]

carolina = Extension(
name="carolina",
sources=sources,
include_dirs=include_dirs,
define_macros=define_macros,
extra_link_args=extra_link_args,
extra_compile_args=["-std=c++17"],
library_dirs=library_dirs,
libraries=libraries,
language="c++",
)
return carolina


Expand All @@ -155,8 +170,8 @@ def get_carolina_extension():
setup(
name="carolina",
description="A Python wrapper for DAKOTA",
long_description=open('README.md').read(),
long_description_content_type='text/markdown',
long_description=Path("README.md").read_text(encoding="utf-8"),
long_description_content_type="text/markdown",
Comment thread
larsevj marked this conversation as resolved.
py_modules=["dakota"],
ext_modules=[CAROLINA],
package_dir={"": "src"},
Expand Down
Loading