Skip to content

Commit

Permalink
Added GPU (test) support and misc. functionalities in Sources and Optics
Browse files Browse the repository at this point in the history
  • Loading branch information
ochubar committed Mar 19, 2024
2 parents c8ead37 + 9338785 commit 8a61040
Show file tree
Hide file tree
Showing 14 changed files with 197 additions and 441 deletions.
160 changes: 160 additions & 0 deletions .github/workflows/pypi_publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
name: PyPI Publish

on:
release:
types: [published]
push:
pull_request:
workflow_dispatch:

jobs:
build-n-publish:
# pull requests are a duplicate of a branch push if within the same repo.
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository

name: ${{ matrix.host-os }} / Python ${{ matrix.python-version }} / OpenMP ${{ matrix.openmp }}
runs-on: ${{ matrix.host-os }}
strategy:
matrix:
host-os: ["ubuntu-latest", "macos-latest", "windows-latest"]
python-version: ["3.8", "3.9", "3.10", "3.11"]
openmp: ["off"]
fail-fast: false

defaults:
run:
shell: bash -l {0}

steps:
- uses: actions/checkout@v3

- name: Set OpenMP mode
if: matrix.openmp == 'on'
run: |
export MODE="omp"
echo "MODE=${MODE}" >> $GITHUB_ENV
- name: Set MacOS Deployment Target
if: runner.os == 'macOS'
run: |
export MACOSX_DEPLOYMENT_TARGET="10.15"
echo "MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET}" >> $GITHUB_ENV
- uses: conda-incubator/setup-miniconda@v2
with:
activate-environment: testenv
allow-softlinks: true
auto-activate-base: false
auto-update-conda: true
channel-priority: flexible
channels: conda-forge
miniconda-version: "latest"
python-version: ${{ matrix.python-version }}
show-channel-urls: true
use-only-tar-bz2: false

- name: Set up Visual Studio shell
if: runner.os == 'Windows'
uses: egor-tensin/vs-shell@v2
with:
arch: x64

- name: Install build requirements with conda
if: runner.os != 'Linux'
run: |
set -vxeuo pipefail
conda install -y cmake
- name: Install OpenMP for macOS with conda
if: runner.os == 'macOS' && matrix.openmp == 'on'
run: |
set -vxeuo pipefail
conda install -y -c conda-forge llvm-openmp
# NOTE: This step is not needed for fast tests.
# - name: Install mpi4py for Unix with conda
# if: runner.os != 'Windows'
# run: |
# set -vxeuo pipefail
# conda install -y -c conda-forge mpi4py openmpi

- name: Install cibuildwheel on Linux
if: runner.os == 'Linux'
run: |
set -vxeuo pipefail
python -m pip install --upgrade pip
python -m pip install cibuildwheel
echo "CIBW_BEFORE_ALL=pip install cmake" >> $GITHUB_ENV
PYTH_VER=${{ matrix.python-version }}
PYTH_VER=${PYTH_VER//.}
echo "CIBW_BUILD="cp$PYTH_VER-manylinux*"" >> $GITHUB_ENV
- name: Build wheel on Linux
if: runner.os == 'Linux'
run: |
set -vxeuo pipefail
python -VV
python -m cibuildwheel --output-dir dist env/python
ls -la dist/*
- name: Build wheel on Windows/Mac
if: runner.os != 'Linux'
run: |
set -vxeuo pipefail
cd env/python
python -VV
python setup.py bdist_wheel
ls -la dist/*
mkdir -p ../../dist
cp dist/*.whl ../../dist/
- name: Publish wheels to GitHub artifacts
uses: actions/upload-artifact@v3
with:
name: wheels
path: dist/*

- name: Install the package and test requirements
run: |
set -vxeuo pipefail
pip install -v dist/*64.whl
# Smoke import test:
python -c "import srwpy; import srwpy.srwlpy"
# Check CLI tools:
srw-viewer --help
python -m pip install -r env/python/requirements-dev.txt
python -m pip list
- name: Run fast tests
run: |
set -vxeuo pipefail
cd env/python
pytest -k fast
publish-to-pypi:
# Hints from:
# - https://github.com/pypa/gh-action-pypi-publish/discussions/28
# - https://github.com/Lightning-AI/lightning/blob/master/.github/workflows/release-pypi.yml
if: github.event_name == 'release'
name: Publish to PyPI
needs: build-n-publish
runs-on: ubuntu-latest
permissions:
id-token: write

steps:
- uses: actions/checkout@v3

- name: Download wheels from GitHub artifacts
uses: actions/download-artifact@v3
with:
name: wheels
path: dist/

- name: Publish wheels to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: ./dist/
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ docs/build/
# Compiled libraries
*.a
*.so
*.pyd

.vscode/
__srwl_logs__/
uti_plot*.png
10 changes: 4 additions & 6 deletions cpp/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ set(srw_clients_c_source_files
../src/clients/c/srwlclient.cpp
)

add_executable(srwlclient ${srw_clients_c_source_files})
add_library(srwlclient STATIC ${srw_clients_c_source_files})

target_link_libraries(srwlclient srw)

Expand All @@ -227,10 +227,8 @@ install(TARGETS srwlclient RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

# python
# for testing we will need the python interpreter
find_package(PythonInterp REQUIRED)

# we require python development headers
find_package(PythonLibs ${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR} EXACT REQUIRED)
find_package(Python COMPONENTS Interpreter Development.Module REQUIRED)


set(srw_clients_python_source_files
Expand All @@ -239,7 +237,7 @@ set(srw_clients_python_source_files

add_library(srwlpy SHARED ${srw_clients_python_source_files})

target_include_directories(srwlpy PUBLIC ${PYTHON_INCLUDE_DIRS})
target_include_directories(srwlpy PUBLIC ${Python_INCLUDE_DIRS})

target_include_directories(srwlpy PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../src/clients/python>)

Expand All @@ -263,7 +261,7 @@ if(APPLE)
endif()

if(WIN32)
target_link_libraries(srwlpy srw ${PYTHON_LIBRARIES})
target_link_libraries(srwlpy srw ${Python_LIBRARIES})
set_target_properties(srwlpy PROPERTIES SUFFIX ".pyd")
endif()

Expand Down
Loading

0 comments on commit 8a61040

Please sign in to comment.