Skip to content

Commit

Permalink
Merge pull request #57 from Qulacs-Osaka/nb-test
Browse files Browse the repository at this point in the history
nanobind
  • Loading branch information
KowerKoint authored Feb 27, 2024
2 parents 005ee76 + f3fe291 commit 1d3ccd0
Show file tree
Hide file tree
Showing 23 changed files with 1,837 additions and 214 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/cpu/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ RUN apt-get update && \
&& apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/*

RUN pip install -U pip \
&& pip install black flake8 openfermion mypy pybind11-stubgen
&& pip install black flake8 isort openfermion mypy nanobind scikit_build nanobind-stubgen

RUN wget https://github.com/Kitware/CMake/releases/download/v3.28.0/cmake-3.28.0-Linux-x86_64.sh -q -O /tmp/cmake-install.sh && \
chmod u+x /tmp/cmake-install.sh && \
Expand Down
3 changes: 2 additions & 1 deletion .devcontainer/cpu/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"/usr/local/include/python3.9",
"build/_deps/eigen_fetch-src",
"build/_deps/googletest_fetch-src/googletest/include",
"build/_deps/pybind11_fetch-src/include"
"/usr/local/lib/python3.10/dist-packages/nanobind/include",
"/usr/include/python3.10"
],
"C_Cpp.default.cppStandard": "c++20"
},
Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/gpu/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ RUN apt-get update && \
&& apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/*

RUN pip install -U pip \
&& pip install black flake8 openfermion mypy pybind11-stubgen
&& pip install black flake8 isort openfermion mypy nanobind scikit_build nanobind-stubgen

RUN wget https://github.com/Kitware/CMake/releases/download/v3.28.0/cmake-3.28.0-Linux-x86_64.sh -q -O /tmp/cmake-install.sh && \
chmod u+x /tmp/cmake-install.sh && \
Expand Down
3 changes: 2 additions & 1 deletion .devcontainer/gpu/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"/usr/include/python3.8",
"build/_deps/eigen_fetch-src",
"build/_deps/googletest_fetch-src/googletest/include",
"build/_deps/pybind11_fetch-src/include"
"/usr/local/lib/python3.10/dist-packages/nanobind/include",
"/usr/include/python3.10"
],
"C_Cpp.default.cppStandard": "c++20"
},
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/ci_ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ jobs:
- name: Install qulacs for Ubuntu
run: CMAKE_BUILD_TYPE=Debug ./script/build_gcc.sh

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

- name: Check stubs
run: |
./script/update_stubs.sh
diff=$(git diff)
echo -n "$diff"
test $(echo -n "$diff" | wc -l) -eq 0
- name: Test in Ubuntu
run: |
ninja test -C build -j $(nproc)
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@
/.vscode
/bin
/build
/typings
61 changes: 38 additions & 23 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,14 @@ endif(NOT DEFINED QULACS_USE_OMP)
if(NOT DEFINED QULACS_USE_CUDA)
set(QULACS_USE_CUDA OFF)
endif(NOT DEFINED QULACS_USE_CUDA)
if(NOT DEFINED QULACS_USE_PYTHON)
set(QULACS_USE_PYTHON OFF)
endif(NOT DEFINED QULACS_USE_PYTHON)
if(NOT DEFINED QULACS_USE_TEST)
set(QULACS_USE_TEST ON)
endif(NOT DEFINED QULACS_USE_TEST)
if(NOT DEFINED QULACS_USE_EXE)
set(QULACS_USE_EXE ON)
endif(NOT DEFINED QULACS_USE_EXE)

message(STATUS "QULACS_USE_PYTHON = ${QULACS_USE_PYTHON}")
message(STATUS "SKBUILD = ${SKBUILD}")
message(STATUS "QULACS_USE_TEST = ${QULACS_USE_TEST}")

### Kokkos options ###
Expand Down Expand Up @@ -53,6 +50,7 @@ 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)

# Eigen
Expand All @@ -68,20 +66,22 @@ if(NOT eigen_fetch_POPULATED)
add_subdirectory(${eigen_fetch_SOURCE_DIR})
endif(NOT eigen_fetch_POPULATED)

# pybind11
if(QULACS_USE_PYTHON)
FetchContent_Declare(
pybind11_fetch
GIT_REPOSITORY https://github.com/pybind/pybind11
GIT_TAG v2.10.0
)
FetchContent_GetProperties(pybind11_fetch)
if(NOT pybind11_fetch_POPULATED)
message(STATUS "Fetch pybind11 for python-binding")
FetchContent_Populate(pybind11_fetch)
add_subdirectory(${pybind11_fetch_SOURCE_DIR})
endif(NOT pybind11_fetch_POPULATED)
endif(QULACS_USE_PYTHON)
# nanobind
if(SKBUILD)
find_package(Python 3.8
REQUIRED COMPONENTS Interpreter Development.Module
OPTIONAL_COMPONENTS Development.SABIModule)
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()

execute_process(
COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE NB_DIR)
list(APPEND CMAKE_PREFIX_PATH "${NB_DIR}")
find_package(nanobind CONFIG REQUIRED)
endif(SKBUILD)

# Google test
if(QULACS_USE_TEST)
Expand All @@ -101,6 +101,7 @@ else()
endif(QULACS_USE_TEST)

add_library(qulacs)
set_property(TARGET qulacs PROPERTY POSITION_INDEPENDENT_CODE ON)

### Compiler options ###
if ((${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") OR (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") OR (${CMAKE_CXX_COMPILER_ID} STREQUAL "AppleClang"))
Expand All @@ -109,8 +110,15 @@ if ((${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") OR (${CMAKE_CXX_COMPILER_ID} STREQ

# Warning
target_compile_options(qulacs PUBLIC
-Wall -Wextra -Wunused-parameter -Wshadow -pedantic
-Wsign-compare -Wtype-limits -Wuninitialized)
-Wall
-Wextra
-Wunused-parameter
# -Wshadow
# -pedantic
-Wsign-compare
-Wtype-limits
-Wuninitialized
)

# Enable pthread
target_compile_options(qulacs PUBLIC -pthread)
Expand All @@ -128,17 +136,24 @@ endif()

### Add subdirectories ###
add_subdirectory(qulacs)
if(QULACS_USE_PYTHON)
if(SKBUILD)
add_subdirectory(python)
endif(QULACS_USE_PYTHON)
endif(SKBUILD)
if(QULACS_USE_TEST)
add_subdirectory(tests)
endif(QULACS_USE_TEST)
if(QULACS_USE_EXE)
add_subdirectory(exe)
endif(QULACS_USE_EXE)

### Custom target ###
# python
if(SKBUILD)
add_custom_target(
python
DEPENDS qulacs_core
)
endif(SKBUILD)

# test
if(QULACS_USE_TEST)
add_custom_target(
Expand Down
9 changes: 9 additions & 0 deletions exe/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from qulacs2023 import *

def main():
a = PauliOperator([0, 60, 2], [2, 3, 1])
print(a.get_XZ_mask_representation())

initialize(InitializationSettings().set_num_threads(8))
main()
finalize()
40 changes: 23 additions & 17 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
[build-system]
requires = ["wheel", "setuptools", "setuptools_scm[toml]"]
build-backend = "setuptools.build_meta"
requires = ["scikit-build-core >=0.4.3", "nanobind >=1.3.2"]
build-backend = "scikit_build_core.build"

[project]
dynamic = ["version"]
name = "qulacs2023"
version = "1.0.0"
description = "Quantum circuit simulator for research"
authors = [
{ name = "Qulacs-Osaka", email = "[email protected]" }
]
readme = "README.md"
requires-python = ">=3.8"
license = { file = "LICENSE" }
dependencies = []
dependencies = [
"scikit_build",
"nanobind"
]
classifiers = [
"Development Status :: 3 - Alpha",
"Environment :: Console",
Expand All @@ -24,11 +28,12 @@ classifiers = [
"Topic :: Communications :: Email"
]

[tool.setuptools.dynamic]
version = {attr = "qulacs._version.__version__"}

[tool.setuptools_scm]
write_to = "pysrc/qulacs/_version.py"
[tool.scikit-build]
minimum-version = "0.4"
# Setuptools-style build caching in a local directory
build-dir = "build/{wheel_tag}"
# Build stable ABI wheels for CPython 3.12+
wheel.py-api = "cp312"

[project.urls]
homepage = "http://www.qulacs.org"
Expand All @@ -37,19 +42,24 @@ homepage = "http://www.qulacs.org"
dev = [
"black",
"flake8",
"openfermion",
"isort",
"mypy",
"pybind11-stubgen"
"nanobind",
"nanobind-stubgen",
"openfermion"
]

test = [
"openfermion"
]

ci = [
"openfermion",
"black",
"flake8",
"isort",
"mypy",
"pybind11-stubgen"
"nanobind-stubgen",
"openfermion"
]

doc = [
Expand All @@ -63,7 +73,3 @@ doc = [
"ipykernel == 6.17.*",
"sphinx-autoapi == 2.0.*"
]

[tool.setuptools]
include-package-data = true
zip-safe = false
1 change: 0 additions & 1 deletion pysrc/qulacs/__init__.py

This file was deleted.

16 changes: 0 additions & 16 deletions pysrc/qulacs/_version.py

This file was deleted.

9 changes: 6 additions & 3 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
cmake_minimum_required(VERSION 3.21)

pybind11_add_module(qulacs_core SHARED EXCLUDE_FROM_ALL binding.cpp)
target_link_libraries(qulacs_core PRIVATE Kokkos::kokkos)
target_link_libraries(qulacs_core PUBLIC qulacs)

message(STATUS "Building library for python...")

nanobind_add_module(qulacs_core STABLE_ABI binding.cpp)
target_link_libraries(qulacs_core PRIVATE qulacs Kokkos::kokkos)
target_include_directories(qulacs_core PRIVATE ${PROJECT_SOURCE_DIR}/qulacs)
install(TARGETS qulacs_core LIBRARY DESTINATION qulacs2023)
Loading

0 comments on commit 1d3ccd0

Please sign in to comment.