Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
e9101ab
draft scikit build core wheel
shimwell Jul 19, 2024
e857f45
renamed executable
shimwell Jul 19, 2024
61b7035
linking libopenmc with openmc in cmakelists
jon-proximafusion Jul 19, 2024
12cb43d
Merge branch 'scikit_build_core_wheel' of github.com:shimwell/openmc …
jon-proximafusion Jul 19, 2024
2541d50
updated docs for pip install that compiles
jon-proximafusion Jul 19, 2024
f15e80f
pip install with cmake args in ci
jon-proximafusion Jul 23, 2024
3c98d8a
added missing ,
jon-proximafusion Jul 23, 2024
0aafd44
no need for manual creation of build dir
jon-proximafusion Jul 23, 2024
12b4221
[skip ci] merged develop
shimwell Jul 26, 2024
9ef3beb
[skip ci] adding apt packages for read the docs
shimwell Jul 26, 2024
40ceaad
[skip ci] trying ubuntu 22.04
shimwell Jul 26, 2024
2c8cf71
[skip ci] added missing s
shimwell Jul 26, 2024
4c0075f
adding gha actions
shimwell Jul 26, 2024
4de0d94
upper case ON for cmake args
shimwell Jul 26, 2024
688d688
added quotes to cmake args
shimwell Jul 26, 2024
07a4dcd
keeping same filename
shimwell Jul 26, 2024
9253977
running just pytest
shimwell Jul 26, 2024
1f01694
[skip ci] corrected cmake arg passing example
shimwell Jul 26, 2024
6850217
added diagnosis prints
shimwell Jul 27, 2024
a601de8
Merge branch 'scikit_build_core_wheel' of github.com:shimwell/openmc …
shimwell Jul 27, 2024
97a3f22
removed 2nd pip install which was overwritting
shimwell Jul 27, 2024
41d28ff
float_endf from endf package
shimwell Jul 29, 2024
c03a236
removed reference to float endf
shimwell Jul 29, 2024
3cc88a0
removing resonance
jon-proximafusion Aug 7, 2024
f8f9ac4
no longer calling ResonancesWithBackground
jon-proximafusion Aug 8, 2024
1912b6c
Merge pull request #59 from shimwell/scikit_build_core_wheel
shimwell Aug 13, 2024
d3efb24
Merge branch 'wheel_building_without_cython' into replacing_endf_c_fu…
shimwell Aug 13, 2024
3c8fb17
Merge pull request #60 from shimwell/replacing_endf_c_functions_with_…
shimwell Aug 13, 2024
0731b75
Merge pull request #61 from shimwell/removing_reconstruct_resonance_c…
shimwell Aug 13, 2024
a2bc555
[skip ci] removed prints
shimwell Aug 13, 2024
f994293
added action
jon-proximafusion Aug 13, 2024
3ace251
merge dev
shimwell Aug 14, 2024
0b79757
added source dir include
shimwell Aug 27, 2024
22df26a
trying to get libopenmc.so found
shimwell Aug 27, 2024
a7bde52
correcting dir for lib
shimwell Aug 27, 2024
37f22cc
[skip ci] returned to previous state as error not fixed
shimwell Aug 27, 2024
fb01690
changed rpath to lib folder for .so file
jon-proximafusion Aug 29, 2024
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
23 changes: 23 additions & 0 deletions .github/workflows/build_wheels.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 1 addition & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
version: 2

build:
os: "ubuntu-20.04"
os: "ubuntu-22.04"
tools:
python: "3.10"
apt_packages:
- g++
- cmake
- libhdf5-dev
- libpng-dev

sphinx:
configuration: docs/source/conf.py
Expand Down
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -36,6 +41,7 @@ option(OPENMC_USE_MCPL "Enable MCPL"
option(OPENMC_USE_NCRYSTAL "Enable support for NCrystal scattering" OFF)
option(OPENMC_USE_UWUW "Enable UWUW" OFF)


# Warnings for deprecated options
foreach(OLD_OPT IN ITEMS "openmp" "profile" "coverage" "dagmc" "libmesh")
if(DEFINED ${OLD_OPT})
Expand Down Expand Up @@ -327,6 +333,11 @@ if("${isSystemDir}" STREQUAL "-1")
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}")
endif()

if(SKBUILD)
set(CMAKE_INSTALL_RPATH "$ORIGIN/lib")
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
endif()

#===============================================================================
# libopenmc
#===============================================================================
Expand Down Expand Up @@ -614,3 +625,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/bin)
endif()
25 changes: 8 additions & 17 deletions docs/source/quickinstall.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://pip.pypa.io/en/stable/>`_.
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 <https://pip.pypa.io/en/stable/>`_.
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
<usersguide_build>`.
42 changes: 32 additions & 10 deletions docs/source/usersguide/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ feature can be used to access the installed packages.

.. _install_source:

----------------------
Installing from Source
----------------------
--------------------------------
Compiling from source with CMake
--------------------------------

.. _prerequisites:

Expand Down Expand Up @@ -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
++++++++++++++++++++++

Expand Down Expand Up @@ -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 <install_conda>`, no further steps are
necessary in order to use OpenMC's :ref:`Python API <pythonapi>`. However, if
you are :ref:`installing from source <install_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 <install_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
``openmc`` executable (for example, if you are installing the package into a
`virtual environment <https://docs.python.org/3/tutorial/venv.html>`_). The
easiest way to install the :mod:`openmc` Python package is to use pip_, which is
Expand All @@ -527,7 +529,27 @@ distribution/repository, run:
pip will first check that all :ref:`required third-party packages
<usersguide_python_prereqs>` have been installed, and if they are not present,
they will be installed by downloading the appropriate packages from the Python
Package Index (`PyPI <https://pypi.org/>`_).
Package Index (`PyPI <https://pypi.org/>`_). 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 arguments 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<cmake_arguemnts>` are supported.
For example, to build OpenMC with MPI support, you can run:

.. code-block:: sh

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 . --config-settings=cmake.args="-DOPENMC_USE_DAGMC=ON;DDAGMC_ROOT=/path/to/dagmc/installation"

Installing in "Development" Mode
--------------------------------
Expand Down
1 change: 1 addition & 0 deletions openmc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions openmc/openmc_exec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env python3

# helper script that launches the openmc binary

import os
import sys
import sysconfig
from pathlib import Path


def main():
os.execv(
Path(sysconfig.get_path("platlib")) / "openmc" / "bin" / "openmc", sys.argv
)


if __name__ == "__main__":
main()
18 changes: 16 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
requires = ["setuptools", "wheel", "numpy", "cython", "scikit-build-core"]
build-backend = "scikit_build_core.build"

[project]
name = "openmc"
Expand Down Expand Up @@ -75,3 +75,17 @@ 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 = "openmc.openmc_exec:main"

[tool.scikit-build]
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"
19 changes: 19 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env python

import os
import numpy as np
from setuptools import setup, Extension


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 = {
'ext_modules': [OpenMCExtension('libopenmc')],
'include_dirs': [np.get_include()]
}

setup(**kwargs)
39 changes: 17 additions & 22 deletions tools/ci/gha-install.py
Original file line number Diff line number Diff line change
@@ -1,57 +1,52 @@
import os
import shutil
import subprocess


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
cmake_cmd = ['cmake', '-DCMAKE_BUILD_TYPE=Debug', '-DOPENMC_USE_MCPL=on']
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
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))
pip_command.append('--verbose')
# 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()
Expand Down
3 changes: 0 additions & 3 deletions tools/ci/gha-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,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]