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

cmake build #157

Merged
merged 30 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
5ee897c
add cmake build
kleinhenz Feb 17, 2022
77cda35
update targets to match config module
kleinhenz Mar 4, 2022
369c2d2
wip allow setuptools to drive cmake build
kleinhenz Mar 6, 2022
49e0e39
provide edrixs executables as part of python package installation
kleinhenz Mar 7, 2022
bc13801
print CMAKE_COMMAND
kleinhenz Mar 7, 2022
018f802
properly set module filename to include abi info
kleinhenz Mar 7, 2022
5fb9d72
add pyproject.toml to specify required build environment
kleinhenz Mar 7, 2022
b15ba58
remove unnecessary cmake code
kleinhenz Mar 8, 2022
4faec47
set CMAKE_BUILD_TYPE to RelWithDebInfo if not specified
kleinhenz Mar 9, 2022
f5b8c0d
allow passing args to cmake configure via CMAKE_CONFIGURE_ARGS env var
kleinhenz Mar 9, 2022
1cbab54
update install instruction in README
kleinhenz Mar 9, 2022
809ce87
remove unused makefiles
kleinhenz Mar 9, 2022
232d939
delete pdfs from examples directory
kleinhenz Feb 17, 2022
de2046b
update dockerfile
kleinhenz Feb 17, 2022
ad7f35f
make flake8 happy
kleinhenz Mar 10, 2022
b4f0c8a
update install-deps.sh script for new build system
kleinhenz Mar 10, 2022
27b8252
allow python 3.7
kleinhenz Mar 10, 2022
f23207d
update installation.rst
kleinhenz Mar 18, 2022
6af7daf
Merge branch 'master' into develop
mpmdean Aug 30, 2023
ab91da5
update ubuntu version
mpmdean Sep 3, 2023
57b3e35
CI: add steps to upload GHA artifacts
mrakitin Sep 15, 2023
36ea6a8
MNT: move wheels generation step to the beginning
mrakitin Sep 15, 2023
5d1699b
Comment-out wheels building step for now
mrakitin Sep 15, 2023
b1e0b56
make wheel with pip
mpmdean Sep 16, 2023
6be197e
remove pin of setuptools version
mpmdean Sep 16, 2023
4f74e93
CI: add diagnostic checks and update CI env with repo name
mrakitin Sep 19, 2023
c99eb1e
CI: put wheels into a separate dir
mrakitin Sep 19, 2023
982ac1e
CI: back to `python setup.py bdist_wheel`
mrakitin Sep 19, 2023
464e1e7
PKG: fix warnings from CI logs
mrakitin Sep 19, 2023
3c6463f
CI: add pkg name to the wheels artifact
mrakitin Sep 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
.git/
docker/
build
40 changes: 33 additions & 7 deletions .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ name: CI-Test
on: [push, pull_request]

jobs:

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: pre-commit/[email protected]
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- uses: pre-commit/[email protected]

test:
name: Tests
runs-on: ${{ matrix.host-os }}
Expand All @@ -19,23 +21,37 @@ jobs:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
fail-fast: false
steps:
- name: Set env.REPOSITORY_NAME # just the repo, as opposed to org/repo
run: |
export REPOSITORY_NAME=${GITHUB_REPOSITORY#*/}
echo "REPOSITORY_NAME=${REPOSITORY_NAME}" >> $GITHUB_ENV

- name: Checkout the code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
set -vxeuo pipefail
bash ./scripts/install-deps.sh
ls -Al .
ls -Al ./dist/
tree .

- uses: actions/upload-artifact@v3
with:
name: ${{ env.REPOSITORY_NAME }}-wheels
path: dist/*.whl

- name: Test with pytest
run: |
set -vxeuo pipefail
bash ./scripts/run-tests.sh

docs:
name: Documentation
runs-on: ubuntu-latest
Expand All @@ -46,11 +62,16 @@ jobs:
fail-fast: false

steps:
- name: Set env.REPOSITORY_NAME # just the repo, as opposed to org/repo
run: |
export REPOSITORY_NAME=${GITHUB_REPOSITORY#*/}
echo "REPOSITORY_NAME=${REPOSITORY_NAME}" >> $GITHUB_ENV

- name: Checkout the code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

Expand All @@ -63,3 +84,8 @@ jobs:
run: |
set -vxeuo pipefail
bash ./scripts/build-docs.sh

- uses: actions/upload-artifact@v3
with:
name: ${{ env.REPOSITORY_NAME }}-docs
path: docs/build/html/
9 changes: 7 additions & 2 deletions .github/workflows/docs-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ jobs:
echo "REPOSITORY_NAME=${REPOSITORY_NAME}" >> $GITHUB_ENV

- name: Checkout the code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

Expand All @@ -38,6 +38,11 @@ jobs:
set -vxeuo pipefail
bash ./scripts/build-docs.sh

- uses: actions/upload-artifact@v3
with:
name: ${{ env.REPOSITORY_NAME }}-docs
path: docs/build/html/

- name: Deploy documentation to nsls-ii.github.io
# We pin to the SHA, not the tag, for security reasons.
# https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/security-hardening-for-github-actions#using-third-party-actions
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ target/
#pycharm
.idea/*

.vscode/*

#Ipython Notebook
.ipynb_checkpoints
10 changes: 4 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
rev: v4.4.0
hooks:
- id: check-yaml
- id: check-toml
Expand All @@ -10,18 +10,16 @@ repos:
exclude: |
(?x)^(
src/|
docs/|
github_deploy_key_nsls_ii_edrixs.enc
docs/
)
- id: trailing-whitespace
exclude: |
(?x)^(
src/|
docs/|
github_deploy_key_nsls_ii_edrixs.enc
docs/
)
- repo: https://github.com/PyCQA/flake8.git
rev: 4.0.1
rev: 6.1.0
hooks:
- id: flake8
exclude: ^examples/
Expand Down
65 changes: 65 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
cmake_minimum_required(VERSION 3.17.3 FATAL_ERROR) # 3.17 > for Python3_SOABI

project (EDRIXS C Fortran)

if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Build type configuration" FORCE)
message(STATUS "Setting default build type: ${CMAKE_BUILD_TYPE}")
endif()

message(STATUS "CMAKE_COMMAND: ${CMAKE_COMMAND}")
message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)

find_package(MPI REQUIRED)

find_package(LAPACK REQUIRED)

option(EDRIXS_PYINTERFACE "Build python interface" OFF)

# see https://gitlab.kitware.com/cmake/cmake/-/issues/21779
if (CMAKE_VERSION VERSION_LESS 3.20)
if(LAPACK_FOUND)
set(_lapack_libs "${LAPACK_LIBRARIES}")
if(_lapack_libs AND TARGET BLAS::BLAS)
# remove the ${BLAS_LIBRARIES} from the interface and replace it
# with the BLAS::BLAS target
list(REMOVE_ITEM _lapack_libs "${BLAS_LIBRARIES}")
list(APPEND _lapack_libs BLAS::BLAS)
endif()
if(_lapack_libs)
set_target_properties(LAPACK::LAPACK PROPERTIES
INTERFACE_LINK_LIBRARIES "${_lapack_libs}"
)
endif()
unset(_lapack_libs)
endif()
endif()

# use a custom find module because arpack-ng config module doesn't provide full paths to libs
# see https://github.com/opencollab/arpack-ng/pull/311
find_package(arpack MODULE REQUIRED COMPONENTS serial parallel)


if (EDRIXS_PY_INTERFACE)
message(STATUS "Building python interface")
find_package(Python3 3.7 REQUIRED COMPONENTS Interpreter Development NumPy)
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if it will only find Python 3.7 in this case... I guess we can keep it for now and see what happens when we remove py37 support.


# Grab the variables from a local Python installation
# F2PY headers
execute_process(
COMMAND "${Python3_EXECUTABLE}"
-c "import numpy.f2py; print(numpy.f2py.get_include())"
OUTPUT_VARIABLE F2PY_INCLUDE_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)

message(STATUS "Python3_INCLUDE_DIRS: ${Python3_INCLUDE_DIRS}")
message(STATUS "F2PY_INCLUDE_DIR: ${F2PY_INCLUDE_DIR}")
message(STATUS "Python3_NumPy_INCLUDE_DIRS: ${Python3_NumPy_INCLUDE_DIRS}")
endif()

add_subdirectory(src)
26 changes: 4 additions & 22 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,31 +103,13 @@ Install from source

Be sure to compile OpenBLAS, arpack-ng, mpi4py and edrixs with the same (MPI) Fortran compiler.

* Install Fortran parts of edrixs
* Install edrixs

.. code-block:: bash

$ cd src
$ make F90=mpif90 LIBS="-L/usr/local/lib -lopenblas -lparpack -larpack"
$ make install
$ pip install -v .

where, you may need to change ``F90`` and ``LIBS`` according to your specific environment. There will be problems when using gfortran with MKL, so we recommend ``gfortran+OpenBLAS`` or ``ifort+MKL``. ``libedrixsfortran.a`` will be generated, which will be used when building python interface. The executable ``.x`` files will be installed in ``edrixs/bin`` directory and add the following line in ``.bashrc`` or ``.bash_profile`` file,

.. code-block:: bash

export PATH=/root_dir_of_edrixs/edrixs/bin:$PATH

* Install Python parts of edrixs

Be sure to first make ``libedrixsfortran.a`` in src.

.. code-block:: bash

$ python setup.py config_fc --f77exec=mpif90 --f90exec=mpif90 build_ext \
--libraries=openblas,parpack,arpack --library-dirs=/usr/lib:/usr/local/lib:/opt/local/lib \
--link-objects=./src/libedrixsfortran.a
$ pip install .

where, ``--library-dirs`` ares the paths to search ``--libraries``, please set it according to your environments.
There will be problems when using gfortran with MKL, so we recommend ``gfortran+OpenBLAS`` or ``ifort+MKL``. The executable ``.x`` files will be installed in the ``bin`` directory of the active python environment.
The fortran library and compiled python extension are built using ``cmake`` which can be configured by setting the ``CMAKE_CONFIGURE_ARGS`` environment variable.

Please see our `online documentation <https://nsls-ii.github.io/edrixs/user/installation.html>`_ for more details of installation.
50 changes: 50 additions & 0 deletions cmake/Findarpack.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
include(FindPackageHandleStandardArgs)

message(STATUS "Finding arpack")

# if components not specified default to serial library
set(_supported_components serial parallel)
if(NOT arpack_FIND_COMPONENTS)
set(arpack_FIND_COMPONENTS serial)
endif()

# check request components
foreach(_component ${arpack_FIND_COMPONENTS})
if (NOT ${_component} IN_LIST _supported_components)
message(FATAL_ERROR "${_component} is not a valid component (serial,parallel)")
endif()
endforeach()

message(STATUS "${arpack_FIND_COMPONENTS}")

if(DEFINED ENV{ARPACK_ROOT})
set(ARPACK_ROOT "$ENV{ARPACK_ROOT}")
endif()

set(arpack_serial_FOUND FALSE)
set(arpack_parallel_FOUND FALSE)
set(arpack_LIBRARIES "")

if ("serial" IN_LIST arpack_FIND_COMPONENTS)
find_library(ARPACK_LIBRARY NAMES arpack HINTS ${ARPACK_ROOT})
if(ARPACK_LIBRARY)
set(arpack_serial_FOUND TRUE)
message(STATUS "ARPACK_LIBRARY: ${ARPACK_LIBRARY}")
add_library(ARPACK::ARPACK INTERFACE IMPORTED)
set_target_properties(ARPACK::ARPACK PROPERTIES INTERFACE_LINK_LIBRARIES "${ARPACK_LIBRARY}")
list(APPEND arpack_LIBRARIES ${ARPACK_LIBRARY})
endif()
endif()

if ("parallel" IN_LIST arpack_FIND_COMPONENTS)
find_library(PARPACK_LIBRARY NAMES parpack HINTS ${ARPACK_ROOT})
if(PARPACK_LIBRARY)
set(arpack_parallel_FOUND TRUE)
message(STATUS "PARPACK_LIBRARY: ${PARPACK_LIBRARY}")
add_library(PARPACK::PARPACK INTERFACE IMPORTED)
set_target_properties(PARPACK::PARPACK PROPERTIES INTERFACE_LINK_LIBRARIES "${PARPACK_LIBRARY}")
list(APPEND arpack_LIBRARIES ${PARPACK_LIBRARY})
endif()
endif()

find_package_handle_standard_args(arpack REQUIRED_VARS "arpack_LIBRARIES" HANDLE_COMPONENTS)
89 changes: 69 additions & 20 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,69 @@
FROM edrixs/edrixs_base
WORKDIR /project

COPY . ./src/edrixs

# build fortran part of edrixs
RUN export LD_LIBRARY_PATH="/usr/local/lib:\$LD_LIBRARY_PATH" \
&& make -C src/edrixs/src F90=mpif90 LIBS="-L/usr/local/lib -lopenblas -lparpack -larpack" \
&& make install -C src/edrixs/src \
# build python part of edrixs
&& cd src/edrixs \
&& python setup.py build_ext --library-dirs=/usr/local/lib \
&& pip install . \
&& cd ../../ \
# set env
&& echo "export PATH=/project/src/edrixs/bin:\$PATH" >> ~/.bashrc \
&& echo "export PATH=/project/src/edrixs/bin:\$PATH" >> /home/rixs/.bashrc \
# copy examples to /home/rixs
&& cp -r src/edrixs/examples /home/rixs/edrixs_examples \
&& chown -R rixs:rixs /home/rixs/edrixs_examples
FROM ubuntu:22.04 as base

# general environment for docker
ENV DEBIAN_FRONTEND=noninteractive

# base packages
RUN apt-get update && apt-get install -y --no-install-recommends sudo curl vim libgfortran-11-dev libopenmpi-dev libopenblas-dev python3 libpython3-dev python3-pip python3-venv && rm -rf /var/lib/apt/lists/*

# create docker user
RUN useradd -m -s /bin/bash -u 1999 docker && echo "docker:docker" | chpasswd && adduser docker sudo

# enable passwordless sudo
RUN echo "docker ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/docker

# allow docker user to install into /opt
RUN sudo chown docker:docker /opt

USER docker
WORKDIR /home/docker

# create venv
ENV VIRTUAL_ENV=/opt/edrixs
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

FROM base as dep_builder

ENV LD_LIBRARY_PATH="/opt/edrixs/lib" \
CMAKE_PREFIX_PATH="/opt/edrixs"

# install build tools
RUN sudo apt-get update && sudo apt-get install -y --no-install-recommends \
autoconf \
build-essential \
gfortran \
ca-certificates \
coreutils \
curl \
git \
cmake

RUN curl -L https://github.com/opencollab/arpack-ng/archive/refs/tags/3.8.0.tar.gz | tar xvz && \
cd arpack-ng-3.8.0 && \
mkdir build && \
cd build && \
cmake -DMPI=ON -DCMAKE_INSTALL_PREFIX=/opt/edrixs .. && \
make -j4 && \
make test && \
make install

FROM dep_builder as app_builder

RUN pip install --upgrade pip setuptools
RUN pip install numpy scipy sympy matplotlib sphinx mpi4py ipython jupyter jupyterlab

COPY --chown=docker . edrixs

RUN export VERBOSE=1 FFLAGS="-Wall -Wunused -Wextra -Wno-maybe-uninitialized -Ofast -faggressive-loop-optimizations -fno-tree-pre" && \
pip install -v ./edrixs

from base as app

# see https://github.com/open-mpi/ompi/issues/4948
ENV LD_LIBRARY_PATH="/opt/edrixs/lib" \
CMAKE_PREFIX_PATH="/opt/edrixs" \
OMPI_MCA_btl_vader_single_copy_mechanism="none"

COPY --from=app_builder /opt /opt
COPY --from=app_builder --chown=docker /home/docker/edrixs/examples examples
Loading
Loading