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

[WIP] setup.py uses CMake #176

Merged
merged 59 commits into from
Nov 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
ff5e211
Rewrite the simplest setup.py for CMake
chaeyeunpark Nov 6, 2021
b034233
Rewrite the simplest setup.py for CMake
chaeyeunpark Nov 6, 2021
b9685af
Merge branch 'cmake_setup_py' of github.com:PennyLaneAI/pennylane-lig…
chaeyeunpark Nov 9, 2021
b0d50ed
Cut clutter in CMakeLists.txt
chaeyeunpark Nov 9, 2021
e84ddbb
setup.py correctly configure --define
chaeyeunpark Nov 11, 2021
d08b5b1
Refactored CMakeLists.txt
chaeyeunpark Nov 11, 2021
0ea2819
OpenMP fixed
chaeyeunpark Nov 11, 2021
9785770
Now uses Ninja
chaeyeunpark Nov 11, 2021
db4e2ca
Disable OpenMP ans BLAS for Windows
chaeyeunpark Nov 11, 2021
e338cc1
Corrected BLAS message
chaeyeunpark Nov 11, 2021
8720386
Suppress warnings for release mode in MSVC
chaeyeunpark Nov 11, 2021
6d6d558
Ninja version relaxed
chaeyeunpark Nov 11, 2021
52f53a8
Format fixed
chaeyeunpark Nov 11, 2021
75d89da
Merge branch 'master' into cmake_setup_py
chaeyeunpark Nov 12, 2021
5c7cb7b
Now path is str
chaeyeunpark Nov 12, 2021
86ef04d
More path is str
chaeyeunpark Nov 12, 2021
df129fd
Test with explicit cmake
chaeyeunpark Nov 12, 2021
23b61fe
Configureations for cibuildwheel updated
chaeyeunpark Nov 12, 2021
9f7b892
Updated commands for windows
chaeyeunpark Nov 12, 2021
4ba3e20
Only target AMD64 for Windows
chaeyeunpark Nov 12, 2021
abad7f6
Should call vcvars64.bat before test
chaeyeunpark Nov 12, 2021
6283fa9
Test python path for Windows
chaeyeunpark Nov 12, 2021
9d11e35
Removed comments
chaeyeunpark Nov 12, 2021
0b51693
Adds dependencies to readthedocs
chaeyeunpark Nov 12, 2021
cc01c06
Command fixed
chaeyeunpark Nov 12, 2021
e6d9870
Fixed
chaeyeunpark Nov 12, 2021
e6a1e77
Readthedocs build updated
chaeyeunpark Nov 12, 2021
759c1d4
Added tools to readthedocs config
chaeyeunpark Nov 12, 2021
354322f
Command fixed for cmd
chaeyeunpark Nov 12, 2021
ccb3d03
Python version further fixed
chaeyeunpark Nov 12, 2021
076aba4
Removing python.version as it is deprecated
chaeyeunpark Nov 12, 2021
7b70f65
Test after adding current dir to dllpath
chaeyeunpark Nov 14, 2021
96a66dd
Tests in Windows more
chaeyeunpark Nov 14, 2021
130f38e
Add DLL path only when Python>=3.8
chaeyeunpark Nov 14, 2021
90e919c
More fix for Windows
chaeyeunpark Nov 14, 2021
d30d2b0
Try another setting
chaeyeunpark Nov 14, 2021
68ce302
Updated CHANGELOG.md
chaeyeunpark Nov 14, 2021
3ceecea
Update README.rst
chaeyeunpark Nov 15, 2021
5d8b4fd
Update .github/CHANGELOG.md
chaeyeunpark Nov 15, 2021
9322482
Removed openblas from wheel (at the moment); Recovered AVX support
chaeyeunpark Nov 15, 2021
4b84029
Merge branch 'master' into cmake_setup_py_actions_wheel
chaeyeunpark Nov 15, 2021
fd94133
CMakeLists.txt now processes options using an indendent file.
chaeyeunpark Nov 15, 2021
aa77098
Use Ninja for noarch
chaeyeunpark Nov 15, 2021
9b92ecb
Disable OpenMP in M1 Macs; Test upload wheel
chaeyeunpark Nov 16, 2021
034c460
Merge branch 'master' into cmake_setup_py_actions_wheel
chaeyeunpark Nov 16, 2021
6d60ff2
Test for M1
chaeyeunpark Nov 16, 2021
0a90da2
Must disable OpenMP instead of BLAS
chaeyeunpark Nov 16, 2021
5dca7c9
Update README.rst
chaeyeunpark Nov 22, 2021
c416e3f
Do not upload wheel for branchs; Added some compile options
chaeyeunpark Nov 22, 2021
91f04ec
Corrected comment
chaeyeunpark Nov 22, 2021
43e7c63
Update README.rst
chaeyeunpark Nov 23, 2021
d50f69c
README.rst fixed; BLAS option fixed
chaeyeunpark Nov 23, 2021
c6395ed
Merge branch 'master' into cmake_setup_py_actions_wheel
chaeyeunpark Nov 23, 2021
8855b6c
Update README.rst
chaeyeunpark Nov 24, 2021
abd894b
Update README.rst
chaeyeunpark Nov 24, 2021
10addaf
Merge branch 'master' into cmake_setup_py_actions_wheel
chaeyeunpark Nov 25, 2021
0fe149a
Updated noarch; Added nolint for coverage
chaeyeunpark Nov 25, 2021
f981070
Do not upload wheel for noarch if not master; format-fixed
chaeyeunpark Nov 25, 2021
7da1e65
Wheel script for noarch fixed
chaeyeunpark Nov 25, 2021
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
5 changes: 5 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@

### Documentation

* Compile guide for MSVC is added.
[(#176)](https://github.com/PennyLaneAI/pennylane-lightning/pull/176)

### Bug fixes

### Contributors

Chae-Yeun Park

This release contains contributions from (in alphabetical order):

Ali Asadi
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/wheel_linux_aarch64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ env:

# Python build settings
CIBW_BEFORE_BUILD: |
pip install pybind11
pip install pybind11 ninja && yum install -y cmake gcc gcc-c++

# Testing of built wheels
CIBW_TEST_REQUIRES: numpy==1.19.5 scipy pytest pytest-cov pytest-mock flaky
Expand Down Expand Up @@ -60,4 +60,4 @@ jobs:
if: ${{ github.event_name == 'release' || github.ref == 'refs/heads/master' }}
with:
name: ${{ runner.os }}-wheels.zip
path: ./wheelhouse/*.whl
path: ./wheelhouse/*.whl
4 changes: 2 additions & 2 deletions .github/workflows/wheel_linux_ppc64le.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ env:

# Python build settings
CIBW_BEFORE_BUILD: |
pip install pybind11
pip install pybind11 ninja && yum install -y cmake gcc gcc-c++

# Skip PPC tests due to lack of numpy/scipy wheel support
CIBW_TEST_SKIP: "*-manylinux_{ppc64le}"
Expand Down Expand Up @@ -57,4 +57,4 @@ jobs:
if: ${{ github.event_name == 'release' || github.ref == 'refs/heads/master' }}
with:
name: ${{ runner.os }}-wheels.zip
path: ./wheelhouse/*.whl
path: ./wheelhouse/*.whl
2 changes: 1 addition & 1 deletion .github/workflows/wheel_linux_x86_64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ env:

# Python build settings
CIBW_BEFORE_BUILD: |
pip install pybind11
pip install pybind11 ninja && yum install -y cmake gcc gcc-c++

# Testing of built wheels
CIBW_TEST_REQUIRES: numpy==1.19.5 scipy pytest pytest-cov pytest-mock flaky
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/wheel_macos_arm64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
push:
branches:
- master
pull_request:
release:

env:
Expand All @@ -14,7 +15,7 @@ env:

# Python build settings
CIBW_BEFORE_BUILD: |
pip install pybind11
pip install pybind11 ninja

# Testing of built wheels
CIBW_TEST_REQUIRES: numpy==1.19.5 scipy pytest pytest-cov pytest-mock flaky
Expand Down Expand Up @@ -60,4 +61,4 @@ jobs:
if: ${{ github.event_name == 'release' || github.ref == 'refs/heads/master' }}
with:
name: ${{ runner.os }}-wheels.zip
path: ./wheelhouse/*.whl
path: ./wheelhouse/*.whl
4 changes: 2 additions & 2 deletions .github/workflows/wheel_macos_x86_64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ env:

# Python build settings
CIBW_BEFORE_BUILD: |
pip install pybind11
pip install pybind11 ninja

# Testing of built wheels
CIBW_TEST_REQUIRES: numpy==1.19.5 scipy pytest pytest-cov pytest-mock flaky
Expand Down Expand Up @@ -64,4 +64,4 @@ jobs:
if: ${{ github.event_name == 'release' || github.ref == 'refs/heads/master' }}
with:
name: ${{ runner.os }}-wheels.zip
path: ./wheelhouse/*.whl
path: ./wheelhouse/*.whl
8 changes: 8 additions & 0 deletions .github/workflows/wheel_noarch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ jobs:
with:
python-version: '3.7'

- name: Upgrade pip
run: |
python -m pip install --upgrade pip

- name: Install CMake and ninja
run: |
python -m pip install --upgrade cmake ninja

- name: Build wheels
run: |
python -m pip install --upgrade pip wheel
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/wheel_win_x86_64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ on:
env:
CIBW_BUILD: 'cp37-* cp38-* cp39-*'

CIBW_ARCHS_WINDOWS: "AMD64"

# Python build settings
CIBW_BEFORE_BUILD: |
pip install pybind11
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat" && pip install pybind11 ninja

# Testing of built wheels
CIBW_TEST_REQUIRES: numpy==1.19.5 scipy pytest pytest-cov pytest-mock flaky

CIBW_BEFORE_TEST: |
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat" && python -c "import sys; print(sys.path)"

CIBW_TEST_COMMAND: |
pl-device-test --device=lightning.qubit --skip-ops -x --tb=short --no-flaky-report

Expand Down
10 changes: 8 additions & 2 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ sphinx:
configuration: doc/conf.py

python:
version: 3.8
install:
- requirements: doc/requirements.txt
- requirements: requirements.txt
Expand All @@ -13,4 +12,11 @@ python:
system_packages: true

build:
image: latest
os: ubuntu-20.04
tools:
python: "3.8"
apt_packages:
- cmake
- build-essential
- libopenblas-base
- libopenblas-dev
56 changes: 30 additions & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
cmake_minimum_required(VERSION 3.14)

set(CMAKE_OSX_DEPLOYMENT_TARGET "10.14" CACHE STRING "Minimum OS X deployment version")

project(pennylane_lightning)

# Read and set pennylane_lightning version
Expand All @@ -26,20 +28,31 @@ if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()

# Clang-tidy
option(ENABLE_CLANG_TIDY "Enable clang-tidy build checks" OFF)

# Compile options
option(ENABLE_WARNINGS "Enable warnings" ON)
option(ENABLE_NATIVE "Enable native CPU build tuning" OFF)
option(ENABLE_AVX "Enable AVX support" ON)
option(ENABLE_OPENMP "Enable OpenMP" ON)
option(ENABLE_BLAS "Enable BLAS" OFF)

# Other build options
option(BUILD_TESTS "Build cpp tests" OFF)
option(ENABLE_WARNINGS "Enable warnings" ON)
option(ENABLE_CLANG_TIDY "Enable clang-tidy build checks" OFF)

if(ENABLE_CLANG_TIDY)
if (NOT DEFINED CLANG_TIDY_BINARY)
if(NOT DEFINED CLANG_TIDY_BINARY)
set(CLANG_TIDY_BINARY clang-tidy)
endif()
set(CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_BINARY};
-extra-arg=-std=c++17;
)
endif()

# Process compile options
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/process_options.cmake")

# Add pybind11
include(FetchContent)
FetchContent_Declare(
Expand All @@ -49,40 +62,31 @@ FetchContent_Declare(
)
FetchContent_MakeAvailable(pybind11)

# All CMakeLists.txt in subdirectories use pennylane_lightning_compile_options and pennylane_lightning_external_libs
add_subdirectory(pennylane_lightning/src)


add_library(pennylane_lightning INTERFACE)
target_link_libraries(pennylane_lightning INTERFACE lightning_utils
lightning_simulator
target_link_libraries(pennylane_lightning INTERFACE lightning_utils
lightning_simulator
lightning_algorithms)
target_include_directories(pennylane_lightning INTERFACE "pennylane_lightning/src")

add_library(external_dependency INTERFACE)
pybind11_add_module(lightning_qubit_ops "pennylane_lightning/src/bindings/Bindings.cpp")
target_link_libraries(lightning_qubit_ops PRIVATE pennylane_lightning
pennylane_lightning_compile_options
pennylane_lightning_external_libs)
set_target_properties(lightning_qubit_ops PROPERTIES CXX_VISIBILITY_PRESET hidden)

if ("$ENV{USE_OPENBLAS}" OR "${USE_OPENBLAS}")
message(STATUS "Use OPENBLAS")
target_link_libraries(external_dependency INTERFACE openblas)
target_compile_options(external_dependency INTERFACE "-DOPENBLAS=1")
if (MSVC)
target_compile_options(lightning_qubit_ops PRIVATE "$<$<CONFIG:RELEASE>:/w>")
else()
target_compile_options(lightning_qubit_ops PRIVATE "$<$<CONFIG:RELEASE>:-W>")
endif()

pybind11_add_module(lightning_qubit_ops "pennylane_lightning/src/bindings/Bindings.cpp")
target_link_libraries(lightning_qubit_ops PRIVATE pennylane_lightning external_dependency)
set_target_properties(lightning_qubit_ops PROPERTIES CXX_VISIBILITY_PRESET hidden)

target_compile_options(lightning_qubit_ops PRIVATE "$<$<CONFIG:RELEASE>:-W>")
target_compile_definitions(lightning_qubit_ops PRIVATE VERSION_INFO=${VERSION_STRING})

if(ENABLE_WARNINGS)
target_compile_options(pennylane_lightning INTERFACE $<$<COMPILE_LANGUAGE:CXX>:-Wall;-Wextra;-Werror>)
endif()

if(ENABLE_NATIVE)
message(STATUS "ENABLE_NATIVE is ON. Using -march=native")
add_compile_options(-march=native)
target_compile_options(pennylane_lightning INTERFACE -march=native)
target_compile_options(lightning_qubit_ops PRIVATE -march=native)
endif()

if (BUILD_TESTS)
if(BUILD_TESTS)
enable_testing()
endif()
55 changes: 44 additions & 11 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ Alternatively, for development and testing, you can install by cloning the repos
Note that subsequent calls to ``pip install -e .`` will use cached binaries stored in the
``build`` folder. Run ``make clean`` if you would like to recompile.

You can also pass ``cmake`` options with ``build_ext``:

.. code-block:: console

$ python3 setup.py build_ext -i --define="ENABLE_OPENMP=OFF;ENABLE_NATIVE=ON"

and install the compilied library with

.. code-block:: console

$ python3 setup.py develop

Testing
-------

Expand All @@ -97,7 +109,6 @@ while the C++ code can be tested with

$ make test-cpp

Testing the C++ code requires the `GoogleTest <https://github.com/google/googletest>`__ framework.

CMake Support
-------------
Expand All @@ -109,31 +120,53 @@ One can also build the plugin using CMake:
$ cmake -S. -B build
$ cmake --build build

and install

.. code-block:: console

$ pip install -e .

To test the C++ code:

.. code-block:: console

$ mkdir build && cd build
$ cmake -DBUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Debug ..
$ make cpptests
$ make test
$ make

Other supported options are ``-DENABLE_NATIVE=ON`` (for ``-march=native``),
``-DUSE_LAPACK=ON``, ``-DUSE_OPENBLAS=ON``, and
Other supported options are ``-DENABLE_WARNINGS=ON``,
``-DENABLE_NATIVE=ON`` (for ``-march=native``),
``-DENALBE_OPENMP=ON``, ``-DENALBE_BLAS=ON``, and
``-DENABLE_CLANG_TIDY=ON``.



Compile on Windows with MSVC
----------------------------

You can also compile Pennylane-Lightning on Windows using `Microsoft Visual C++ <https://visualstudio.microsoft.com/vs/features/cplusplus/>`_ compiler. You need `cmake <https://cmake.org/download/>`_ and appropriate Python environment (e.g. using `Anaconda <https://www.anaconda.com/>`_).


We recommend to use ``[x64 (or x86)] Native Tools Command Prompt for VS [version]`` for compiling the library. Be sure that ``cmake`` and ``python`` can be called within the prompt.


.. code-block:: console

$ cmake --version
$ python --version

Then a common command will work.

.. code-block:: console

$ pip install -r requirements.txt
$ pip install -e .

Note that OpenMP and BLAS are disabled in this setting.


.. installation-end-inclusion-marker-do-not-remove


Please refer to the `plugin documentation <https://pennylane-lightning.readthedocs.io/>`_ as
well as to the `PennyLane documentation <https://pennylane.readthedocs.io/>`_ for further reference.



Contributing
============

Expand Down
Loading