From e9101ab57f9fb4ab076ff9eb2a3b5e85aaafc21b Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Fri, 19 Jul 2024 01:25:36 +0100 Subject: [PATCH 01/29] draft scikit build core wheel --- CMakeLists.txt | 10 ++++++++++ openmc/__init__.py | 1 + openmc/openmc_exec.py | 22 ++++++++++++++++++++++ pyproject.toml | 9 ++++++++- setup.py | 11 +++++++++-- 5 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 openmc/openmc_exec.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f4cc1b527b..d7fa6cb2a2f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,11 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) # Set module path set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules) +# Conditionally find Python if building with scikit-build-core +if(SKBUILD) + find_package(Python COMPONENTS Interpreter Development.Module REQUIRED) +endif() + # Enable correct usage of CXX_EXTENSIONS if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.22) cmake_policy(SET CMP0128 NEW) @@ -614,3 +619,8 @@ install(FILES man/man1/openmc.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) install(FILES LICENSE DESTINATION "${CMAKE_INSTALL_DOCDIR}" RENAME copyright) install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) install(FILES "${CMAKE_BINARY_DIR}/include/openmc/version.h" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/openmc) + +if(SKBUILD) + install(TARGETS openmc RUNTIME DESTINATION openmc/bin) + install(TARGETS libopenmc LIBRARY DESTINATION openmc/lib) +endif() diff --git a/openmc/__init__.py b/openmc/__init__.py index 566d287068f..32320365d58 100644 --- a/openmc/__init__.py +++ b/openmc/__init__.py @@ -34,6 +34,7 @@ from openmc.polynomial import * from openmc.tracks import * from .config import * +from .openmc_exec import main # Import a few names from the model module from openmc.model import Model diff --git a/openmc/openmc_exec.py b/openmc/openmc_exec.py new file mode 100644 index 00000000000..72cd283beff --- /dev/null +++ b/openmc/openmc_exec.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python3 + +# helper script that launches the openmc binary + +import os +import sys +import sysconfig +from pathlib import Path + + +def main(): + lib_path = sysconfig.get_path("platlib") + "openmc/lib/openmc" + os.environ["LD_LIBRARY_PATH"] = ( + lib_path + ":" + os.environ.get("LD_LIBRARY_PATH", "") + ) + os.execv( + Path(sysconfig.get_path("platlib")) / "openmc" / "bin" / "openmc", sys.argv + ) + + +if __name__ == "__main__": + main() diff --git a/pyproject.toml b/pyproject.toml index d1b2c335cd7..08bc9ad1313 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,6 @@ [build-system] -requires = ["setuptools", "wheel", "numpy", "cython"] +requires = ["setuptools", "wheel", "numpy", "cython", "scikit-build-core"] +build-backend = "scikit_build_core.build" [project] name = "openmc" @@ -72,3 +73,9 @@ openmc-track-to-vtk = "scripts.openmc_track_to_vtk:main" openmc-update-inputs = "scripts.openmc_update_inputs:main" openmc-update-mgxs = "scripts.openmc_update_mgxs:main" openmc-voxel-to-vtk = "scripts.openmc_voxel_to_vtk:main" +openmc-exec = "openmc.openmc_exec:main" + +[tool.scikit-build] +cmake.verbose = true +# cmake args can be passed in here or in the command line via exports or inline with the pip install +cmake.args = ["-DCMAKE_BUILD_TYPE=RELEASE"] \ No newline at end of file diff --git a/setup.py b/setup.py index 4e24f48a123..32cf2483ce0 100755 --- a/setup.py +++ b/setup.py @@ -1,13 +1,20 @@ #!/usr/bin/env python +import os import numpy as np -from setuptools import setup +from setuptools import setup, Extension from Cython.Build import cythonize +class OpenMCExtension(Extension): + def __init__(self, name, cmake_lists_dir=".", sources=[], **kwa): + Extension.__init__(self, name, sources=sources, **kwa) + self.cmake_lists_dir = os.path.abspath(cmake_lists_dir) + + kwargs = { # Cython is used to add resonance reconstruction and fast float_endf - 'ext_modules': cythonize('openmc/data/*.pyx'), + 'ext_modules': cythonize('openmc/data/*.pyx') + [OpenMCExtension('libopenmc')], 'include_dirs': [np.get_include()] } From e857f4529cd8833c475ee1cecbf6af7e48a61493 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Fri, 19 Jul 2024 01:31:11 +0100 Subject: [PATCH 02/29] renamed executable --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 08bc9ad1313..69090111b33 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -73,7 +73,7 @@ openmc-track-to-vtk = "scripts.openmc_track_to_vtk:main" openmc-update-inputs = "scripts.openmc_update_inputs:main" openmc-update-mgxs = "scripts.openmc_update_mgxs:main" openmc-voxel-to-vtk = "scripts.openmc_voxel_to_vtk:main" -openmc-exec = "openmc.openmc_exec:main" +openmc = "openmc.openmc_exec:main" [tool.scikit-build] cmake.verbose = true From 61b7035681230cb0c94e8b819584ee104873faed Mon Sep 17 00:00:00 2001 From: Jon Shimwell Date: Fri, 19 Jul 2024 10:02:52 +0100 Subject: [PATCH 03/29] linking libopenmc with openmc in cmakelists --- CMakeLists.txt | 7 ++++++- openmc/openmc_exec.py | 4 ---- pyproject.toml | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d7fa6cb2a2f..7c86c391521 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -332,6 +332,11 @@ if("${isSystemDir}" STREQUAL "-1") set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}") endif() +if(SKBUILD) + set(CMAKE_INSTALL_RPATH "$ORIGIN") + set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) +endif() + #=============================================================================== # libopenmc #=============================================================================== @@ -622,5 +627,5 @@ install(FILES "${CMAKE_BINARY_DIR}/include/openmc/version.h" DESTINATION ${CMAKE if(SKBUILD) install(TARGETS openmc RUNTIME DESTINATION openmc/bin) - install(TARGETS libopenmc LIBRARY DESTINATION openmc/lib) + install(TARGETS libopenmc LIBRARY DESTINATION openmc/bin) endif() diff --git a/openmc/openmc_exec.py b/openmc/openmc_exec.py index 72cd283beff..579eeced24f 100644 --- a/openmc/openmc_exec.py +++ b/openmc/openmc_exec.py @@ -9,10 +9,6 @@ def main(): - lib_path = sysconfig.get_path("platlib") + "openmc/lib/openmc" - os.environ["LD_LIBRARY_PATH"] = ( - lib_path + ":" + os.environ.get("LD_LIBRARY_PATH", "") - ) os.execv( Path(sysconfig.get_path("platlib")) / "openmc" / "bin" / "openmc", sys.argv ) diff --git a/pyproject.toml b/pyproject.toml index 08bc9ad1313..c236b968035 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -73,9 +73,9 @@ openmc-track-to-vtk = "scripts.openmc_track_to_vtk:main" openmc-update-inputs = "scripts.openmc_update_inputs:main" openmc-update-mgxs = "scripts.openmc_update_mgxs:main" openmc-voxel-to-vtk = "scripts.openmc_voxel_to_vtk:main" -openmc-exec = "openmc.openmc_exec:main" +openmc = "openmc.openmc_exec:main" [tool.scikit-build] cmake.verbose = true # cmake args can be passed in here or in the command line via exports or inline with the pip install -cmake.args = ["-DCMAKE_BUILD_TYPE=RELEASE"] \ No newline at end of file +cmake.args = ["-DCMAKE_BUILD_TYPE=RELEASE"] From 2541d50e557653ba6dc17e70c47db8431edc72a4 Mon Sep 17 00:00:00 2001 From: Jon Shimwell Date: Sat, 20 Jul 2024 00:08:42 +0100 Subject: [PATCH 04/29] updated docs for pip install that compiles --- docs/source/quickinstall.rst | 25 ++++++------------ docs/source/usersguide/install.rst | 42 +++++++++++++++++++++++------- 2 files changed, 40 insertions(+), 27 deletions(-) diff --git a/docs/source/quickinstall.rst b/docs/source/quickinstall.rst index 7f222f77cb8..3e0778a9eca 100644 --- a/docs/source/quickinstall.rst +++ b/docs/source/quickinstall.rst @@ -160,28 +160,19 @@ download and install OpenMC by entering the following commands in a terminal: git clone --recurse-submodules https://github.com/openmc-dev/openmc.git cd openmc - mkdir build && cd build - cmake .. - make - sudo make install + python -m pip install . -This will build an executable named ``openmc`` and install it (by default in -/usr/local/bin). If you do not have administrator privileges, the cmake command -should specify an installation directory where you have write access, e.g. +The easiest way to install it is using `pip `_. +This `pip` command will install the `openmc` Python package and compile an executable named ``openmc`` +and install it (by default in the bin folder of the Python package directory). .. code-block:: sh - cmake -DCMAKE_INSTALL_PREFIX=$HOME/.local .. - -The :mod:`openmc` Python package must be installed separately. The easiest way -to install it is using `pip `_. -From the root directory of the OpenMC repository, run: + python -m pip install . --global-option="build_ext" --global-option="--" --global-option="-DOPENMC_USE_MPI=ON" -.. code-block:: sh - - python -m pip install . +The compilion of the ``openmc`` can be customised by specifying CMake arguments. By default, OpenMC will be built with multithreading support. To build -distributed-memory parallel versions of OpenMC using MPI or to configure other -options, directions can be found in the :ref:`detailed installation instructions +distributed-memory parallel versions of OpenMC using MPI the above command can be run. +There are other options that can be set, more details can be found in the :ref:`detailed installation instructions `. diff --git a/docs/source/usersguide/install.rst b/docs/source/usersguide/install.rst index 130e96c0ae6..203ec879430 100644 --- a/docs/source/usersguide/install.rst +++ b/docs/source/usersguide/install.rst @@ -175,9 +175,9 @@ feature can be used to access the installed packages. .. _install_source: ----------------------- -Installing from Source ----------------------- +-------------------------------- +Compiling from Source with CMake +-------------------------------- .. _prerequisites: @@ -367,6 +367,8 @@ Note that first a build directory is created as a subdirectory of the source directory. The Makefile in the top-level directory will automatically perform an out-of-source build with default options. +.. _cmake_arguemnts: + CMakeLists.txt Options ++++++++++++++++++++++ @@ -505,15 +507,15 @@ To run the test suite, you will first need to download a pre-generated cross section library along with windowed multipole data. Please refer to our :ref:`devguide_tests` documentation for further details. ---------------------- -Installing Python API ---------------------- +----------------------------------------------- +Installing Python API and compiling from source +----------------------------------------------- If you installed OpenMC using :ref:`Conda `, no further steps are necessary in order to use OpenMC's :ref:`Python API `. However, if -you are :ref:`installing from source `, the Python API is not -installed by default when ``make install`` is run because in many situations it -doesn't make sense to install a Python package in the same location as the +you are :ref:`Compiling from Source with CMake `, the Python API +is not installed by default when ``make install`` is run because in many situations +it doesn't make sense to install a Python package in the same location as the ``openmc`` executable (for example, if you are installing the package into a `virtual environment `_). The easiest way to install the :mod:`openmc` Python package is to use pip_, which is @@ -527,7 +529,27 @@ distribution/repository, run: pip will first check that all :ref:`required third-party packages ` have been installed, and if they are not present, they will be installed by downloading the appropriate packages from the Python -Package Index (`PyPI `_). +Package Index (`PyPI `_). The pip command will also compile +an executable named ``openmc`` and install it (by default in the bin folder of +the Python package directory). + +Passing CMake Options to via pip +-------------------------------- + +If you need to pass CMake options to the build process, you can do so by +running pip install with some additional options. All the CMake arguments +covered in the :ref:`CMakeLists.txt Options` are supported. +For example, to build OpenMC with MPI support, you can run: + +.. code-block:: sh + + python -m pip install . --global-option="build_ext" --global-option="--" --global-option="-DOPENMC_USE_MPI=ON" + +To build OpenMC with DAGMC support two CMake arguments are needed, you can run: + +.. code-block:: sh + + python -m pip install . --global-option="build_ext" --global-option="--" --global-option="-DOPENMC_USE_DAGMC=ON" --global-option="-DDAGMC_ROOT=/path/to/dagmc/installation" Installing in "Development" Mode -------------------------------- From f15e80f00537660919b2d8ff9d8b66f65562953b Mon Sep 17 00:00:00 2001 From: Jon Shimwell Date: Tue, 23 Jul 2024 19:04:34 +0100 Subject: [PATCH 05/29] pip install with cmake args in ci --- tools/ci/gha-install.py | 33 ++++++++++++++++----------------- tools/ci/gha-install.sh | 3 --- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/tools/ci/gha-install.py b/tools/ci/gha-install.py index f4b2fbb3187..5cf46baa24c 100644 --- a/tools/ci/gha-install.py +++ b/tools/ci/gha-install.py @@ -26,48 +26,47 @@ def install(omp=False, mpi=False, phdf5=False, dagmc=False, libmesh=False, ncrys os.chdir('build') # Build in debug mode by default with support for MCPL - cmake_cmd = ['cmake', '-DCMAKE_BUILD_TYPE=Debug', '-DOPENMC_USE_MCPL=on'] + pip_command = ['pip' 'install' '.[test,vtk]'] + pip_suffix = ['--config-settings=cmake.args=-DCMAKE_BUILD_TYPE=ON;-DOPENMC_USE_MCPL=ON'] # Turn off OpenMP if specified if not omp: - cmake_cmd.append('-DOPENMC_USE_OPENMP=off') + pip_suffix.append('-DOPENMC_USE_OPENMP=off') # Use MPI wrappers when building in parallel if mpi: - cmake_cmd.append('-DOPENMC_USE_MPI=on') + pip_suffix.append('-DOPENMC_USE_MPI=on') # Tell CMake to prefer parallel HDF5 if specified if phdf5: if not mpi: raise ValueError('Parallel HDF5 must be used in ' 'conjunction with MPI.') - cmake_cmd.append('-DHDF5_PREFER_PARALLEL=ON') + pip_suffix.append('-DHDF5_PREFER_PARALLEL=ON') else: - cmake_cmd.append('-DHDF5_PREFER_PARALLEL=OFF') + pip_suffix.append('-DHDF5_PREFER_PARALLEL=OFF') if dagmc: - cmake_cmd.append('-DOPENMC_USE_DAGMC=ON') - cmake_cmd.append('-DCMAKE_PREFIX_PATH=~/DAGMC') + pip_suffix.append('-DOPENMC_USE_DAGMC=ON') + pip_suffix.append('-DCMAKE_PREFIX_PATH=~/DAGMC') if libmesh: - cmake_cmd.append('-DOPENMC_USE_LIBMESH=ON') + pip_suffix.append('-DOPENMC_USE_LIBMESH=ON') libmesh_path = os.environ.get('HOME') + '/LIBMESH' - cmake_cmd.append('-DCMAKE_PREFIX_PATH=' + libmesh_path) + pip_suffix.append('-DCMAKE_PREFIX_PATH=' + libmesh_path) if ncrystal: - cmake_cmd.append('-DOPENMC_USE_NCRYSTAL=ON') + pip_suffix.append('-DOPENMC_USE_NCRYSTAL=ON') ncrystal_cmake_path = os.environ.get('HOME') + '/ncrystal_inst/lib/cmake' - cmake_cmd.append(f'-DCMAKE_PREFIX_PATH={ncrystal_cmake_path}') + pip_suffix.append(f'-DCMAKE_PREFIX_PATH={ncrystal_cmake_path}') # Build in coverage mode for coverage testing - cmake_cmd.append('-DOPENMC_ENABLE_COVERAGE=on') + pip_suffix.append('-DOPENMC_ENABLE_COVERAGE=on') + pip_command.append(';'.join(pip_suffix)) # Build and install - cmake_cmd.append('..') - print(' '.join(cmake_cmd)) - subprocess.check_call(cmake_cmd) - subprocess.check_call(['make', '-j4']) - subprocess.check_call(['sudo', 'make', 'install']) + print(' '.join(pip_command)) + subprocess.check_call(pip_command) def main(): # Convert Travis matrix environment variables into arguments for install() diff --git a/tools/ci/gha-install.sh b/tools/ci/gha-install.sh index 2cef974d346..1673edd4ada 100755 --- a/tools/ci/gha-install.sh +++ b/tools/ci/gha-install.sh @@ -47,9 +47,6 @@ fi # Build and install OpenMC executable python tools/ci/gha-install.py -# Install Python API in editable mode -pip install -e .[test,vtk] - # For coverage testing of the C++ source files pip install cpp-coveralls From 3c98d8a8346746d1c0cd90dd60ed33c4799d5b39 Mon Sep 17 00:00:00 2001 From: Jon Shimwell Date: Tue, 23 Jul 2024 19:59:07 +0100 Subject: [PATCH 06/29] added missing , --- tools/ci/gha-install.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/ci/gha-install.py b/tools/ci/gha-install.py index 5cf46baa24c..f8c9ebe7e53 100644 --- a/tools/ci/gha-install.py +++ b/tools/ci/gha-install.py @@ -26,7 +26,7 @@ def install(omp=False, mpi=False, phdf5=False, dagmc=False, libmesh=False, ncrys os.chdir('build') # Build in debug mode by default with support for MCPL - pip_command = ['pip' 'install' '.[test,vtk]'] + pip_command = ['pip', 'install', '.[test,vtk]'] pip_suffix = ['--config-settings=cmake.args=-DCMAKE_BUILD_TYPE=ON;-DOPENMC_USE_MCPL=ON'] # Turn off OpenMP if specified From 0aafd44dda9cdaffca73e83fd42c201eec0fbae5 Mon Sep 17 00:00:00 2001 From: Jon Shimwell Date: Tue, 23 Jul 2024 20:02:44 +0100 Subject: [PATCH 07/29] no need for manual creation of build dir --- tools/ci/gha-install.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tools/ci/gha-install.py b/tools/ci/gha-install.py index f8c9ebe7e53..536df1f9377 100644 --- a/tools/ci/gha-install.py +++ b/tools/ci/gha-install.py @@ -1,5 +1,4 @@ import os -import shutil import subprocess def which(program): @@ -20,10 +19,6 @@ def is_exe(fpath): def install(omp=False, mpi=False, phdf5=False, dagmc=False, libmesh=False, ncrystal=False): - # Create build directory and change to it - shutil.rmtree('build', ignore_errors=True) - os.mkdir('build') - os.chdir('build') # Build in debug mode by default with support for MCPL pip_command = ['pip', 'install', '.[test,vtk]'] From 9ef3beb1603bd286467dccbfa13eca87f29c9bf2 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Fri, 26 Jul 2024 13:05:41 +0100 Subject: [PATCH 08/29] [skip ci] adding apt packages for read the docs --- .readthedocs.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index b7b69f9fe59..fb49db819e5 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -4,6 +4,11 @@ build: os: "ubuntu-20.04" tools: python: "3.10" + apt_package: + - g++ + - cmake + - libhdf5-dev + - libpng-dev sphinx: configuration: docs/source/conf.py From 40ceaadea68b02e6758b4ef0a66194371095456c Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Fri, 26 Jul 2024 13:17:20 +0100 Subject: [PATCH 09/29] [skip ci] trying ubuntu 22.04 --- .readthedocs.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index fb49db819e5..e5d69973b34 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -1,7 +1,7 @@ version: 2 build: - os: "ubuntu-20.04" + os: "ubuntu-22.04" tools: python: "3.10" apt_package: From 2c8cf714a716d77bcf9363d4e93abd73bb93defa Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Fri, 26 Jul 2024 13:18:08 +0100 Subject: [PATCH 10/29] [skip ci] added missing s --- .readthedocs.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index e5d69973b34..bcbea55994e 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -4,7 +4,7 @@ build: os: "ubuntu-22.04" tools: python: "3.10" - apt_package: + apt_packages: - g++ - cmake - libhdf5-dev From 4c0075f0f3fdb7562beff590a71de2da7ad0f9d7 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Fri, 26 Jul 2024 17:52:37 +0100 Subject: [PATCH 11/29] adding gha actions --- .github/workflows/ci.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9293e319b42..1415074ad71 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -145,9 +145,7 @@ jobs: - name: test shell: bash - run: | - CTEST_OUTPUT_ON_FAILURE=1 make test -C $GITHUB_WORKSPACE/build/ - $GITHUB_WORKSPACE/tools/ci/gha-script.sh + run: $GITHUB_WORKSPACE/tools/ci/gha-script.sh - name: after_success shell: bash From 4de0d948f0feceaa5c3fa1e4c1119f6db2224697 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Fri, 26 Jul 2024 23:30:11 +0100 Subject: [PATCH 12/29] upper case ON for cmake args --- tools/ci/gha-install.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/ci/gha-install.py b/tools/ci/gha-install.py index cb1b23b2433..a03c89712b1 100644 --- a/tools/ci/gha-install.py +++ b/tools/ci/gha-install.py @@ -14,7 +14,7 @@ def install(omp=False, mpi=False, phdf5=False, dagmc=False, libmesh=False, ncrys # Use MPI wrappers when building in parallel if mpi: - pip_suffix.append('-DOPENMC_USE_MPI=on') + pip_suffix.append('-DOPENMC_USE_MPI=ON') # Tell CMake to prefer parallel HDF5 if specified if phdf5: @@ -40,7 +40,7 @@ def install(omp=False, mpi=False, phdf5=False, dagmc=False, libmesh=False, ncrys pip_suffix.append(f'-DCMAKE_PREFIX_PATH={ncrystal_cmake_path}') # Build in coverage mode for coverage testing - pip_suffix.append('-DOPENMC_ENABLE_COVERAGE=on') + pip_suffix.append('-DOPENMC_ENABLE_COVERAGE=ON') pip_command.append(';'.join(pip_suffix)) # Build and install From 688d6882d59e56da6b3f2e191986b788fadf7982 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Sat, 27 Jul 2024 00:09:17 +0100 Subject: [PATCH 13/29] added quotes to cmake args --- tools/ci/gha-pip-install.py | 63 +++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 tools/ci/gha-pip-install.py diff --git a/tools/ci/gha-pip-install.py b/tools/ci/gha-pip-install.py new file mode 100644 index 00000000000..dde7535e0d6 --- /dev/null +++ b/tools/ci/gha-pip-install.py @@ -0,0 +1,63 @@ +import os +import subprocess + + +def install(omp=False, mpi=False, phdf5=False, dagmc=False, libmesh=False, ncrystal=False): + + # Build in debug mode by default with support for MCPL + pip_command = ['pip', 'install', '.[test,vtk]'] + pip_suffix = ['--config-settings=cmake.args="-DCMAKE_BUILD_TYPE=ON;-DOPENMC_USE_MCPL=ON'] + + # Turn off OpenMP if specified + if not omp: + pip_suffix.append('-DOPENMC_USE_OPENMP=off') + + # Use MPI wrappers when building in parallel + if mpi: + pip_suffix.append('-DOPENMC_USE_MPI=ON') + + # Tell CMake to prefer parallel HDF5 if specified + if phdf5: + if not mpi: + raise ValueError('Parallel HDF5 must be used in ' + 'conjunction with MPI.') + pip_suffix.append('-DHDF5_PREFER_PARALLEL=ON') + else: + pip_suffix.append('-DHDF5_PREFER_PARALLEL=OFF') + + if dagmc: + pip_suffix.append('-DOPENMC_USE_DAGMC=ON') + pip_suffix.append('-DCMAKE_PREFIX_PATH=~/DAGMC') + + if libmesh: + pip_suffix.append('-DOPENMC_USE_LIBMESH=ON') + libmesh_path = os.environ.get('HOME') + '/LIBMESH' + pip_suffix.append('-DCMAKE_PREFIX_PATH=' + libmesh_path) + + if ncrystal: + pip_suffix.append('-DOPENMC_USE_NCRYSTAL=ON') + ncrystal_cmake_path = os.environ.get('HOME') + '/ncrystal_inst/lib/cmake' + pip_suffix.append(f'-DCMAKE_PREFIX_PATH={ncrystal_cmake_path}') + + # Build in coverage mode for coverage testing + pip_suffix.append('-DOPENMC_ENABLE_COVERAGE=ON"') + + pip_command.append(';'.join(pip_suffix)) + # Build and install + print(' '.join(pip_command)) + subprocess.check_call(pip_command) + +def main(): + # Convert Travis matrix environment variables into arguments for install() + omp = (os.environ.get('OMP') == 'y') + mpi = (os.environ.get('MPI') == 'y') + phdf5 = (os.environ.get('PHDF5') == 'y') + dagmc = (os.environ.get('DAGMC') == 'y') + ncrystal = (os.environ.get('NCRYSTAL') == 'y') + libmesh = (os.environ.get('LIBMESH') == 'y') + + # Build and install + install(omp, mpi, phdf5, dagmc, libmesh, ncrystal) + +if __name__ == '__main__': + main() From 07a4dcd473fc048aeb4baf22bceb22fb203aa9a0 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Sat, 27 Jul 2024 00:26:08 +0100 Subject: [PATCH 14/29] keeping same filename --- .github/workflows/ci.yml | 4 ++- tools/ci/gha-install.py | 4 +-- tools/ci/gha-pip-install.py | 63 ------------------------------------- 3 files changed, 5 insertions(+), 66 deletions(-) delete mode 100644 tools/ci/gha-pip-install.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1415074ad71..9293e319b42 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -145,7 +145,9 @@ jobs: - name: test shell: bash - run: $GITHUB_WORKSPACE/tools/ci/gha-script.sh + run: | + CTEST_OUTPUT_ON_FAILURE=1 make test -C $GITHUB_WORKSPACE/build/ + $GITHUB_WORKSPACE/tools/ci/gha-script.sh - name: after_success shell: bash diff --git a/tools/ci/gha-install.py b/tools/ci/gha-install.py index a03c89712b1..dde7535e0d6 100644 --- a/tools/ci/gha-install.py +++ b/tools/ci/gha-install.py @@ -6,7 +6,7 @@ def install(omp=False, mpi=False, phdf5=False, dagmc=False, libmesh=False, ncrys # Build in debug mode by default with support for MCPL pip_command = ['pip', 'install', '.[test,vtk]'] - pip_suffix = ['--config-settings=cmake.args=-DCMAKE_BUILD_TYPE=ON;-DOPENMC_USE_MCPL=ON'] + pip_suffix = ['--config-settings=cmake.args="-DCMAKE_BUILD_TYPE=ON;-DOPENMC_USE_MCPL=ON'] # Turn off OpenMP if specified if not omp: @@ -40,7 +40,7 @@ def install(omp=False, mpi=False, phdf5=False, dagmc=False, libmesh=False, ncrys pip_suffix.append(f'-DCMAKE_PREFIX_PATH={ncrystal_cmake_path}') # Build in coverage mode for coverage testing - pip_suffix.append('-DOPENMC_ENABLE_COVERAGE=ON') + pip_suffix.append('-DOPENMC_ENABLE_COVERAGE=ON"') pip_command.append(';'.join(pip_suffix)) # Build and install diff --git a/tools/ci/gha-pip-install.py b/tools/ci/gha-pip-install.py deleted file mode 100644 index dde7535e0d6..00000000000 --- a/tools/ci/gha-pip-install.py +++ /dev/null @@ -1,63 +0,0 @@ -import os -import subprocess - - -def install(omp=False, mpi=False, phdf5=False, dagmc=False, libmesh=False, ncrystal=False): - - # Build in debug mode by default with support for MCPL - pip_command = ['pip', 'install', '.[test,vtk]'] - pip_suffix = ['--config-settings=cmake.args="-DCMAKE_BUILD_TYPE=ON;-DOPENMC_USE_MCPL=ON'] - - # Turn off OpenMP if specified - if not omp: - pip_suffix.append('-DOPENMC_USE_OPENMP=off') - - # Use MPI wrappers when building in parallel - if mpi: - pip_suffix.append('-DOPENMC_USE_MPI=ON') - - # Tell CMake to prefer parallel HDF5 if specified - if phdf5: - if not mpi: - raise ValueError('Parallel HDF5 must be used in ' - 'conjunction with MPI.') - pip_suffix.append('-DHDF5_PREFER_PARALLEL=ON') - else: - pip_suffix.append('-DHDF5_PREFER_PARALLEL=OFF') - - if dagmc: - pip_suffix.append('-DOPENMC_USE_DAGMC=ON') - pip_suffix.append('-DCMAKE_PREFIX_PATH=~/DAGMC') - - if libmesh: - pip_suffix.append('-DOPENMC_USE_LIBMESH=ON') - libmesh_path = os.environ.get('HOME') + '/LIBMESH' - pip_suffix.append('-DCMAKE_PREFIX_PATH=' + libmesh_path) - - if ncrystal: - pip_suffix.append('-DOPENMC_USE_NCRYSTAL=ON') - ncrystal_cmake_path = os.environ.get('HOME') + '/ncrystal_inst/lib/cmake' - pip_suffix.append(f'-DCMAKE_PREFIX_PATH={ncrystal_cmake_path}') - - # Build in coverage mode for coverage testing - pip_suffix.append('-DOPENMC_ENABLE_COVERAGE=ON"') - - pip_command.append(';'.join(pip_suffix)) - # Build and install - print(' '.join(pip_command)) - subprocess.check_call(pip_command) - -def main(): - # Convert Travis matrix environment variables into arguments for install() - omp = (os.environ.get('OMP') == 'y') - mpi = (os.environ.get('MPI') == 'y') - phdf5 = (os.environ.get('PHDF5') == 'y') - dagmc = (os.environ.get('DAGMC') == 'y') - ncrystal = (os.environ.get('NCRYSTAL') == 'y') - libmesh = (os.environ.get('LIBMESH') == 'y') - - # Build and install - install(omp, mpi, phdf5, dagmc, libmesh, ncrystal) - -if __name__ == '__main__': - main() From 9253977ac3df5a29b2b021fb6112c509b7794c54 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Sat, 27 Jul 2024 00:37:54 +0100 Subject: [PATCH 15/29] running just pytest --- .github/workflows/ci.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9293e319b42..1415074ad71 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -145,9 +145,7 @@ jobs: - name: test shell: bash - run: | - CTEST_OUTPUT_ON_FAILURE=1 make test -C $GITHUB_WORKSPACE/build/ - $GITHUB_WORKSPACE/tools/ci/gha-script.sh + run: $GITHUB_WORKSPACE/tools/ci/gha-script.sh - name: after_success shell: bash From 1f016940ee9e6c0c6e2eba5bf71912729ee2bf63 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Sat, 27 Jul 2024 00:39:43 +0100 Subject: [PATCH 16/29] [skip ci] corrected cmake arg passing example --- docs/source/usersguide/install.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/source/usersguide/install.rst b/docs/source/usersguide/install.rst index 203ec879430..c0ad2fdcd48 100644 --- a/docs/source/usersguide/install.rst +++ b/docs/source/usersguide/install.rst @@ -176,7 +176,7 @@ feature can be used to access the installed packages. .. _install_source: -------------------------------- -Compiling from Source with CMake +Compiling from source with CMake -------------------------------- .. _prerequisites: @@ -533,7 +533,7 @@ Package Index (`PyPI `_). The pip command will also compile an executable named ``openmc`` and install it (by default in the bin folder of the Python package directory). -Passing CMake Options to via pip +Passing CMake arguments via pip -------------------------------- If you need to pass CMake options to the build process, you can do so by @@ -543,13 +543,13 @@ For example, to build OpenMC with MPI support, you can run: .. code-block:: sh - python -m pip install . --global-option="build_ext" --global-option="--" --global-option="-DOPENMC_USE_MPI=ON" + python -m pip install . --config-settings=cmake.args=-DOPENMC_USE_MPI=ON To build OpenMC with DAGMC support two CMake arguments are needed, you can run: .. code-block:: sh - python -m pip install . --global-option="build_ext" --global-option="--" --global-option="-DOPENMC_USE_DAGMC=ON" --global-option="-DDAGMC_ROOT=/path/to/dagmc/installation" + python -m pip install . --config-settings=cmake.args="-DOPENMC_USE_DAGMC=ON;DDAGMC_ROOT=/path/to/dagmc/installation" Installing in "Development" Mode -------------------------------- From 6850217ad5dffdcc1874c052b809c154166dfc84 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Sat, 27 Jul 2024 01:02:49 +0100 Subject: [PATCH 17/29] added diagnosis prints --- CMakeLists.txt | 11 +++++++++++ tools/ci/gha-install.py | 1 + 2 files changed, 12 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c86c391521..928f72c245f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,17 @@ option(OPENMC_USE_MCPL "Enable MCPL" option(OPENMC_USE_NCRYSTAL "Enable support for NCrystal scattering" OFF) option(OPENMC_USE_UWUW "Enable UWUW" OFF) +message(STATUS "OPENMC_USE_OPENMP ${OPENMC_USE_OPENMP}") +message(STATUS "OPENMC_BUILD_TESTS ${OPENMC_BUILD_TESTS}") +message(STATUS "OPENMC_ENABLE_PROFILE ${OPENMC_ENABLE_PROFILE}") +message(STATUS "OPENMC_ENABLE_COVERAGE ${OPENMC_ENABLE_COVERAGE}") +message(STATUS "OPENMC_USE_DAGMC ${OPENMC_USE_DAGMC}") +message(STATUS "OPENMC_USE_LIBMESH ${OPENMC_USE_LIBMESH}") +message(STATUS "OPENMC_USE_MPI ${OPENMC_USE_MPI}") +message(STATUS "OPENMC_USE_MCPL ${OPENMC_USE_MCPL}") +message(STATUS "OPENMC_USE_NCRYSTAL ${OPENMC_USE_NCRYSTAL}") +message(STATUS "OPENMC_USE_UWUW ${OPENMC_USE_UWUW}") + # Warnings for deprecated options foreach(OLD_OPT IN ITEMS "openmp" "profile" "coverage" "dagmc" "libmesh") if(DEFINED ${OLD_OPT}) diff --git a/tools/ci/gha-install.py b/tools/ci/gha-install.py index dde7535e0d6..4ef2e780d3f 100644 --- a/tools/ci/gha-install.py +++ b/tools/ci/gha-install.py @@ -43,6 +43,7 @@ def install(omp=False, mpi=False, phdf5=False, dagmc=False, libmesh=False, ncrys pip_suffix.append('-DOPENMC_ENABLE_COVERAGE=ON"') pip_command.append(';'.join(pip_suffix)) + pip_command.append('--verbose') # Build and install print(' '.join(pip_command)) subprocess.check_call(pip_command) From 97a3f22bdf532315f5381310ce540a374272f7cc Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Sat, 27 Jul 2024 01:15:36 +0100 Subject: [PATCH 18/29] removed 2nd pip install which was overwritting --- tools/ci/gha-install.py | 2 +- tools/ci/gha-install.sh | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/tools/ci/gha-install.py b/tools/ci/gha-install.py index 4ef2e780d3f..da94df1bc2b 100644 --- a/tools/ci/gha-install.py +++ b/tools/ci/gha-install.py @@ -5,7 +5,7 @@ def install(omp=False, mpi=False, phdf5=False, dagmc=False, libmesh=False, ncrystal=False): # Build in debug mode by default with support for MCPL - pip_command = ['pip', 'install', '.[test,vtk]'] + pip_command = ['pip', 'install', '.[test,vtk,ci]'] pip_suffix = ['--config-settings=cmake.args="-DCMAKE_BUILD_TYPE=ON;-DOPENMC_USE_MCPL=ON'] # Turn off OpenMP if specified diff --git a/tools/ci/gha-install.sh b/tools/ci/gha-install.sh index 87952fda9cb..e69aaaa13fb 100755 --- a/tools/ci/gha-install.sh +++ b/tools/ci/gha-install.sh @@ -46,6 +46,3 @@ fi # Build and install OpenMC executable python tools/ci/gha-install.py - -# Install Python API in editable mode -pip install -e .[test,vtk,ci] From 41d28ff3394626a467dec907deb6f68a60e904b5 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Mon, 29 Jul 2024 17:33:46 +0100 Subject: [PATCH 19/29] float_endf from endf package --- openmc/data/_endf.pyx | 8 ------ openmc/data/endf.c | 57 ------------------------------------------- openmc/data/endf.py | 10 +------- pyproject.toml | 1 + 4 files changed, 2 insertions(+), 74 deletions(-) delete mode 100644 openmc/data/_endf.pyx delete mode 100644 openmc/data/endf.c diff --git a/openmc/data/_endf.pyx b/openmc/data/_endf.pyx deleted file mode 100644 index 991ee015b29..00000000000 --- a/openmc/data/_endf.pyx +++ /dev/null @@ -1,8 +0,0 @@ -# cython: c_string_type=str, c_string_encoding=ascii - -cdef extern from "endf.c": - double cfloat_endf(const char* buffer, int n) - -def float_endf(s): - cdef const char* c_string = s - return cfloat_endf(c_string, len(s)) diff --git a/openmc/data/endf.c b/openmc/data/endf.c deleted file mode 100644 index dd5eee54184..00000000000 --- a/openmc/data/endf.c +++ /dev/null @@ -1,57 +0,0 @@ -#include - -//! Convert string representation of a floating point number into a double -// -//! This function handles converting floating point numbers from an ENDF 11 -//! character field into a double, covering all the corner cases. Floating point -//! numbers are allowed to contain whitespace (which is ignored). Also, in -//! exponential notation, it allows the 'e' to be omitted. A field containing -//! only whitespace is to be interpreted as a zero. -// -//! \param buffer character input from an ENDF file -//! \param n Length of character input -//! \return Floating point number - -double cfloat_endf(const char* buffer, int n) -{ - char arr[13]; // 11 characters plus e and a null terminator - int j = 0; // current position in arr - int found_significand = 0; - int found_exponent = 0; - - // limit n to 11 characters - n = n > 11 ? 11 : n; - - int i; - for (i = 0; i < n; ++i) { - char c = buffer[i]; - - // Skip whitespace characters - if (c == ' ') continue; - - if (found_significand) { - if (!found_exponent) { - if (c == '+' || c == '-') { - // In the case that we encounter +/- and we haven't yet encountered - // e/E, we manually add it - arr[j++] = 'e'; - found_exponent = 1; - - } else if (c == 'e' || c == 'E' || c == 'd' || c == 'D') { - arr[j++] = 'e'; - found_exponent = 1; - continue; - } - } - } else if (c == '.' || (c >= '0' && c <= '9')) { - found_significand = 1; - } - - // Copy character - arr[j++] = c; - } - - // Done copying. Add null terminator and convert to double - arr[j] = '\0'; - return atof(arr); -} diff --git a/openmc/data/endf.py b/openmc/data/endf.py index 73299723a8b..63cd092ebb1 100644 --- a/openmc/data/endf.py +++ b/openmc/data/endf.py @@ -14,11 +14,7 @@ from .data import gnds_name from .function import Tabulated1D -try: - from ._endf import float_endf - _CYTHON = True -except ImportError: - _CYTHON = False +from endf.records import float_endf _LIBRARY = {0: 'ENDF/B', 1: 'ENDF/A', 2: 'JEFF', 3: 'EFF', @@ -91,10 +87,6 @@ def py_float_endf(s): return float(ENDF_FLOAT_RE.sub(r'\1e\2\3', s)) -if not _CYTHON: - float_endf = py_float_endf - - def int_endf(s): """Convert string of integer number in ENDF to int. diff --git a/pyproject.toml b/pyproject.toml index 2b2764cea69..98b1d152fbc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,6 +34,7 @@ dependencies = [ "lxml", "uncertainties", "setuptools", + "endf", ] [project.optional-dependencies] From c03a236ddda10dfcdc4c3018a046ff3ed3c2fc0e Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Mon, 29 Jul 2024 17:47:23 +0100 Subject: [PATCH 20/29] removed reference to float endf --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 4e24f48a123..88a45a36090 100755 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ kwargs = { - # Cython is used to add resonance reconstruction and fast float_endf + # Cython is used to add resonance reconstruction 'ext_modules': cythonize('openmc/data/*.pyx'), 'include_dirs': [np.get_include()] } From 3cc88a0588ef9f23c1ea9fef6a80a884c425b79b Mon Sep 17 00:00:00 2001 From: Jon Shimwell Date: Wed, 7 Aug 2024 17:22:34 +0100 Subject: [PATCH 21/29] removing resonance --- openmc/data/function.py | 22 -- openmc/data/reconstruct.pyx | 522 -------------------------- tests/unit_tests/test_data_neutron.py | 26 +- 3 files changed, 4 insertions(+), 566 deletions(-) delete mode 100644 openmc/data/reconstruct.pyx diff --git a/openmc/data/function.py b/openmc/data/function.py index 23fd5e9d4fa..c5914f513d5 100644 --- a/openmc/data/function.py +++ b/openmc/data/function.py @@ -708,28 +708,6 @@ def __init__(self, resonances, background, mt): self.background = background self.mt = mt - def __call__(self, x): - # Get background cross section - xs = self.background(x) - - for r in self.resonances: - if not isinstance(r, openmc.data.resonance._RESOLVED): - continue - - if isinstance(x, Iterable): - # Determine which energies are within resolved resonance range - within = (r.energy_min <= x) & (x <= r.energy_max) - - # Get resonance cross sections and add to background - resonant_xs = r.reconstruct(x[within]) - xs[within] += resonant_xs[self.mt] - else: - if r.energy_min <= x <= r.energy_max: - resonant_xs = r.reconstruct(x) - xs += resonant_xs[self.mt] - - return xs - @property def background(self): return self._background diff --git a/openmc/data/reconstruct.pyx b/openmc/data/reconstruct.pyx deleted file mode 100644 index cd0bbc38b95..00000000000 --- a/openmc/data/reconstruct.pyx +++ /dev/null @@ -1,522 +0,0 @@ -from libc.stdlib cimport malloc, calloc, free -from libc.math cimport cos, sin, sqrt, atan, M_PI - -cimport numpy as np -import numpy as np -from numpy.linalg import inv -cimport cython - - -cdef extern from "complex.h": - double cabs(double complex) - double complex conj(double complex) - double creal(complex double) - double cimag(complex double) - double complex cexp(double complex) - -# Physical constants are from CODATA 2014 -cdef double NEUTRON_MASS_ENERGY = 939.5654133e6 # eV/c^2 -cdef double HBAR_C = 197.3269788e5 # eV-b^0.5 - - -@cython.cdivision(True) -def wave_number(double A, double E): - r"""Neutron wave number in center-of-mass system. - - ENDF-102 defines the neutron wave number in the center-of-mass system in - Equation D.10 as - - .. math:: - k = \frac{2m_n}{\hbar} \frac{A}{A + 1} \sqrt{|E|} - - Parameters - ---------- - A : double - Ratio of target mass to neutron mass - E : double - Energy in eV - - Returns - ------- - double - Neutron wave number in b^-0.5 - - """ - return A/(A + 1)*sqrt(2*NEUTRON_MASS_ENERGY*abs(E))/HBAR_C - -@cython.cdivision(True) -cdef double _wave_number(double A, double E): - return A/(A + 1)*sqrt(2*NEUTRON_MASS_ENERGY*abs(E))/HBAR_C - - -@cython.cdivision(True) -cdef double phaseshift(int l, double rho): - """Calculate hardsphere phase shift as given in ENDF-102, Equation D.13 - - Parameters - ---------- - l : int - Angular momentum quantum number - rho : float - Product of the wave number and the channel radius - - Returns - ------- - double - Hardsphere phase shift - - """ - if l == 0: - return rho - elif l == 1: - return rho - atan(rho) - elif l == 2: - return rho - atan(3*rho/(3 - rho**2)) - elif l == 3: - return rho - atan((15*rho - rho**3)/(15 - 6*rho**2)) - elif l == 4: - return rho - atan((105*rho - 10*rho**3)/(105 - 45*rho**2 + rho**4)) - - -@cython.cdivision(True) -def penetration_shift(int l, double rho): - r"""Calculate shift and penetration factors as given in ENDF-102, Equations D.11 - and D.12. - - Parameters - ---------- - l : int - Angular momentum quantum number - rho : float - Product of the wave number and the channel radius - - Returns - ------- - double - Penetration factor for given :math:`l` - double - Shift factor for given :math:`l` - - """ - cdef double den - - if l == 0: - return rho, 0. - elif l == 1: - den = 1 + rho**2 - return rho**3/den, -1/den - elif l == 2: - den = 9 + 3*rho**2 + rho**4 - return rho**5/den, -(18 + 3*rho**2)/den - elif l == 3: - den = 225 + 45*rho**2 + 6*rho**4 + rho**6 - return rho**7/den, -(675 + 90*rho**2 + 6*rho**4)/den - elif l == 4: - den = 11025 + 1575*rho**2 + 135*rho**4 + 10*rho**6 + rho**8 - return rho**9/den, -(44100 + 4725*rho**2 + 270*rho**4 + 10*rho**6)/den - - -@cython.boundscheck(False) -@cython.wraparound(False) -@cython.cdivision(True) -def reconstruct_mlbw(mlbw, double E): - """Evaluate cross section using MLBW data. - - Parameters - ---------- - mlbw : openmc.data.MultiLevelBreitWigner - Multi-level Breit-Wigner resonance parameters - E : double - Energy in eV at which to evaluate the cross section - - Returns - ------- - elastic : double - Elastic scattering cross section in barns - capture : double - Radiative capture cross section in barns - fission : double - Fission cross section in barns - - """ - cdef int i, nJ, ij, l, n_res, i_res - cdef double elastic, capture, fission - cdef double A, k, rho, rhohat, I - cdef double P, S, phi, cos2phi, sin2phi - cdef double Ex, Q, rhoc, rhochat, P_c, S_c - cdef double jmin, jmax, j, Dl - cdef double E_r, gt, gn, gg, gf, gx, P_r, S_r, P_rx - cdef double gnE, gtE, Eprime, x, f - cdef double *g - cdef double (*s)[2] - cdef double [:,:] params - - I = mlbw.target_spin - A = mlbw.atomic_weight_ratio - k = _wave_number(A, E) - - elastic = 0. - capture = 0. - fission = 0. - - for i, l in enumerate(mlbw._l_values): - params = mlbw._parameter_matrix[l] - - rho = k*mlbw.channel_radius[l](E) - rhohat = k*mlbw.scattering_radius[l](E) - P, S = penetration_shift(l, rho) - phi = phaseshift(l, rhohat) - cos2phi = cos(2*phi) - sin2phi = sin(2*phi) - - # Determine shift and penetration at modified energy - if mlbw._competitive[i]: - Ex = E + mlbw.q_value[l]*(A + 1)/A - rhoc = mlbw.channel_radius[l](Ex) - rhochat = mlbw.scattering_radius[l](Ex) - P_c, S_c = penetration_shift(l, rhoc) - if Ex < 0: - P_c = 0 - - # Determine range of total angular momentum values based on equation - # 41 in LA-UR-12-27079 - jmin = abs(abs(I - l) - 0.5) - jmax = I + l + 0.5 - nJ = int(jmax - jmin + 1) - - # Determine Dl factor using Equation 43 in LA-UR-12-27079 - Dl = 2*l + 1 - g = malloc(nJ*sizeof(double)) - for ij in range(nJ): - j = jmin + ij - g[ij] = (2*j + 1)/(4*I + 2) - Dl -= g[ij] - - s = calloc(2*nJ, sizeof(double)) - for i_res in range(params.shape[0]): - # Copy resonance parameters - E_r = params[i_res, 0] - j = params[i_res, 2] - ij = int(j - jmin) - gt = params[i_res, 3] - gn = params[i_res, 4] - gg = params[i_res, 5] - gf = params[i_res, 6] - gx = params[i_res, 7] - P_r = params[i_res, 8] - S_r = params[i_res, 9] - P_rx = params[i_res, 10] - - # Calculate neutron and total width at energy E - gnE = P*gn/P_r # ENDF-102, Equation D.7 - gtE = gnE + gg + gf - if gx > 0: - gtE += gx*P_c/P_rx - - Eprime = E_r + (S_r - S)/(2*P_r)*gn # ENDF-102, Equation D.9 - x = 2*(E - Eprime)/gtE # LA-UR-12-27079, Equation 26 - f = 2*gnE/(gtE*(1 + x*x)) # Common factor in Equation 40 - s[ij][0] += f # First sum in Equation 40 - s[ij][1] += f*x # Second sum in Equation 40 - capture += f*g[ij]*gg/gtE - if gf > 0: - fission += f*g[ij]*gf/gtE - - for ij in range(nJ): - # Add all but last term of LA-UR-12-27079, Equation 40 - elastic += g[ij]*((1 - cos2phi - s[ij][0])**2 + - (sin2phi + s[ij][1])**2) - - # Add final term with Dl from Equation 40 - elastic += 2*Dl*(1 - cos2phi) - - # Free memory - free(g) - free(s) - - capture *= 2*M_PI/(k*k) - fission *= 2*M_PI/(k*k) - elastic *= M_PI/(k*k) - - return (elastic, capture, fission) - - -@cython.boundscheck(False) -@cython.wraparound(False) -@cython.cdivision(True) -def reconstruct_slbw(slbw, double E): - """Evaluate cross section using SLBW data. - - Parameters - ---------- - slbw : openmc.data.SingleLevelBreitWigner - Single-level Breit-Wigner resonance parameters - E : double - Energy in eV at which to evaluate the cross section - - Returns - ------- - elastic : double - Elastic scattering cross section in barns - capture : double - Radiative capture cross section in barns - fission : double - Fission cross section in barns - - """ - cdef int i, l, i_res - cdef double elastic, capture, fission - cdef double A, k, rho, rhohat, I - cdef double P, S, phi, cos2phi, sin2phi, sinphi2 - cdef double Ex, rhoc, rhochat, P_c, S_c - cdef double E_r, J, gt, gn, gg, gf, gx, P_r, S_r, P_rx - cdef double gnE, gtE, Eprime, f - cdef double x, theta, psi, chi - cdef double [:,:] params - - I = slbw.target_spin - A = slbw.atomic_weight_ratio - k = _wave_number(A, E) - - elastic = 0. - capture = 0. - fission = 0. - - for i, l in enumerate(slbw._l_values): - params = slbw._parameter_matrix[l] - - rho = k*slbw.channel_radius[l](E) - rhohat = k*slbw.scattering_radius[l](E) - P, S = penetration_shift(l, rho) - phi = phaseshift(l, rhohat) - cos2phi = cos(2*phi) - sin2phi = sin(2*phi) - sinphi2 = sin(phi)**2 - - # Add potential scattering -- first term in ENDF-102, Equation D.2 - elastic += 4*M_PI/(k*k)*(2*l + 1)*sinphi2 - - # Determine shift and penetration at modified energy - if slbw._competitive[i]: - Ex = E + slbw.q_value[l]*(A + 1)/A - rhoc = k*slbw.channel_radius[l](Ex) - rhochat = k*slbw.scattering_radius[l](Ex) - P_c, S_c = penetration_shift(l, rhoc) - if Ex < 0: - P_c = 0 - - for i_res in range(params.shape[0]): - # Copy resonance parameters - E_r = params[i_res, 0] - J = params[i_res, 2] - gt = params[i_res, 3] - gn = params[i_res, 4] - gg = params[i_res, 5] - gf = params[i_res, 6] - gx = params[i_res, 7] - P_r = params[i_res, 8] - S_r = params[i_res, 9] - P_rx = params[i_res, 10] - - # Calculate neutron and total width at energy E - gnE = P*gn/P_r # Equation D.7 - gtE = gnE + gg + gf - if gx > 0: - gtE += gx*P_c/P_rx - - Eprime = E_r + (S_r - S)/(2*P_r)*gn # Equation D.9 - gJ = (2*J + 1)/(4*I + 2) # Mentioned in section D.1.1.4 - - # Calculate common factor for elastic, capture, and fission - # cross sections - f = M_PI/(k*k)*gJ*gnE/((E - Eprime)**2 + gtE**2/4) - - # Add contribution to elastic per Equation D.2 - elastic += f*(gnE*cos2phi - 2*(gg + gf)*sinphi2 - + 2*(E - Eprime)*sin2phi) - - # Add contribution to capture per Equation D.3 - capture += f*gg - - # Add contribution to fission per Equation D.6 - if gf > 0: - fission += f*gf - - return (elastic, capture, fission) - - -@cython.boundscheck(False) -@cython.wraparound(False) -@cython.cdivision(True) -def reconstruct_rm(rm, double E): - """Evaluate cross section using Reich-Moore data. - - Parameters - ---------- - rm : openmc.data.ReichMoore - Reich-Moore resonance parameters - E : double - Energy in eV at which to evaluate the cross section - - Returns - ------- - elastic : double - Elastic scattering cross section in barns - capture : double - Radiative capture cross section in barns - fission : double - Fission cross section in barns - - """ - cdef int i, l, m, n, i_res - cdef int i_s, num_s, i_J, num_J - cdef double elastic, capture, fission, total - cdef double A, k, rho, rhohat, I - cdef double P, S, phi - cdef double smin, smax, s, Jmin, Jmax, J, j - cdef double E_r, gn, gg, gfa, gfb, P_r - cdef double E_diff, abs_value, gJ - cdef double Kr, Ki, x - cdef double complex Ubar, U_, factor - cdef bint hasfission - cdef np.ndarray[double, ndim=2] one - cdef np.ndarray[double complex, ndim=2] K, Imat, U - cdef double [:,:] params - - # Get nuclear spin - I = rm.target_spin - - elastic = 0. - fission = 0. - total = 0. - A = rm.atomic_weight_ratio - k = _wave_number(A, E) - one = np.eye(3) - K = np.zeros((3,3), dtype=complex) - - for i, l in enumerate(rm._l_values): - # Check for l-dependent scattering radius - rho = k*rm.channel_radius[l](E) - rhohat = k*rm.scattering_radius[l](E) - - # Calculate shift and penetrability - P, S = penetration_shift(l, rho) - - # Calculate phase shift - phi = phaseshift(l, rhohat) - - # Calculate common factor on collision matrix terms (term outside curly - # braces in ENDF-102, Eq. D.27) - Ubar = cexp(-2j*phi) - - # The channel spin is the vector sum of the target spin, I, and the - # neutron spin, 1/2, so can take on values of |I - 1/2| < s < I + 1/2 - smin = abs(I - 0.5) - smax = I + 0.5 - num_s = int(smax - smin + 1) - - for i_s in range(num_s): - s = i_s + smin - - # Total angular momentum is the vector sum of l and s and can assume - # values between |l - s| < J < l + s - Jmin = abs(l - s) - Jmax = l + s - num_J = int(Jmax - Jmin + 1) - - for i_J in range(num_J): - J = i_J + Jmin - - # Initialize K matrix - for m in range(3): - for n in range(3): - K[m,n] = 0.0 - - hasfission = False - if (l, J) in rm._parameter_matrix: - params = rm._parameter_matrix[l, J] - - for i_res in range(params.shape[0]): - # Sometimes, the same (l, J) quantum numbers can occur - # for different values of the channel spin, s. In this - # case, the sign of the channel spin indicates which - # spin is to be used. If the spin is negative assume - # this resonance comes from the I - 1/2 channel and vice - # versa. - j = params[i_res, 2] - if l > 0: - if (j < 0 and s != smin) or (j > 0 and s != smax): - continue - - # Copy resonance parameters - E_r = params[i_res, 0] - gn = params[i_res, 3] - gg = params[i_res, 4] - gfa = params[i_res, 5] - gfb = params[i_res, 6] - P_r = params[i_res, 7] - - # Calculate neutron width at energy E - gn = sqrt(P*gn/P_r) - - # Calculate j/2 * inverse of denominator of K matrix terms - factor = 0.5j/(E_r - E - 0.5j*gg) - - # Upper triangular portion of K matrix -- see ENDF-102, - # Equation D.28 - K[0,0] = K[0,0] + gn*gn*factor - if gfa != 0.0 or gfb != 0.0: - # Negate fission widths if necessary - gfa = (-1 if gfa < 0 else 1)*sqrt(abs(gfa)) - gfb = (-1 if gfb < 0 else 1)*sqrt(abs(gfb)) - - K[0,1] = K[0,1] + gn*gfa*factor - K[0,2] = K[0,2] + gn*gfb*factor - K[1,1] = K[1,1] + gfa*gfa*factor - K[1,2] = K[1,2] + gfa*gfb*factor - K[2,2] = K[2,2] + gfb*gfb*factor - hasfission = True - - # Get collision matrix - gJ = (2*J + 1)/(4*I + 2) - if hasfission: - # Copy upper triangular portion of K to lower triangular - K[1,0] = K[0,1] - K[2,0] = K[0,2] - K[2,1] = K[1,2] - - Imat = inv(one - K) - U = Ubar*(2*Imat - one) # ENDF-102, Eq. D.27 - elastic += gJ*cabs(1 - U[0,0])**2 # ENDF-102, Eq. D.24 - total += 2*gJ*(1 - creal(U[0,0])) # ENDF-102, Eq. D.23 - - # Calculate fission from ENDF-102, Eq. D.26 - fission += 4*gJ*(cabs(Imat[1,0])**2 + cabs(Imat[2,0])**2) - else: - U_ = Ubar*(2/(1 - K[0,0]) - 1) - if abs(creal(K[0,0])) < 3e-4 and abs(phi) < 3e-4: - # If K and phi are both very small, the calculated cross - # sections can lose precision because the real part of U - # ends up very close to unity. To get around this, we - # use Euler's formula to express Ubar by real and - # imaginary parts, expand cos(2phi) = 1 - 2phi^2 + - # O(phi^4), and then simplify - Kr = creal(K[0,0]) - Ki = cimag(K[0,0]) - x = 2*(-Kr + (Kr*Kr + Ki*Ki)*(1 - phi*phi) + phi*phi - - sin(2*phi)*Ki)/((1 - Kr)*(1 - Kr) + Ki*Ki) - total += 2*gJ*x - elastic += gJ*(x*x + cimag(U_)**2) - else: - total += 2*gJ*(1 - creal(U_)) # ENDF-102, Eq. D.23 - elastic += gJ*cabs(1 - U_)**2 # ENDF-102, Eq. D.24 - - # Calculate capture as difference of other cross sections as per ENDF-102, - # Equation D.25 - capture = total - elastic - fission - - elastic *= M_PI/(k*k) - capture *= M_PI/(k*k) - fission *= M_PI/(k*k) - - return (elastic, capture, fission) diff --git a/tests/unit_tests/test_data_neutron.py b/tests/unit_tests/test_data_neutron.py index c0d6a1f1547..5e685854367 100644 --- a/tests/unit_tests/test_data_neutron.py +++ b/tests/unit_tests/test_data_neutron.py @@ -282,10 +282,6 @@ def test_slbw(xe135): s = resolved.parameters.iloc[0] assert s['energy'] == pytest.approx(0.084) - xs = resolved.reconstruct([10., 30., 100.]) - assert sorted(xs.keys()) == [2, 18, 102] - assert np.all(xs[18] == 0.0) - def test_mlbw(sm150): resolved = sm150.resonances.resolved @@ -294,10 +290,6 @@ def test_mlbw(sm150): assert resolved.energy_max == pytest.approx(1570.) assert resolved.target_spin == 0.0 - xs = resolved.reconstruct([10., 100., 1000.]) - assert sorted(xs.keys()) == [2, 18, 102] - assert np.all(xs[18] == 0.0) - def test_reichmoore(gd154): res = gd154.resonances @@ -347,8 +339,6 @@ def test_mlbw_cov_lcomp0(cf252): assert not subset.parameters.empty assert (subset.file2res.parameters['energy'] < 100).all() samples = cov.sample(1) - xs = samples[0].reconstruct([10., 100., 1000.]) - assert sorted(xs.keys()) == [2, 18, 102] def test_mlbw_cov_lcomp1(ti50): @@ -365,9 +355,7 @@ def test_mlbw_cov_lcomp1(ti50): subset = cov.subset('L', [1, 1]) assert not subset.parameters.empty assert (subset.file2res.parameters['L'] == 1).all() - samples = cov.sample(1) - xs = samples[0].reconstruct([10., 100., 1000.]) - assert sorted(xs.keys()) == [2, 18, 102] + cov.sample(1) def test_mlbw_cov_lcomp2(na23): @@ -384,9 +372,7 @@ def test_mlbw_cov_lcomp2(na23): subset = cov.subset('L', [1, 1]) assert not subset.parameters.empty assert (subset.file2res.parameters['L'] == 1).all() - samples = cov.sample(1) - xs = samples[0].reconstruct([10., 100., 1000.]) - assert sorted(xs.keys()) == [2, 18, 102] + cov.sample(1) def test_rmcov_lcomp1(gd154): @@ -403,9 +389,7 @@ def test_rmcov_lcomp1(gd154): subset = cov.subset('energy', [0, 100]) assert not subset.parameters.empty assert (subset.file2res.parameters['energy'] < 100).all() - samples = cov.sample(1) - xs = samples[0].reconstruct([10., 100., 1000.]) - assert sorted(xs.keys()) == [2, 18, 102] + cov.sample(1) def test_rmcov_lcomp2(th232): @@ -422,9 +406,7 @@ def test_rmcov_lcomp2(th232): subset = cov.subset('energy', [0, 100]) assert not subset.parameters.empty assert (subset.file2res.parameters['energy'] < 100).all() - samples = cov.sample(1) - xs = samples[0].reconstruct([10., 100., 1000.]) - assert sorted(xs.keys()) == [2, 18, 102] + cov.sample(1) def test_madland_nix(am241): From f8f9ac4277f02bf285896fb1c9e831f55e5a9c55 Mon Sep 17 00:00:00 2001 From: Jon Shimwell Date: Thu, 8 Aug 2024 08:13:01 +0100 Subject: [PATCH 22/29] no longer calling ResonancesWithBackground --- tests/unit_tests/test_data_neutron.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/unit_tests/test_data_neutron.py b/tests/unit_tests/test_data_neutron.py index 5e685854367..db6ae1eb850 100644 --- a/tests/unit_tests/test_data_neutron.py +++ b/tests/unit_tests/test_data_neutron.py @@ -311,7 +311,6 @@ def test_reichmoore(gd154): elastic = gd154.reactions[2].xs['0K'] assert isinstance(elastic, openmc.data.ResonancesWithBackground) - assert elastic(0.0253) == pytest.approx(5.7228949796394524) def test_rml(cl35): From a2bc5552dda4d803ed40fd102ab42cc5d5e09620 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Tue, 13 Aug 2024 15:56:58 +0100 Subject: [PATCH 23/29] [skip ci] removed prints --- CMakeLists.txt | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 928f72c245f..14047e171d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,16 +41,6 @@ option(OPENMC_USE_MCPL "Enable MCPL" option(OPENMC_USE_NCRYSTAL "Enable support for NCrystal scattering" OFF) option(OPENMC_USE_UWUW "Enable UWUW" OFF) -message(STATUS "OPENMC_USE_OPENMP ${OPENMC_USE_OPENMP}") -message(STATUS "OPENMC_BUILD_TESTS ${OPENMC_BUILD_TESTS}") -message(STATUS "OPENMC_ENABLE_PROFILE ${OPENMC_ENABLE_PROFILE}") -message(STATUS "OPENMC_ENABLE_COVERAGE ${OPENMC_ENABLE_COVERAGE}") -message(STATUS "OPENMC_USE_DAGMC ${OPENMC_USE_DAGMC}") -message(STATUS "OPENMC_USE_LIBMESH ${OPENMC_USE_LIBMESH}") -message(STATUS "OPENMC_USE_MPI ${OPENMC_USE_MPI}") -message(STATUS "OPENMC_USE_MCPL ${OPENMC_USE_MCPL}") -message(STATUS "OPENMC_USE_NCRYSTAL ${OPENMC_USE_NCRYSTAL}") -message(STATUS "OPENMC_USE_UWUW ${OPENMC_USE_UWUW}") # Warnings for deprecated options foreach(OLD_OPT IN ITEMS "openmp" "profile" "coverage" "dagmc" "libmesh") From f994293108cfcbcb46eec4e43453028eff117f25 Mon Sep 17 00:00:00 2001 From: Jon Shimwell Date: Tue, 13 Aug 2024 22:37:04 +0100 Subject: [PATCH 24/29] added action --- .github/workflows/build_wheels.yml | 23 +++++++++++++++++++++++ pyproject.toml | 10 +++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/build_wheels.yml diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml new file mode 100644 index 00000000000..d3e8606e96d --- /dev/null +++ b/.github/workflows/build_wheels.yml @@ -0,0 +1,23 @@ +name: Build + +on: [push, pull_request] + +jobs: + build_wheels: + name: Build wheels on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + # macos-13 is an intel runner, macos-14 is apple silicon + os: [ubuntu-latest] + + steps: + - uses: actions/checkout@v4 + + - name: Build wheels + uses: pypa/cibuildwheel@v2.20.0 + + - uses: actions/upload-artifact@v4 + with: + name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }} + path: ./wheelhouse/*.whl \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index a77149c8a48..c24026300b1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -78,6 +78,14 @@ openmc-voxel-to-vtk = "scripts.openmc_voxel_to_vtk:main" openmc = "openmc.openmc_exec:main" [tool.scikit-build] -cmake.verbose = true +build.verbose = true # cmake args can be passed in here or in the command line via exports or inline with the pip install cmake.args = ["-DCMAKE_BUILD_TYPE=RELEASE"] + +[tool.cibuildwheel] +skip = "*-win_*" +before-all = """ + yum install -y epel-release + yum install -y hdf5 hdf5-devel libpng-devel cmake eigen3-devel gcc gcc-c++ wget +""" +manylinux-x86_64-image = "manylinux_2_28" From 0b7975764bb736c19418b27dbc856343a6c1de24 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Tue, 27 Aug 2024 22:31:36 +0100 Subject: [PATCH 25/29] added source dir include --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 14047e171d6..c2b39903a94 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -581,6 +581,7 @@ add_executable(openmc src/main.cpp) add_executable(OpenMC::openmc ALIAS openmc) target_compile_options(openmc PRIVATE ${cxxflags}) target_include_directories(openmc PRIVATE ${CMAKE_BINARY_DIR}/include) +target_include_directories(openmc PRIVATE ${CMAKE_SOURCE_DIR}/include) target_link_libraries(openmc libopenmc) # Ensure C++17 standard is used and turn off GNU extensions From 22df26a99adce7d436a3c349409cacd54151f9fe Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Tue, 27 Aug 2024 22:43:05 +0100 Subject: [PATCH 26/29] trying to get libopenmc.so found --- CMakeLists.txt | 1 + pyproject.toml | 8 ++++++++ setup.py | 7 ++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c2b39903a94..77ce2e7e264 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -336,6 +336,7 @@ endif() if(SKBUILD) set(CMAKE_INSTALL_RPATH "$ORIGIN") set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/openmc/lib) endif() #=============================================================================== diff --git a/pyproject.toml b/pyproject.toml index c24026300b1..e4556d4106d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,6 +2,9 @@ requires = ["setuptools", "wheel", "numpy", "cython", "scikit-build-core"] build-backend = "scikit_build_core.build" +[tool.scikit-build-core] +generator = "Ninja" + [project] name = "openmc" authors = [ @@ -61,11 +64,13 @@ Issues = "https://github.com/openmc-dev/openmc/issues" [tool.setuptools.packages.find] include = ['openmc*', 'scripts*'] exclude = ['tests*'] +packages = ["find:"] [tool.setuptools.package-data] "openmc.data.effective_dose" = ["*.txt"] "openmc.data" = ["*.txt", "*.DAT", "*.json", "*.h5"] "openmc.lib" = ["libopenmc.dylib", "libopenmc.so"] +"lib" = ["libopenmc.so"] [project.scripts] openmc-ace-to-hdf5 = "scripts.openmc_ace_to_hdf5:main" @@ -89,3 +94,6 @@ before-all = """ yum install -y hdf5 hdf5-devel libpng-devel cmake eigen3-devel gcc gcc-c++ wget """ manylinux-x86_64-image = "manylinux_2_28" + +[tool.setuptools.extension] +libopenmc = {sources = [], libraries = ["openmc"], library-dirs = ["lib"], runtime-library-dirs = ["lib"]} \ No newline at end of file diff --git a/setup.py b/setup.py index f26b3138274..eec492647b9 100755 --- a/setup.py +++ b/setup.py @@ -10,10 +10,15 @@ def __init__(self, name, cmake_lists_dir=".", sources=[], **kwa): Extension.__init__(self, name, sources=sources, **kwa) self.cmake_lists_dir = os.path.abspath(cmake_lists_dir) +lib_dir = os.path.join('openmc', 'lib') +libopenmc_path = os.path.join(lib_dir, 'libopenmc.so') kwargs = { 'ext_modules': [OpenMCExtension('libopenmc')], - 'include_dirs': [np.get_include()] + 'include_dirs': [np.get_include()], + 'package_data': { + 'openmc': [os.path.join('lib', 'libopenmc.so')], + }, } setup(**kwargs) From a7bde522c2ed8450fec07539b59daba82f0695db Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Tue, 27 Aug 2024 22:49:16 +0100 Subject: [PATCH 27/29] correcting dir for lib --- pyproject.toml | 3 +-- setup.py | 11 +++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index e4556d4106d..686cf8fde72 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -70,7 +70,6 @@ packages = ["find:"] "openmc.data.effective_dose" = ["*.txt"] "openmc.data" = ["*.txt", "*.DAT", "*.json", "*.h5"] "openmc.lib" = ["libopenmc.dylib", "libopenmc.so"] -"lib" = ["libopenmc.so"] [project.scripts] openmc-ace-to-hdf5 = "scripts.openmc_ace_to_hdf5:main" @@ -96,4 +95,4 @@ before-all = """ manylinux-x86_64-image = "manylinux_2_28" [tool.setuptools.extension] -libopenmc = {sources = [], libraries = ["openmc"], library-dirs = ["lib"], runtime-library-dirs = ["lib"]} \ No newline at end of file +libopenmc = {sources = [], libraries = ["openmc"], library-dirs = ["openmc/lib"], runtime-library-dirs = ["openmc/lib"]} \ No newline at end of file diff --git a/setup.py b/setup.py index eec492647b9..ab28d391fa5 100755 --- a/setup.py +++ b/setup.py @@ -13,12 +13,19 @@ def __init__(self, name, cmake_lists_dir=".", sources=[], **kwa): lib_dir = os.path.join('openmc', 'lib') libopenmc_path = os.path.join(lib_dir, 'libopenmc.so') +# Ensure the library exists +if not os.path.exists(libopenmc_path): + raise FileNotFoundError(f"Required library {libopenmc_path} not found") + kwargs = { 'ext_modules': [OpenMCExtension('libopenmc')], 'include_dirs': [np.get_include()], 'package_data': { - 'openmc': [os.path.join('lib', 'libopenmc.so')], + 'openmc.lib': ['libopenmc.so'], }, + 'data_files': [ + (lib_dir, [libopenmc_path]), + ], } -setup(**kwargs) +setup(**kwargs) \ No newline at end of file From 37f22ccfac4dcbe5670c75d45625632bf741399e Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Tue, 27 Aug 2024 23:24:06 +0100 Subject: [PATCH 28/29] [skip ci] returned to previous state as error not fixed --- CMakeLists.txt | 2 -- pyproject.toml | 7 ------- setup.py | 16 ++-------------- 3 files changed, 2 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 77ce2e7e264..14047e171d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -336,7 +336,6 @@ endif() if(SKBUILD) set(CMAKE_INSTALL_RPATH "$ORIGIN") set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) - set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/openmc/lib) endif() #=============================================================================== @@ -582,7 +581,6 @@ add_executable(openmc src/main.cpp) add_executable(OpenMC::openmc ALIAS openmc) target_compile_options(openmc PRIVATE ${cxxflags}) target_include_directories(openmc PRIVATE ${CMAKE_BINARY_DIR}/include) -target_include_directories(openmc PRIVATE ${CMAKE_SOURCE_DIR}/include) target_link_libraries(openmc libopenmc) # Ensure C++17 standard is used and turn off GNU extensions diff --git a/pyproject.toml b/pyproject.toml index 686cf8fde72..c24026300b1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,9 +2,6 @@ requires = ["setuptools", "wheel", "numpy", "cython", "scikit-build-core"] build-backend = "scikit_build_core.build" -[tool.scikit-build-core] -generator = "Ninja" - [project] name = "openmc" authors = [ @@ -64,7 +61,6 @@ Issues = "https://github.com/openmc-dev/openmc/issues" [tool.setuptools.packages.find] include = ['openmc*', 'scripts*'] exclude = ['tests*'] -packages = ["find:"] [tool.setuptools.package-data] "openmc.data.effective_dose" = ["*.txt"] @@ -93,6 +89,3 @@ before-all = """ yum install -y hdf5 hdf5-devel libpng-devel cmake eigen3-devel gcc gcc-c++ wget """ manylinux-x86_64-image = "manylinux_2_28" - -[tool.setuptools.extension] -libopenmc = {sources = [], libraries = ["openmc"], library-dirs = ["openmc/lib"], runtime-library-dirs = ["openmc/lib"]} \ No newline at end of file diff --git a/setup.py b/setup.py index ab28d391fa5..f26b3138274 100755 --- a/setup.py +++ b/setup.py @@ -10,22 +10,10 @@ def __init__(self, name, cmake_lists_dir=".", sources=[], **kwa): Extension.__init__(self, name, sources=sources, **kwa) self.cmake_lists_dir = os.path.abspath(cmake_lists_dir) -lib_dir = os.path.join('openmc', 'lib') -libopenmc_path = os.path.join(lib_dir, 'libopenmc.so') - -# Ensure the library exists -if not os.path.exists(libopenmc_path): - raise FileNotFoundError(f"Required library {libopenmc_path} not found") kwargs = { 'ext_modules': [OpenMCExtension('libopenmc')], - 'include_dirs': [np.get_include()], - 'package_data': { - 'openmc.lib': ['libopenmc.so'], - }, - 'data_files': [ - (lib_dir, [libopenmc_path]), - ], + 'include_dirs': [np.get_include()] } -setup(**kwargs) \ No newline at end of file +setup(**kwargs) From fb01690b5bda61f11ba9d7be9eeba6a37c8bc423 Mon Sep 17 00:00:00 2001 From: Jon Shimwell Date: Thu, 29 Aug 2024 08:56:19 +0100 Subject: [PATCH 29/29] changed rpath to lib folder for .so file --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 14047e171d6..ffa682ad111 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -334,7 +334,7 @@ if("${isSystemDir}" STREQUAL "-1") endif() if(SKBUILD) - set(CMAKE_INSTALL_RPATH "$ORIGIN") + set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) endif()