Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wheel building with scikit build core #3087

Open
wants to merge 90 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
90 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
3ae207d
Merge branch 'develop' into scikit_build_core_wheel
shimwell Aug 14, 2024
e40cf3b
merge in develop
shimwell Aug 14, 2024
0213392
matching simulation results from ci
jon-proximafusion Aug 14, 2024
6e3e47e
using debug instead of on for DCMAKE_BUILD_TYPE
shimwell Sep 12, 2024
b4b4e3a
scikit-build-core added
ahnaf-tahmid-chowdhury Sep 17, 2024
79ae016
Add rpath
ahnaf-tahmid-chowdhury Sep 20, 2024
394b0f9
Install by scikit-build-core
ahnaf-tahmid-chowdhury Sep 24, 2024
12aec22
update python install doc
ahnaf-tahmid-chowdhury Sep 24, 2024
564cb5f
add support for dev mode
ahnaf-tahmid-chowdhury Sep 24, 2024
1f1faca
update dev doc with skbuild support
ahnaf-tahmid-chowdhury Sep 24, 2024
f4e0faa
Merge branch 'openmc-dev:develop' into scikit_build_core_wheel
shimwell Sep 24, 2024
f88e5ef
Merge branch 'scikit-build-core' into scikit_build_core_wheel
ahnaf-tahmid-chowdhury Sep 24, 2024
f114265
back to -j4 for make
jon-proximafusion Sep 25, 2024
c577d50
adding cmake args to pip install command
jon-proximafusion Sep 25, 2024
ec7e11f
[skip ci] cmake args actual openmc options
jon-proximafusion Sep 25, 2024
03a6744
add manylinux docker
ahnaf-tahmid-chowdhury Sep 30, 2024
556adbb
add gcc and mpi build
ahnaf-tahmid-chowdhury Sep 30, 2024
ef1ca2f
Add openmc options and add more docs
ahnaf-tahmid-chowdhury Sep 30, 2024
ead096d
install openmpi on openmpi stage
ahnaf-tahmid-chowdhury Sep 30, 2024
8a7362e
add /usr/local/lib64 to path
ahnaf-tahmid-chowdhury Sep 30, 2024
9985fab
add workflow
ahnaf-tahmid-chowdhury Sep 30, 2024
65ae22c
remove setup.py
ahnaf-tahmid-chowdhury Sep 30, 2024
ac5648c
remove test stage
ahnaf-tahmid-chowdhury Oct 1, 2024
db8265f
add pypi
ahnaf-tahmid-chowdhury Oct 1, 2024
a205ef7
move python deps to last
ahnaf-tahmid-chowdhury Oct 1, 2024
7036ec6
fix pytest-cov issue
ahnaf-tahmid-chowdhury Oct 2, 2024
1d8e951
fix pytest-cov issue
ahnaf-tahmid-chowdhury Oct 2, 2024
0043634
no need abi
ahnaf-tahmid-chowdhury Oct 2, 2024
9e65e4a
fix path
ahnaf-tahmid-chowdhury Oct 2, 2024
1985003
move openmc to src
ahnaf-tahmid-chowdhury Oct 3, 2024
303f596
no need to copy lib to openmc
ahnaf-tahmid-chowdhury Oct 3, 2024
1813d6e
remove BUILD_EXAMPLES
ahnaf-tahmid-chowdhury Oct 3, 2024
2cbce3b
python deps stage
ahnaf-tahmid-chowdhury Oct 3, 2024
a88e926
Merge remote-tracking branch 'upstream/develop' into scikit_build_cor…
ahnaf-tahmid-chowdhury Oct 3, 2024
d588670
pip install numpy
ahnaf-tahmid-chowdhury Oct 3, 2024
4b08da7
fail-fast: false
ahnaf-tahmid-chowdhury Oct 3, 2024
db2bb3f
sdist.include = ["src/openmc/**"]
ahnaf-tahmid-chowdhury Oct 3, 2024
63e1b26
set DATAROOTDIR
ahnaf-tahmid-chowdhury Oct 4, 2024
cbca837
add vendor packages
ahnaf-tahmid-chowdhury Oct 4, 2024
995c840
add more dirs
ahnaf-tahmid-chowdhury Oct 4, 2024
d68bac5
CMAKE_INSTALL_DATADIR
ahnaf-tahmid-chowdhury Oct 4, 2024
07126a0
no need OpenMCTargets for skbuild
ahnaf-tahmid-chowdhury Oct 5, 2024
bf0f400
install rpath if var is defined
ahnaf-tahmid-chowdhury Oct 5, 2024
12acf73
eval $(ncrystal-config --setup)
ahnaf-tahmid-chowdhury Oct 5, 2024
bf334ce
sdist include *.h5
ahnaf-tahmid-chowdhury Oct 8, 2024
e3398a4
Merge remote-tracking branch 'upstream/develop' into scikit_build_cor…
ahnaf-tahmid-chowdhury Oct 8, 2024
4e69397
setup openmc lib for skbuild
ahnaf-tahmid-chowdhury Oct 17, 2024
4a69b09
prepare for merge
ahnaf-tahmid-chowdhury Oct 17, 2024
3b80c4c
Merge remote-tracking branch 'upstream/develop' into scikit_build_cor…
ahnaf-tahmid-chowdhury Oct 17, 2024
d0740ce
move openmc to src again
ahnaf-tahmid-chowdhury Oct 17, 2024
fbda530
update lib paths
ahnaf-tahmid-chowdhury Oct 17, 2024
0d3f6f2
add include
ahnaf-tahmid-chowdhury Oct 18, 2024
15e34f9
Merge remote-tracking branch 'upstream/develop' into scikit_build_cor…
ahnaf-tahmid-chowdhury Oct 19, 2024
af0f1d5
add openmc.in
ahnaf-tahmid-chowdhury Oct 19, 2024
e2802f3
use OpenMC targets
ahnaf-tahmid-chowdhury Oct 19, 2024
db1d8d1
install source version
ahnaf-tahmid-chowdhury Oct 19, 2024
7a0a56d
add SKBUILDScripts.cmake
ahnaf-tahmid-chowdhury Oct 20, 2024
8dabae4
update get_core_path
ahnaf-tahmid-chowdhury Oct 20, 2024
b8f634c
add /usr/local/lib/ to lib path
ahnaf-tahmid-chowdhury Oct 20, 2024
73cd266
remove file openmc_exec
ahnaf-tahmid-chowdhury Oct 20, 2024
ea6fab9
remove openmc_exec
ahnaf-tahmid-chowdhury Oct 20, 2024
e519189
Allow CMAKE_INSTALL_RPATH_USE_LINK_PATH
ahnaf-tahmid-chowdhury Oct 20, 2024
32d96e2
renamed to GenerateScript.cmake
ahnaf-tahmid-chowdhury Oct 20, 2024
f52ff64
remove SKBUILDScripts
ahnaf-tahmid-chowdhury Oct 20, 2024
d1f8ae3
revert
ahnaf-tahmid-chowdhury Oct 22, 2024
ddb6c96
update to 1.8
ahnaf-tahmid-chowdhury Oct 22, 2024
c1bcb8c
reduced diff
jon-proximafusion Nov 8, 2024
f7441af
Merge branch 'develop' into scikit_build_core_wheel
jon-proximafusion Nov 8, 2024
6065c69
reducing diff
jon-proximafusion Nov 8, 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
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
15 changes: 15 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 Down Expand Up @@ -327,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
#===============================================================================
Expand Down Expand Up @@ -614,3 +624,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
shimwell marked this conversation as resolved.
Show resolved Hide resolved
--------------------------------

.. _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 Options to via pip
shimwell marked this conversation as resolved.
Show resolved Hide resolved
--------------------------------

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 . --global-option="build_ext" --global-option="--" --global-option="-DOPENMC_USE_MPI=ON"
shimwell marked this conversation as resolved.
Show resolved Hide resolved

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"
shimwell marked this conversation as resolved.
Show resolved Hide resolved

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
Copy link
Contributor

Choose a reason for hiding this comment

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

I think, we may not need this file.

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()
9 changes: 8 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -73,3 +74,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 = "openmc.openmc_exec:main"

[tool.scikit-build]
cmake.verbose = true
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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"]
Copy link
Member Author

Choose a reason for hiding this comment

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

In the CI openmc gets built with debug type

    # Build in debug mode by default with support for MCPL
    cmake_cmd = ['cmake', '-DCMAKE_BUILD_TYPE=Debug', '-DOPENMC_USE_MCPL=on']

Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
cmake.args = ["-DCMAKE_BUILD_TYPE=RELEASE"]
cmake.args = ["-DCMAKE_BUILD_TYPE=DEBUG"]

11 changes: 9 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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()]
}

Expand Down
38 changes: 16 additions & 22 deletions tools/ci/gha-install.py
Original file line number Diff line number Diff line change
@@ -1,57 +1,51 @@
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]']
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')
shimwell marked this conversation as resolved.
Show resolved Hide resolved

# 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')
shimwell marked this conversation as resolved.
Show resolved Hide resolved

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()
Expand Down
Loading