Skip to content

Commit

Permalink
Merge pull request #174 from qulacs/137-macos
Browse files Browse the repository at this point in the history
MacOS Support
  • Loading branch information
KowerKoint authored Sep 27, 2024
2 parents a767bef + fc09b84 commit 23facd6
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 165 deletions.
129 changes: 0 additions & 129 deletions .github/workflows/ci_ubuntu.yml

This file was deleted.

40 changes: 40 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Format

on:
push:
paths-ignore:
- ".devcontainer/**"
- ".vscode/**"
- "doc/**"
- "*.md"
pull_request:
paths-ignore:
- ".devcontainer/**"
- ".vscode/**"
- "doc/**"
- "*.md"

jobs:
check-format:
name: Check Format
runs-on: "ubuntu-22.04"
steps:
- uses: actions/checkout@v4

- name: Setup cmake
uses: lukka/get-cmake@latest

- name: Install Ninja
run: sudo apt install ninja-build

- name: Configure
run: |
mkdir -p ./build
cmake -B build -G Ninja
- name: Check format
run: |
ninja -C build format
diff=$(git diff)
echo -n "$diff"
test $(echo -n "$diff" | wc -l) -eq 0
97 changes: 97 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Build and Test

on:
push:
paths-ignore:
- ".devcontainer/**"
- ".vscode/**"
- "doc/**"
- "*.md"
pull_request:
paths-ignore:
- ".devcontainer/**"
- ".vscode/**"
- "doc/**"
- "*.md"

jobs:
test:
name: Build and Test
strategy:
matrix:
os: ["linux", "macos"]
architecture: ["x86_64"]
device: ["cpu", "cuda"]
python-version: ["3.10"]
exclude:
- os: "macos"
device: "cuda"
include:
- os: "linux"
architecture: "x86_64"
runs-on: "ubuntu-22.04"
- os: "macos"
architecture: "x86_64"
runs-on: "macos-13"
runs-on: ${{ matrix.runs-on }}
env:
CMAKE_C_COMPILER: ${{ matrix.os == 'macos' && '/usr/local/opt/ccache/libexec/gcc-14' || '/usr/lib/ccache/gcc' }}
CMAKE_CXX_COMPILER: ${{ matrix.os == 'macos' && '/usr/local/opt/ccache/libexec/g++-14' || '/usr/lib/ccache/g++' }}
CMAKE_BUILD_TYPE: ${{ matrix.device == 'cuda' && 'Release' || 'Debug' }}
SCALUQ_USE_TEST: "ON"
SCALUQ_USE_CUDA: ${{ matrix.device == 'cuda' && 'ON' || 'OFF' }}
SCALUQ_CUDA_ARCH: "PASCAL61"
steps:
- uses: actions/checkout@v4

- name: Install Ninja
if: ${{ matrix.os == 'linux' }}
run: sudo apt update && sudo apt install ninja-build

- name: Install Ninja
if: ${{ matrix.os == 'macos' }}
run: brew install ninja

- name: Setup ccache
uses: hendrikmuhs/[email protected]
with:
key: "${{ github.job }}-${{ matrix.os }}-${{ matrix.device }}"
verbose: 2

- name: Install CUDA toolkit
if: ${{ matrix.device == 'cuda' }}
uses: Jimver/[email protected]
with:
cuda: "12.2.0"
method: "network"

- name: Show installed Compiler version
run: |
[ $SCALUQ_USE_CUDA = 'ON' ] && nvcc --version
ccache --version
$CMAKE_C_COMPILER --version
$CMAKE_CXX_COMPILER --version
cmake --version
ninja --version
- name: Install scaluq for Ubuntu
run: ./script/build_gcc.sh

- name: Install scaluq Python module
run: pip install .[ci]

- name: Test in Ubuntu
if: ${{ matrix.device == 'cpu' }} # currently GPU runner is not supported
run: |
if [ "$(uname)" == 'Darwin' ]; then
NPROC=$(sysctl -n hw.logicalcpu)
else
NPROC=$(nproc)
fi
OMP_PROC_BIND=false ninja test -C build -j ${NPROC}
- name: Test if stub exists
if: ${{ matrix.device == 'cpu' }} # currently GPU runner is not supported
run: |
echo -e "from scaluq import StateVector\nfrom scaluq.gate import I" > /tmp/stub_sample.py
mypy /tmp/stub_sample.py
22 changes: 16 additions & 6 deletions .github/workflows/wheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,18 @@ jobs:
strategy:
fail-fast: false
matrix:
os-arch: ["manylinux_x86_64"]
os: ["linux", "macos"]
arch: ["x86_64"]
cibw-python: ["cp38", "cp39", "cp310", "cp311", "cp312"]
include:
- os-arch: "manylinux_x86_64"
os: "ubuntu-22.04"
- os: "linux"
arch: "x86_64"
runs-on: "ubuntu-22.04"
cibw-os-arch: "manylinux_x86_64"
- os: "macos"
arch: "x86_64"
runs-on: "macos-13"
cibw-os-arch: "macosx_x86_64"
- cibw-python: "cp38"
python-version: "3.8"
- cibw-python: "cp39"
Expand All @@ -33,10 +40,13 @@ jobs:
python-version: "3.11"
- cibw-python: "cp312"
python-version: "3.12"
runs-on: ${{ matrix.os }}
runs-on: ${{ matrix.runs-on }}
env:
CIBW_BUILD: ${{ matrix.cibw-python }}-${{ matrix.os-arch }}
CMAKE_C_COMPILER: ${{ matrix.os == 'macos' && 'gcc-14' || 'gcc' }}
CMAKE_CXX_COMPILER: ${{ matrix.os == 'macos' && 'g++-14' || 'g++' }}
CIBW_BUILD: ${{ matrix.cibw-python }}-${{ matrix.cibw-os-arch }}
PYTHON: ${{ matrix.python-version }}
MACOSX_DEPLOYMENT_TARGET: "13.0"
steps:
- uses: actions/checkout@v4

Expand All @@ -53,7 +63,7 @@ jobs:
- name: Upload wheel to GitHub
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.cibw-python }}-${{ matrix.os-arch }}
name: ${{ matrix.cibw-python }}-${{ matrix.cibw-os-arch }}
path: ./wheels/*.whl

- name: Upload wheel data if the Git tag is set
Expand Down
37 changes: 13 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,20 @@ endif(SCALUQ_USE_CUDA)
### Fetch dependencies ###
# Kokkos
FetchContent_Declare(
kokkos_fetch
kokkos
GIT_REPOSITORY https://github.com/kokkos/kokkos
GIT_TAG 4.2.00
)
FetchContent_GetProperties(kokkos_fetch)
if(NOT kokkos_fetch_POPULATED)
message(STATUS "Fetch Kokkos for parallel execution")
FetchContent_Populate(kokkos_fetch)
add_subdirectory(${kokkos_fetch_SOURCE_DIR})
set_property(TARGET kokkoscore PROPERTY POSITION_INDEPENDENT_CODE ON)
endif(NOT kokkos_fetch_POPULATED)
FetchContent_MakeAvailable(kokkos)
set_property(TARGET kokkoscore PROPERTY POSITION_INDEPENDENT_CODE ON)

# Eigen
FetchContent_Declare(
eigen_fetch
eigen
GIT_REPOSITORY https://gitlab.com/libeigen/eigen
GIT_TAG 3.4.0
)
FetchContent_GetProperties(eigen_fetch)
if(NOT eigen_fetch_POPULATED)
message(STATUS "Fetch Eigen for matrix operation")
FetchContent_Populate(eigen_fetch)
add_subdirectory(${eigen_fetch_SOURCE_DIR})
endif(NOT eigen_fetch_POPULATED)
FetchContent_MakeAvailable(eigen)

# nanobind
if(SKBUILD)
Expand All @@ -88,16 +78,11 @@ endif(SKBUILD)
# Google test
if(SCALUQ_USE_TEST)
FetchContent_Declare(
googletest_fetch
googletest
GIT_REPOSITORY https://github.com/google/googletest
GIT_TAG release-1.12.1
)
FetchContent_GetProperties(googletest_fetch)
if(NOT googletest_fetch_POPULATED)
message(STATUS "Fetch googletest for C++ testing")
FetchContent_Populate(googletest_fetch)
add_subdirectory(${googletest_fetch_SOURCE_DIR})
endif()
FetchContent_MakeAvailable(googletest)
else()
message(STATUS "Skip downloding googletest")
endif(SCALUQ_USE_TEST)
Expand Down Expand Up @@ -140,8 +125,12 @@ if ((${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") OR (${CMAKE_CXX_COMPILER_ID} STREQ
endif()

# Debug options
target_compile_options(scaluq PUBLIC $<IF:$<CONFIG:Debug>,-O0 -g -fsanitize=address$<COMMA>undefined,-O3>)
target_link_options(scaluq PUBLIC $<$<CONFIG:Debug>:-fsanitize=address$<COMMA>undefined>)
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
target_compile_options(scaluq PUBLIC $<IF:$<CONFIG:Debug>,-O0 -g,-O3>)
else()
target_compile_options(scaluq PUBLIC $<IF:$<CONFIG:Debug>,-O0 -g -fsanitize=address$<COMMA>undefined,-O3>)
target_link_options(scaluq PUBLIC $<$<CONFIG:Debug>:-fsanitize=address$<COMMA>undefined>)
endif()
endif()

### Add subdirectories ###
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ metadata.version.provider = "scikit_build_core.metadata.setuptools_scm"
sdist.include = ["python/scaluq/_version.py"]

[tool.scikit-build.cmake.define]
CMAKE_C_COMPILER = {env="CMAKE_C_COMPILER", default="gcc"}
CMAKE_CXX_COMPILER = {env="CMAKE_CXX_COMPILER", default="g++"}
SCALUQ_USE_OMP = {env="SCALUQ_USE_OMP", default="Yes"}
SCALUQ_USE_CUDA = {env="SCALUQ_USE_CUDA", default="No"}
SCALUQ_CUDA_ARCH = {env="SCALUQ_CUDA_ARCH"}
Expand Down
Loading

0 comments on commit 23facd6

Please sign in to comment.