From 73ffb3996f8863ed9846a49729df247450b94f5a Mon Sep 17 00:00:00 2001 From: Mikhail Andrenkov Date: Tue, 11 May 2021 16:56:50 -0400 Subject: [PATCH 01/18] Add Python build target and Version.hpp bindings --- CMakeLists.txt | 61 +++++++++++++++++++++++++++++------------- src/Python.cpp | 11 ++++++++ src/python/Version.hpp | 22 +++++++++++++++ 3 files changed, 75 insertions(+), 19 deletions(-) create mode 100644 src/Python.cpp create mode 100644 src/python/Version.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index a8a5e66b..3232c8fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ ########################## ## Set Project version ########################## -cmake_minimum_required(VERSION 3.13) +cmake_minimum_required(VERSION 3.14) set(JET_LOGO " ▄▄ ▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄ ██ ██▀▀▀▀▀▀ ▀▀▀██▀▀▀ @@ -30,11 +30,12 @@ option(ENABLE_NATIVE "Enable native build tuning" OFF) option(ENABLE_IPO "Enable interprocedural/link-time optimisation" OFF) # Build options +option(BUILD_PYTHON "Generate Python bindings" OFF) +option(BUILD_TESTS "Build tests" OFF) if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Default build type: Release" FORCE) endif() -option(BUILD_TESTS "Build tests" OFF) ########################## ## Enfore Compiler Support @@ -88,7 +89,7 @@ endif() ########################## -## Fetch Taskflow +## Fetch dependencies ########################## Include(FetchContent) @@ -97,31 +98,30 @@ FetchContent_Declare( GIT_REPOSITORY https://github.com/taskflow/taskflow.git GIT_TAG v3.1.0 ) +FetchContent_Declare( + Pybind11 + GIT_REPOSITORY https://github.com/pybind/pybind11.git + GIT_TAG v2.6.2 +) -# FetchContent_MakeAvailable() requires CMake 3.14 or newer. -FetchContent_GetProperties(Taskflow) -if(NOT Taskflow_POPULATED) - FetchContent_Populate(Taskflow) - # Don't build the Taskflow tests or examples. - set(TF_BUILD_EXAMPLES OFF CACHE INTERNAL "Build Taskflow examples") - set(TF_BUILD_TESTS OFF CACHE INTERNAL "Build Taskflow tests") - add_subdirectory(${taskflow_SOURCE_DIR} ${taskflow_BINARY_DIR}) +# Don't build the Taskflow tests or examples. +set(TF_BUILD_EXAMPLES OFF CACHE INTERNAL "Build Taskflow examples") +set(TF_BUILD_TESTS OFF CACHE INTERNAL "Build Taskflow tests") + +if(BUILD_PYTHON) + FetchContent_MakeAvailable(Taskflow Pybind11) +else() + FetchContent_MakeAvailable(Taskflow) endif() find_package(OpenMP QUIET) -message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") -message(STATUS "BLAS_LIBRARIES: ${BLAS_LIBRARIES}") -message(STATUS "BLAS_INCLUDE_DIRS: ${BLAS_INCLUDE_DIRS}") -message(STATUS "ENABLE_NATIVE: ${ENABLE_NATIVE}") -message(STATUS "ENABLE_IPO: ${ENABLE_IPO}") - ########################## ## Create Jet target ########################## add_library(Jet INTERFACE) -target_include_directories(Jet INTERFACE +target_include_directories(Jet INTERFACE $ ${BLAS_INCLUDE_DIRS} ) @@ -137,24 +137,47 @@ if (ENABLE_OPENMP AND OPENMP_FOUND) elseif (ENABLE_OPENMP AND NOT OPENMP_FOUND) message(FATAL_ERROR "\nOpenMP is enabled but could not be found") endif() + if(ENABLE_SANITIZERS) target_compile_options(Jet INTERFACE -g -fsanitize=address,undefined) target_link_options(Jet INTERFACE -fsanitize=address,undefined) endif() + if(ENABLE_WARNINGS) target_compile_options(Jet INTERFACE -Wall -Wextra -Werror) endif() + if(ENABLE_NATIVE) target_compile_options(Jet INTERFACE -march=native) endif() + if(ENABLE_IPO) target_compile_options(Jet INTERFACE -flto) endif() ########################## -## Build tests +## Report ########################## +message(STATUS "BLAS_INCLUDE_DIRS: ${BLAS_INCLUDE_DIRS}") +message(STATUS "BLAS_LIBRARIES: ${BLAS_LIBRARIES}") +message(STATUS "BUILD_PYTHON: ${BUILD_PYTHON}") +message(STATUS "BUILD_TESTS: ${BUILD_TESTS}") +message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") +message(STATUS "ENABLE_IPO: ${ENABLE_IPO}") +message(STATUS "ENABLE_NATIVE: ${ENABLE_NATIVE}") +message(STATUS "ENABLE_SANITIZERS: ${ENABLE_SANITIZERS}") +message(STATUS "ENABLE_WARNINGS: ${ENABLE_WARNINGS}") + +########################## +## Build targets +########################## + +if(BUILD_PYTHON) + pybind11_add_module(jet src/Python.cpp) + target_link_libraries(jet PRIVATE Jet) +endif() + if(BUILD_TESTS) enable_testing() add_subdirectory(test) diff --git a/src/Python.cpp b/src/Python.cpp new file mode 100644 index 00000000..642ce326 --- /dev/null +++ b/src/Python.cpp @@ -0,0 +1,11 @@ +#include + +#include "python/Version.hpp" + +PYBIND11_MODULE(jet, m) +{ + m.doc() = "Jet is a library for simulating quantum circuits using tensor " + "network contractions."; + + AddBindingsForVersion(m); +} \ No newline at end of file diff --git a/src/python/Version.hpp b/src/python/Version.hpp new file mode 100644 index 00000000..b238b031 --- /dev/null +++ b/src/python/Version.hpp @@ -0,0 +1,22 @@ +#include + +#include + +namespace py = pybind11; + +/** + * @brief Adds Python bindings for the include/jet/Version.hpp file. + * + * @param m Jet pybind11 module. + */ +void AddBindingsForVersion(py::module_ &m) +{ + m.attr("__version__") = Jet::Version(); + + m.def("version", Jet::Version, R"( + Returns the current Jet version. + + Returns: + String representation of the current Jet version. + )"); +} \ No newline at end of file From 6dfd7fe8baa340f9a80b37389e15acb40f43a075 Mon Sep 17 00:00:00 2001 From: Mikhail Andrenkov Date: Tue, 11 May 2021 17:09:24 -0400 Subject: [PATCH 02/18] Add src/python/Version.hpp to pybind11 source files --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3232c8fd..75d3db0b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -174,7 +174,8 @@ message(STATUS "ENABLE_WARNINGS: ${ENABLE_WARNINGS}") ########################## if(BUILD_PYTHON) - pybind11_add_module(jet src/Python.cpp) + pybind11_add_module(jet src/Python.cpp + src/python/Version.hpp) target_link_libraries(jet PRIVATE Jet) endif() From 33c65c3cab4311f562539db7b7ca07dc7b70b355 Mon Sep 17 00:00:00 2001 From: Mikhail Andrenkov Date: Wed, 12 May 2021 10:14:27 -0400 Subject: [PATCH 03/18] Create changelog entry for 0.2.0 release --- .github/CHANGELOG.md | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index 3623e116..e388d1be 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -1,4 +1,24 @@ -## Release 0.1.0 +## Release 0.2.0 (development release) + +### New features since last release + +* Running CMake with `-DBUILD_PYTHON=ON` now generates Python bindings within a `jet` package. [(#1)](https://github.com/XanaduAI/jet/pull/1) + +### Improvements + +### Breaking Changes + +### Bug Fixes + +### Documentation + +### Contributors + +This release contains contributions from (in alphabetical order): + +[Mikhail Andrenkov](https://github.com/Mandrenkov). + +## Release 0.1.0 (current release) ### New features since last release From 06d3b0acce7644a45db0db35671c3aa0f7c232ba Mon Sep 17 00:00:00 2001 From: Mikhail Andrenkov Date: Wed, 12 May 2021 10:18:50 -0400 Subject: [PATCH 04/18] Add src/ directory to Format workflow --- .github/workflows/format.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index 8f7686d4..60a96b61 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -26,4 +26,4 @@ jobs: uses: actions/checkout@v2 - name: Run formatter - run: ./bin/format --check include test \ No newline at end of file + run: ./bin/format --check include src test \ No newline at end of file From 4f47174f190fe2ae085d08ff8894e7314e611ed6 Mon Sep 17 00:00:00 2001 From: Mikhail Andrenkov Date: Wed, 12 May 2021 10:26:12 -0400 Subject: [PATCH 05/18] Add src/ directory to list of Format workflow paths --- .github/workflows/format.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index 60a96b61..4e982276 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -6,6 +6,7 @@ on: - main paths: - "include/**" + - "src/**" - "test/**" jobs: From f814940df50229bfbe224553303975ee8678f8b6 Mon Sep 17 00:00:00 2001 From: Mikhail Andrenkov Date: Wed, 12 May 2021 14:12:16 -0400 Subject: [PATCH 06/18] Add proper build system support for Python bindings --- .gitignore | 3 +- CMakeLists.txt | 3 +- python/Makefile | 46 ++++++++++++++++++++++++++ python/requirements_test.txt | 3 ++ {src => python/src}/Python.cpp | 2 +- {src/python => python/src}/Version.hpp | 0 python/tests/test_version.py | 14 ++++++++ 7 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 python/Makefile create mode 100644 python/requirements_test.txt rename {src => python/src}/Python.cpp (87%) rename {src/python => python/src}/Version.hpp (100%) create mode 100644 python/tests/test_version.py diff --git a/.gitignore b/.gitignore index c709e58a..f7fc3e3f 100644 --- a/.gitignore +++ b/.gitignore @@ -41,8 +41,9 @@ build # CMake build artifacts include/jet/CmakeMacros.hpp -# Python virtualenv +# Python .venv +__pycache__ # Sphinx documentation docs/__pycache__/* diff --git a/CMakeLists.txt b/CMakeLists.txt index 75d3db0b..58d10b24 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -174,8 +174,7 @@ message(STATUS "ENABLE_WARNINGS: ${ENABLE_WARNINGS}") ########################## if(BUILD_PYTHON) - pybind11_add_module(jet src/Python.cpp - src/python/Version.hpp) + pybind11_add_module(jet python/src/Python.cpp) target_link_libraries(jet PRIVATE Jet) endif() diff --git a/python/Makefile b/python/Makefile new file mode 100644 index 00000000..4ee72c94 --- /dev/null +++ b/python/Makefile @@ -0,0 +1,46 @@ +.VENV_DIR=.venv +.VENV_BIN=$(.VENV_DIR)/bin + +python=python3 + +define HELP_BODY +Please use 'make [target]'. + +TARGETS + + setup [python=] Set up virtualenv using the Python interpreter at , defaults to $(python) + + test Run tests + + format [check=1] Apply formatters; use with 'check=1' to check instead of modify + + clean Remove all build artifacts + +endef + +.PHONY: help +help: + @: $(info $(HELP_BODY)) + +.PHONY: setup +setup: $(.VENV_DIR) requirements_test.txt + $(.VENV_DIR)/bin/pip install -r requirements_test.txt + +.PHONY: format +format: +ifdef check + $(.VENV_BIN)/black --check tests && $(.VENV_BIN)/isort --profile black --check-only tests +else + $(.VENV_BIN)/black tests && $(.VENV_BIN)/isort --profile black tests +endif + +.PHONY: test +test: setup + PYTHONPATH="../build" $(.VENV_BIN)/python -m pytest + +.PHONY: clean +clean: + rm -rf $(.VENV_DIR) + +$(.VENV_DIR): + $(python) -m venv $@ diff --git a/python/requirements_test.txt b/python/requirements_test.txt new file mode 100644 index 00000000..804d570d --- /dev/null +++ b/python/requirements_test.txt @@ -0,0 +1,3 @@ +black +isort>5 +pytest>=5,<6 diff --git a/src/Python.cpp b/python/src/Python.cpp similarity index 87% rename from src/Python.cpp rename to python/src/Python.cpp index 642ce326..225c2a47 100644 --- a/src/Python.cpp +++ b/python/src/Python.cpp @@ -1,6 +1,6 @@ #include -#include "python/Version.hpp" +#include "Version.hpp" PYBIND11_MODULE(jet, m) { diff --git a/src/python/Version.hpp b/python/src/Version.hpp similarity index 100% rename from src/python/Version.hpp rename to python/src/Version.hpp diff --git a/python/tests/test_version.py b/python/tests/test_version.py new file mode 100644 index 00000000..9e1170f2 --- /dev/null +++ b/python/tests/test_version.py @@ -0,0 +1,14 @@ +import re + +import jet + + +class TestVersion: + def test_attribute(self): + """Tests that the version attribute has the correct form.""" + semver_pattern = re.compile(r"^\d+\.\d+\.\d+$") + assert semver_pattern.match(jet.__version__) + + def test_function(self): + """Tests that the version attribute matches the version function.""" + assert jet.__version__ == jet.version() From a7526f76bdbbb1c52fcce29238178d179e4cc4a8 Mon Sep 17 00:00:00 2001 From: Mikhail Andrenkov Date: Wed, 12 May 2021 14:25:42 -0400 Subject: [PATCH 07/18] Restore requirements_test.txt touch file --- python/Makefile | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/python/Makefile b/python/Makefile index 4ee72c94..8734f6f1 100644 --- a/python/Makefile +++ b/python/Makefile @@ -23,8 +23,7 @@ help: @: $(info $(HELP_BODY)) .PHONY: setup -setup: $(.VENV_DIR) requirements_test.txt - $(.VENV_DIR)/bin/pip install -r requirements_test.txt +setup: $(.VENV_DIR)/requirements_test.txt.touch .PHONY: format format: @@ -35,12 +34,17 @@ else endif .PHONY: test -test: setup +test: $(.VENV_DIR)/requirements_test.txt.touch PYTHONPATH="../build" $(.VENV_BIN)/python -m pytest .PHONY: clean clean: rm -rf $(.VENV_DIR) -$(.VENV_DIR): - $(python) -m venv $@ +$(.VENV_DIR)/requirements_test.txt.touch: $(.VENV_DIR)/touch requirements_test.txt + $(.VENV_DIR)/bin/pip install -r requirements_test.txt + @touch $@ + +$(.VENV_DIR)/touch: + $(python) -m venv ${.VENV_DIR} + @touch $@ \ No newline at end of file From 98d41aeeab4bb5684cc4402c1af3325175bbe664 Mon Sep 17 00:00:00 2001 From: Mikhail Andrenkov Date: Wed, 12 May 2021 14:39:22 -0400 Subject: [PATCH 08/18] Create GitHub Actions workflow for Python bindings --- .github/workflows/python.yml | 77 ++++++++++++++++++++++++++++++++++++ python/Makefile | 4 +- 2 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/python.yml diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml new file mode 100644 index 00000000..acff073a --- /dev/null +++ b/.github/workflows/python.yml @@ -0,0 +1,77 @@ +name: Python +on: + pull_request: + push: + branches: + - main + paths-ignore: + - ".github/**" + - "docs/**" + - "README.rst" + +jobs: + test-ubuntu: + name: Build (Ubuntu) + runs-on: ubuntu-20.04 + + steps: + - name: Cancel previous runs + uses: styfle/cancel-workflow-action@0.4.1 + with: + access_token: ${{ github.token }} + + - name: Install dependencies + run: sudo apt install -y libopenblas-dev python3.8-dev + + - name: Checkout code + uses: actions/checkout@v2 + + - name: Initialize build directory + run: | + mkdir build + cd build + cmake -DBUILD_PYTHON=ON ../ + + - name: Build Jet + run: | + cd build + make -j`nproc` + + - name: Run tests + run: | + cd python + make setup + make test + + test-macos: + name: Build (MacOS) + runs-on: macos-10.15 + + steps: + - name: Cancel previous runs + uses: styfle/cancel-workflow-action@0.4.1 + with: + access_token: ${{ github.token }} + + - name: Install dependencies + run: brew install libomp + + - name: Checkout code + uses: actions/checkout@v2 + + - name: Initialize build directory + run: | + mkdir build + cd build + cmake -DBUILD_PYTHON=ON ../ + + - name: Build Jet + run: | + cd build + make -j`sysctl -n hw.physicalcpu` + + - name: Run tests + run: | + cd python + make setup + make test \ No newline at end of file diff --git a/python/Makefile b/python/Makefile index 8734f6f1..648b1d00 100644 --- a/python/Makefile +++ b/python/Makefile @@ -10,7 +10,7 @@ TARGETS setup [python=] Set up virtualenv using the Python interpreter at , defaults to $(python) - test Run tests + test [args=] Run tests; use with 'args=' to pass test arguments format [check=1] Apply formatters; use with 'check=1' to check instead of modify @@ -35,7 +35,7 @@ endif .PHONY: test test: $(.VENV_DIR)/requirements_test.txt.touch - PYTHONPATH="../build" $(.VENV_BIN)/python -m pytest + PYTHONPATH="../build" $(.VENV_BIN)/python -m pytest ./tests $(args) .PHONY: clean clean: From 5e4df993986ab7614101bd6c228ccde687a6ffd4 Mon Sep 17 00:00:00 2001 From: Mikhail Andrenkov Date: Wed, 12 May 2021 14:46:15 -0400 Subject: [PATCH 09/18] Move 'make setup' to independent step --- .github/workflows/python.yml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index acff073a..19e6662b 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -32,15 +32,19 @@ jobs: cd build cmake -DBUILD_PYTHON=ON ../ - - name: Build Jet + - name: Generate Python bindings run: | cd build make -j`nproc` - - name: Run tests + - name: Create virtual environment run: | cd python make setup + + - name: Run tests + run: | + cd python make test test-macos: @@ -65,13 +69,17 @@ jobs: cd build cmake -DBUILD_PYTHON=ON ../ - - name: Build Jet + - name: Generate Python bindings run: | cd build make -j`sysctl -n hw.physicalcpu` - - name: Run tests + - name: Create virtual environment run: | cd python make setup + + - name: Run tests + run: | + cd python make test \ No newline at end of file From f51f0ecb539cf69f59634c94319c814424ee2c25 Mon Sep 17 00:00:00 2001 From: Mikhail Andrenkov Date: Wed, 12 May 2021 14:52:53 -0400 Subject: [PATCH 10/18] Replace src/ directory with python/ directory in formatters --- .github/workflows/format.yml | 4 ++-- Makefile | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index 4e982276..9e223d46 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -6,7 +6,7 @@ on: - main paths: - "include/**" - - "src/**" + - "python/**" - "test/**" jobs: @@ -27,4 +27,4 @@ jobs: uses: actions/checkout@v2 - name: Run formatter - run: ./bin/format --check include src test \ No newline at end of file + run: ./bin/format --check include python test \ No newline at end of file diff --git a/Makefile b/Makefile index ea74e853..795d3f00 100644 --- a/Makefile +++ b/Makefile @@ -30,9 +30,9 @@ help: .PHONY: format format: ifdef check - ./bin/format --check include test + ./bin/format --check include python test else - ./bin/format include test + ./bin/format include python test endif From ec7b40c5bd445ac7fb2dcc4cf3a798653cb3e33c Mon Sep 17 00:00:00 2001 From: Mikhail Andrenkov Date: Wed, 12 May 2021 16:44:56 -0400 Subject: [PATCH 11/18] Acknowledge Jack's migrated contribution to the Tensor.hpp bindings branch --- .github/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index e388d1be..c69337b9 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -16,7 +16,7 @@ This release contains contributions from (in alphabetical order): -[Mikhail Andrenkov](https://github.com/Mandrenkov). +[Mikhail Andrenkov](https://github.com/Mandrenkov) and [Jack Brown](https://github.com/brownj85). ## Release 0.1.0 (current release) From 3fc17513aaf082d82fdfb34db617f71e2d98d7f6 Mon Sep 17 00:00:00 2001 From: Mikhail Andrenkov Date: Wed, 12 May 2021 16:52:49 -0400 Subject: [PATCH 12/18] Replace python/ with python/src/ in formatters --- .github/workflows/format.yml | 4 ++-- Makefile | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index 9e223d46..c7cf439b 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -6,7 +6,7 @@ on: - main paths: - "include/**" - - "python/**" + - "python/src/**" - "test/**" jobs: @@ -27,4 +27,4 @@ jobs: uses: actions/checkout@v2 - name: Run formatter - run: ./bin/format --check include python test \ No newline at end of file + run: ./bin/format --check include python/src test \ No newline at end of file diff --git a/Makefile b/Makefile index 795d3f00..797c206d 100644 --- a/Makefile +++ b/Makefile @@ -30,9 +30,9 @@ help: .PHONY: format format: ifdef check - ./bin/format --check include python test + ./bin/format --check include python/src test else - ./bin/format include python test + ./bin/format include python/src test endif From 85298b01306596ffd953bf1b8132f4ea1a231802 Mon Sep 17 00:00:00 2001 From: Mikhail Andrenkov Date: Thu, 13 May 2021 13:19:53 -0400 Subject: [PATCH 13/18] Declare pybind11 target only if BUILD_PYTHON is ON --- CMakeLists.txt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 58d10b24..361200df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,20 +98,20 @@ FetchContent_Declare( GIT_REPOSITORY https://github.com/taskflow/taskflow.git GIT_TAG v3.1.0 ) -FetchContent_Declare( - Pybind11 - GIT_REPOSITORY https://github.com/pybind/pybind11.git - GIT_TAG v2.6.2 -) -# Don't build the Taskflow tests or examples. +# Don't build the Taskflow examples or tests. set(TF_BUILD_EXAMPLES OFF CACHE INTERNAL "Build Taskflow examples") set(TF_BUILD_TESTS OFF CACHE INTERNAL "Build Taskflow tests") +FetchContent_MakeAvailable(Taskflow) + if(BUILD_PYTHON) - FetchContent_MakeAvailable(Taskflow Pybind11) -else() - FetchContent_MakeAvailable(Taskflow) + FetchContent_Declare( + Pybind11 + GIT_REPOSITORY https://github.com/pybind/pybind11.git + GIT_TAG v2.6.2 + ) + FetchContent_MakeAvailable(Pybind11) endif() find_package(OpenMP QUIET) From 909cd54a0ad998e65b8e043f7eb8ee94104ef9aa Mon Sep 17 00:00:00 2001 From: Mikhail Andrenkov Date: Thu, 13 May 2021 14:11:23 -0400 Subject: [PATCH 14/18] Use FetchContent_MakeAvailable() to fetch Catch2 --- test/CMakeLists.txt | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 52a9994a..221397af 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -9,12 +9,7 @@ FetchContent_Declare( GIT_TAG v2.13.1 ) -# FetchContent_MakeAvailable() requires CMake 3.14 or newer. -FetchContent_GetProperties(Catch2) -if(NOT Catch2_POPULATED) - FetchContent_Populate(Catch2) - add_subdirectory(${catch2_SOURCE_DIR} ${catch2_BINARY_DIR}) -endif() +FetchContent_MakeAvailable(Catch2) target_link_libraries(runner Catch2::Catch2) From 7a36816f78af39c01da54ff476d72ab8d821ebdf Mon Sep 17 00:00:00 2001 From: Mikhail Andrenkov Date: Thu, 13 May 2021 14:51:00 -0400 Subject: [PATCH 15/18] Set indentation to 2 spaces --- CMakeLists.txt | 44 +++++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 361200df..ea4bc49e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,13 +78,13 @@ list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") find_package(MKL QUIET) if(MKL_FOUND) - add_definitions("-DENABLE_MKL") - set(BLAS_INCLUDE_DIRS "${MKL_INCLUDE_DIR}") - set(BLAS_LIBRARIES ${MKL_LIBRARY}) + add_definitions("-DENABLE_MKL") + set(BLAS_INCLUDE_DIRS "${MKL_INCLUDE_DIR}") + set(BLAS_LIBRARIES ${MKL_LIBRARY}) else() - find_package(CBLAS REQUIRED) - set(BLAS_LIBRARIES ${CBLAS_LIBRARIES}) - set(BLAS_INCLUDE_DIRS ${CBLAS_INCLUDE_DIRS}) + find_package(CBLAS REQUIRED) + set(BLAS_LIBRARIES ${CBLAS_LIBRARIES}) + set(BLAS_INCLUDE_DIRS ${CBLAS_INCLUDE_DIRS}) endif() @@ -105,15 +105,6 @@ set(TF_BUILD_TESTS OFF CACHE INTERNAL "Build Taskflow tests") FetchContent_MakeAvailable(Taskflow) -if(BUILD_PYTHON) - FetchContent_Declare( - Pybind11 - GIT_REPOSITORY https://github.com/pybind/pybind11.git - GIT_TAG v2.6.2 - ) - FetchContent_MakeAvailable(Pybind11) -endif() - find_package(OpenMP QUIET) ########################## @@ -132,27 +123,27 @@ target_link_libraries(Jet INTERFACE ${BLAS_LIBRARIES} Taskflow) ## Compile options ########################## -if (ENABLE_OPENMP AND OPENMP_FOUND) - target_link_libraries(Jet INTERFACE OpenMP::OpenMP_CXX) +if(ENABLE_OPENMP AND OPENMP_FOUND) + target_link_libraries(Jet INTERFACE OpenMP::OpenMP_CXX) elseif (ENABLE_OPENMP AND NOT OPENMP_FOUND) - message(FATAL_ERROR "\nOpenMP is enabled but could not be found") + message(FATAL_ERROR "\nOpenMP is enabled but could not be found") endif() if(ENABLE_SANITIZERS) - target_compile_options(Jet INTERFACE -g -fsanitize=address,undefined) - target_link_options(Jet INTERFACE -fsanitize=address,undefined) + target_compile_options(Jet INTERFACE -g -fsanitize=address,undefined) + target_link_options(Jet INTERFACE -fsanitize=address,undefined) endif() if(ENABLE_WARNINGS) - target_compile_options(Jet INTERFACE -Wall -Wextra -Werror) + target_compile_options(Jet INTERFACE -Wall -Wextra -Werror) endif() if(ENABLE_NATIVE) - target_compile_options(Jet INTERFACE -march=native) + target_compile_options(Jet INTERFACE -march=native) endif() if(ENABLE_IPO) - target_compile_options(Jet INTERFACE -flto) + target_compile_options(Jet INTERFACE -flto) endif() ########################## @@ -174,11 +165,10 @@ message(STATUS "ENABLE_WARNINGS: ${ENABLE_WARNINGS}") ########################## if(BUILD_PYTHON) - pybind11_add_module(jet python/src/Python.cpp) - target_link_libraries(jet PRIVATE Jet) + add_subdirectory(python) endif() if(BUILD_TESTS) - enable_testing() - add_subdirectory(test) + enable_testing() + add_subdirectory(test) endif(BUILD_TESTS) From 5ab3217b5a73cea6c4ee37b7eb117c24a43043d5 Mon Sep 17 00:00:00 2001 From: Mikhail Andrenkov Date: Thu, 13 May 2021 14:51:51 -0400 Subject: [PATCH 16/18] Move Python bindings commands to CMake script in python/ directory --- python/CMakeLists.txt | 14 ++++++++++++++ python/Makefile | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 python/CMakeLists.txt diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt new file mode 100644 index 00000000..034725ed --- /dev/null +++ b/python/CMakeLists.txt @@ -0,0 +1,14 @@ +Include(FetchContent) + +FetchContent_Declare( + Pybind11 + GIT_REPOSITORY https://github.com/pybind/pybind11.git + GIT_TAG v2.6.2 +) + +FetchContent_MakeAvailable(Pybind11) + +# The following command also creates a CMake target called "jet". +pybind11_add_module(jet src/Python.cpp) + +target_link_libraries(jet PRIVATE Jet) diff --git a/python/Makefile b/python/Makefile index 648b1d00..7714d4af 100644 --- a/python/Makefile +++ b/python/Makefile @@ -35,7 +35,7 @@ endif .PHONY: test test: $(.VENV_DIR)/requirements_test.txt.touch - PYTHONPATH="../build" $(.VENV_BIN)/python -m pytest ./tests $(args) + PYTHONPATH="../build/python" $(.VENV_BIN)/python -m pytest ./tests $(args) .PHONY: clean clean: From 2e30802d10b3babc612f1ef35f19e76ade88507a Mon Sep 17 00:00:00 2001 From: Mikhail Andrenkov Date: Thu, 13 May 2021 14:59:39 -0400 Subject: [PATCH 17/18] Add Python formatter to GitHub Actions workflow --- .github/workflows/format.yml | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index c7cf439b..4c35187b 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -6,12 +6,12 @@ on: - main paths: - "include/**" - - "python/src/**" + - "python/**" - "test/**" jobs: - format: - name: Format + format-cpp: + name: C++ runs-on: ubuntu-20.04 steps: @@ -27,4 +27,30 @@ jobs: uses: actions/checkout@v2 - name: Run formatter - run: ./bin/format --check include python/src test \ No newline at end of file + run: ./bin/format --check include python/src test + + format-python: + name: Python + runs-on: ubuntu-20.04 + + steps: + - name: Cancel previous runs + uses: styfle/cancel-workflow-action@0.4.1 + with: + access_token: ${{ github.token }} + + - name: Install dependencies + run: sudo apt update && sudo apt -y install python3 + + - name: Checkout code + uses: actions/checkout@v2 + + - name: Create virtual environment + run: | + cd python + make setup + + - name: Run formatter + run: | + cd python + make format check=1 \ No newline at end of file From d912f40fb455bc3517b3f3ea802ca3910460eec1 Mon Sep 17 00:00:00 2001 From: Mikhail Andrenkov Date: Thu, 13 May 2021 15:02:54 -0400 Subject: [PATCH 18/18] Add context to status check name --- .github/workflows/format.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index 4c35187b..5054a7b4 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -11,7 +11,7 @@ on: jobs: format-cpp: - name: C++ + name: Format (C++) runs-on: ubuntu-20.04 steps: @@ -30,7 +30,7 @@ jobs: run: ./bin/format --check include python/src test format-python: - name: Python + name: Format (Python) runs-on: ubuntu-20.04 steps: