Skip to content

Commit 11b86c4

Browse files
authored
Merge branch 'v0.31.0_rc' into qemu_git_ownership
2 parents 9ff839f + 5b5fd0c commit 11b86c4

10 files changed

+190
-207
lines changed

.github/CHANGELOG.md

+108-102
Large diffs are not rendered by default.

.github/workflows/tests_linux.yml

+4-8
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ jobs:
109109
- name: Install lightning.qubit device
110110
run: |
111111
cd main
112-
python setup.py build_ext -i --define="ENABLE_KOKKOS=OFF;ENABLE_PYTHON=ON;CMAKE_CXX_COMPILER=$(which g++-$GCC_VERSION)"
113-
pip install -e .
112+
CMAKE_ARGS="-DENABLE_KOKKOS=OFF -DENABLE_PYTHON=ON -DCMAKE_CXX_COMPILER=$(which g++-$GCC_VERSION)" pip install -e . -vv
114113
115114
- name: Run PennyLane-Lightning unit tests
116115
run: |
@@ -227,8 +226,7 @@ jobs:
227226
- name: Install lightning.qubit device
228227
run: |
229228
cd main
230-
python setup.py build_ext -i --define="ENABLE_BLAS=ON;ENABLE_KOKKOS=OFF;ENABLE_PYTHON=ON;CMAKE_CXX_COMPILER=$(which g++-$GCC_VERSION)"
231-
pip install -e .
229+
CMAKE_ARGS="-DENABLE_BLAS=ON -DENABLE_KOKKOS=OFF -DCMAKE_CXX_COMPILER=$(which g++-$GCC_VERSION)" pip install -e . -vv
232230
233231
- name: Run PennyLane-Lightning unit tests
234232
run: |
@@ -382,8 +380,7 @@ jobs:
382380
- name: Install lightning.qubit device
383381
run: |
384382
cd main
385-
python setup.py build_ext -i --define="CMAKE_PREFIX_PATH=${{ github.workspace }}/Kokkos;ENABLE_KOKKOS=ON;ENABLE_PYTHON=ON;CMAKE_CXX_COMPILER=$(which g++-$GCC_VERSION)"
386-
pip install -e .
383+
CMAKE_ARGS="-DCMAKE_PREFIX_PATH=${{ github.workspace }}/Kokkos -DCMAKE_CXX_COMPILER=$(which g++-$GCC_VERSION)" pip install -e . -vv
387384
388385
- name: Run PennyLane-Lightning unit tests
389386
run: |
@@ -531,8 +528,7 @@ jobs:
531528
- name: Install lightning.qubit device
532529
run: |
533530
cd main
534-
python setup.py build_ext -i --define="ENABLE_BLAS=ON;ENABLE_KOKKOS=ON;DENABLE_PYTHON=ON;CMAKE_PREFIX_PATH=${{ github.workspace }}/Kokkos;CMAKE_CXX_COMPILER=$(which g++-$GCC_VERSION)"
535-
pip install -e .
531+
CMAKE_ARGS="-DENABLE_BLAS=ON -DCMAKE_PREFIX_PATH=${{ github.workspace }}/Kokkos -DCMAKE_CXX_COMPILER=$(which g++-$GCC_VERSION)" pip install -e . -vv
536532
537533
- name: Run PennyLane-Lightning unit tests
538534
run: |

.github/workflows/wheel_linux_x86_64.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ jobs:
170170
yum install devtoolset-11-gcc-c++ -y
171171
source /opt/rh/devtoolset-11/enable -y
172172
173-
CIBW_ENVIRONMENT: PATH=/opt/rh/devtoolset-11/root/usr/bin:$PATH
173+
CIBW_ENVIRONMENT: |
174+
PATH=/opt/rh/devtoolset-11/root/usr/bin:$PATH
174175
# Testing of built wheels
175176
CIBW_TEST_REQUIRES: pytest pytest-cov pytest-mock flaky
176177

.github/workflows/wheel_macos_arm64.yml

+3
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ jobs:
8989
CIBW_BEFORE_BUILD: |
9090
pip install pybind11 ninja cmake~=3.24.0 setuptools
9191
92+
CIBW_ENVIRONMENT: |
93+
CMAKE_ARGS="-DCMAKE_CXX_COMPILER_TARGET=arm64-apple-macos11 -DCMAKE_SYSTEM_NAME=Darwin -DCMAKE_SYSTEM_PROCESSOR=ARM64 -DENABLE_OPENMP=OFF"
94+
9295
# Testing of built wheels
9396
CIBW_TEST_REQUIRES: pytest pytest-cov pytest-mock flaky
9497

.github/workflows/wheel_macos_x86_64.yml

-2
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,6 @@ jobs:
174174

175175
CIBW_ARCHS_MACOS: ${{matrix.arch}}
176176

177-
USE_OMP: 1
178-
179177
run: |
180178
python -m cibuildwheel --output-dir wheelhouse
181179

CMakeLists.txt

+6-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,12 @@ option(ENABLE_CLANG_TIDY "Enable clang-tidy build checks" OFF)
4545
option(ENABLE_COVERAGE "Enable code coverage" OFF)
4646
option(ENABLE_WARNINGS "Enable warnings" ON)
4747
option(ENABLE_NATIVE "Enable native CPU build tuning" OFF)
48-
option(ENABLE_OPENMP "Enable OpenMP" ON)
48+
find_package(OpenMP)
49+
if (OpenMP_CXX_FOUND)
50+
option(ENABLE_OPENMP "Enable OpenMP" ON)
51+
else()
52+
option(ENABLE_OPENMP "Enable OpenMP" OFF)
53+
endif()
4954
option(ENABLE_KOKKOS "Enable Kokkos" ON)
5055
option(ENABLE_BLAS "Enable BLAS" OFF)
5156
option(ENABLE_PYTHON "Enable compilation of the Python module" ON)

README.rst

+28-12
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,19 @@ To build PennyLane-Lightning from source you can run
6767
6868
$ pip install pybind11 pennylane-lightning --no-binary :all:
6969
70-
A C++ compiler such as ``g++``, ``clang``, or ``MSVC`` is required. On Debian-based systems, this
71-
can be installed via ``apt``:
70+
A C++ compiler such as ``g++``, ``clang++``, or ``MSVC`` is required.
71+
On Debian-based systems, this can be installed via ``apt``:
7272

7373
.. code-block:: console
7474
7575
$ sudo apt install g++
7676
77+
On MacOS, we recommend using the latest version of ``clang++`` and ``libomp``:
78+
79+
.. code-block:: console
80+
81+
$ brew install llvm libomp
82+
7783
The `pybind11 <https://pybind11.readthedocs.io/en/stable/>`_ library is also used for binding the
7884
C++ functionality to Python.
7985

@@ -89,23 +95,25 @@ Alternatively, for development and testing, you can install by cloning the repos
8995
Note that subsequent calls to ``pip install -e .`` will use cached binaries stored in the
9096
``build`` folder. Run ``make clean`` if you would like to recompile.
9197

92-
You can also pass ``cmake`` options with ``build_ext``:
98+
You can also pass ``cmake`` options with ``CMAKE_ARGS`` as follows:
9399

94100
.. code-block:: console
95101
96-
$ python3 setup.py build_ext -i --define="ENABLE_OPENMP=OFF;ENABLE_NATIVE=ON"
102+
$ CMAKE_ARGS="-DENABLE_OPENMP=OFF -DENABLE_BLAS=OFF -DENABLE_KOKKOS=OFF" pip install -e . -vv
97103
98-
and install the compiled library with
104+
or with ``build_ext`` and the ``--define`` flag as follows:
99105

100106
.. code-block:: console
101107
108+
$ python3 setup.py build_ext -i --define="ENABLE_OPENMP=OFF;ENABLE_BLAS=OFF;ENABLE_KOKKOS=OFF"
102109
$ python3 setup.py develop
103110
104111
105112
GPU support
106113
-----------
107114

108-
For GPU support, `PennyLane-Lightning-GPU <https://github.com/PennyLaneAI/pennylane-lightning-gpu>`_ can be installed by providing the optional ``[gpu]`` tag:
115+
For GPU support, `PennyLane-Lightning-GPU <https://github.com/PennyLaneAI/pennylane-lightning-gpu>`_
116+
can be installed by providing the optional ``[gpu]`` tag:
109117

110118
.. code-block:: console
111119
@@ -148,18 +156,26 @@ To test the C++ code:
148156
$ cmake -DBUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Debug ..
149157
$ make
150158
151-
Other supported options are ``-DENABLE_WARNINGS=ON``,
152-
``-DENABLE_NATIVE=ON`` (for ``-march=native``),
153-
``-DENABLE_BLAS=ON``, ``-DENABLE_OPENMP=ON``,
154-
``-DENABLE_KOKKOS=ON``, and ``-DENABLE_CLANG_TIDY=ON``.
159+
Other supported options are
160+
161+
- ``-DENABLE_WARNINGS=ON``
162+
- ``-DENABLE_NATIVE=ON`` (for ``-march=native``)
163+
- ``-DENABLE_BLAS=ON``
164+
- ``-DENABLE_OPENMP=ON``
165+
- ``-DENABLE_KOKKOS=ON``
166+
- ``-DENABLE_CLANG_TIDY=ON``
155167

156168
Compile on Windows with MSVC
157169
----------------------------
158170

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

161176

162-
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.
177+
We recommend to use ``[x64 (or x86)] Native Tools Command Prompt for VS [version]`` for compiling the library.
178+
Be sure that ``cmake`` and ``python`` can be called within the prompt.
163179

164180

165181
.. code-block:: console

pennylane_lightning/_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
"""
1818

1919

20-
__version__ = "0.31.0-dev6"
20+
__version__ = "0.31.0-rc1"

pennylane_lightning/lightning_qubit.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,14 @@ class LightningQubit(QubitDevice):
166166
random qubit site and then generates a random number to determine the new bit at that qubit site. The ``"NonZeroRandom"`` kernel
167167
randomly transits between states that have nonzero probability.
168168
num_burnin (int): number of steps that will be dropped. Increasing this value will
169-
result in a closer approximation but increased runtime.
169+
result in a closer approximation but increased runtime.
170170
batch_obs (bool): Determine whether we process observables parallelly when computing the
171171
jacobian. This value is only relevant when the lightning qubit is built with OpenMP.
172172
"""
173173

174174
name = "Lightning Qubit PennyLane plugin"
175175
short_name = "lightning.qubit"
176-
pennylane_requires = ">=0.26"
176+
pennylane_requires = ">=0.30"
177177
version = __version__
178178
author = "Xanadu Inc."
179179
_CPP_BINARY_AVAILABLE = True
@@ -979,7 +979,7 @@ def _get_diagonalizing_gates(self, circuit: qml.tape.QuantumTape) -> List[Operat
979979
class LightningQubit(DefaultQubit): # pragma: no cover
980980
name = "Lightning Qubit PennyLane plugin"
981981
short_name = "lightning.qubit"
982-
pennylane_requires = ">=0.26"
982+
pennylane_requires = ">=0.30"
983983
version = __version__
984984
author = "Xanadu Inc."
985985
_CPP_BINARY_AVAILABLE = False

setup.py

+35-77
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# limitations under the License.
1414
import os
1515
import platform
16-
import sys
1716
import subprocess
1817
import shutil
1918
from pathlib import Path
@@ -32,32 +31,32 @@ class CMakeBuild(build_ext):
3231
This class is built upon https://github.com/diegoferigo/cmake-build-extension/blob/master/src/cmake_build_extension/build_extension.py and https://github.com/pybind/cmake_example/blob/master/setup.py
3332
"""
3433

35-
user_options = build_ext.user_options + [
36-
("define=", "D", "Define variables for CMake")
37-
]
34+
user_options = build_ext.user_options + [("define=", "D", "Define variables for CMake")]
3835

3936
def initialize_options(self):
4037
super().initialize_options()
4138
self.define = None
39+
self.verbosity = ""
4240

4341
def finalize_options(self):
4442
# Parse the custom CMake options and store them in a new attribute
4543
defines = [] if self.define is None else self.define.split(";")
4644
self.cmake_defines = [f"-D{define}" for define in defines]
45+
if self.verbosity != "":
46+
self.verbosity = "--verbose"
4747

4848
super().finalize_options()
4949

5050
def build_extension(self, ext: CMakeExtension):
5151
extdir = str(Path(self.get_ext_fullpath(ext.name)).parent.absolute())
52-
5352
debug = int(os.environ.get("DEBUG", 0)) if self.debug is None else self.debug
53+
build_type = "Debug" if debug else "RelWithDebInfo"
5454
ninja_path = str(shutil.which("ninja"))
5555

56-
# Set Python_EXECUTABLE instead if you use PYBIND11_FINDPYTHON
56+
build_args = ["--config", "Debug"] if debug else ["--config", "RelWithDebInfo"]
5757
configure_args = [
5858
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}",
59-
f"-DPython_EXECUTABLE={sys.executable}", # (Windows)
60-
f"-DPYTHON_EXECUTABLE={sys.executable}", # (Ubuntu)
59+
f"-DCMAKE_BUILD_TYPE={build_type}", # not used on MSVC, but no harm
6160
"-DENABLE_WARNINGS=OFF", # Ignore warnings
6261
]
6362

@@ -73,88 +72,47 @@ def build_extension(self, ext: CMakeExtension):
7372
f"-DCMAKE_MAKE_PROGRAM={ninja_path}",
7473
]
7574

76-
build_args = []
77-
78-
if debug:
79-
configure_args += ["-DCMAKE_BUILD_TYPE=Debug"]
80-
build_args += ["--config", "Debug"]
81-
else:
82-
build_args += ["--config", "RelWithDebInfo"]
83-
8475
configure_args += self.cmake_defines
8576

8677
# Add more platform dependent options
8778
if platform.system() == "Darwin":
88-
# To support ARM64
89-
if os.getenv("ARCHS") == "arm64":
90-
configure_args += [
91-
"-DCMAKE_CXX_COMPILER_TARGET=arm64-apple-macos11",
92-
"-DCMAKE_SYSTEM_NAME=Darwin",
93-
"-DCMAKE_SYSTEM_PROCESSOR=ARM64",
94-
"-DENABLE_OPENMP=OFF",
95-
]
96-
else: # X64 arch
97-
# If we explicitly request a brew LLVM version, use that
98-
if os.getenv("BREW_LLVM_VERSION") and shutil.which("brew"):
99-
brew_llvm_version = os.getenv("BREW_LLVM_VERSION")
100-
llvmpath = subprocess.run(
101-
[
102-
"brew",
103-
"--prefix",
104-
"llvm" + f"@{brew_llvm_version}"
105-
if brew_llvm_version
106-
else "",
107-
],
108-
check=True,
109-
capture_output=True,
110-
text=True,
111-
).stdout.strip()
112-
113-
else:
114-
# No brew, use the default clang++ install provided by MacOS
115-
llvmpath = shutil.which("clang++")
116-
llvmpath = Path(llvmpath).parent.parent
117-
118-
# Ensure the appropriate compiler and linker are chosen
119-
configure_args += [
120-
f"-DCMAKE_CXX_COMPILER={llvmpath}/bin/clang++",
121-
f"-DCMAKE_LINKER={llvmpath}/bin/lld",
122-
] # Use clang instead of appleclang
123-
124-
# Try to support OpenMP through libomp if available
125-
if os.environ.get("USE_OMP") and shutil.which("brew"):
126-
libomp_path = subprocess.run(
127-
[
128-
"brew",
129-
"--prefix",
130-
"libomp",
131-
],
132-
check=False,
133-
capture_output=True,
134-
text=True,
135-
).stdout.strip()
136-
configure_args += (
137-
[f"-DOpenMP_ROOT={libomp_path}/"]
138-
if libomp_path
139-
else ["-DENABLE_OPENMP=OFF"]
140-
)
79+
clang_path = Path(shutil.which("clang++")).parent.parent
80+
configure_args += [
81+
f"-DCMAKE_CXX_COMPILER={clang_path}/bin/clang++",
82+
f"-DCMAKE_LINKER={clang_path}/bin/lld",
83+
]
84+
if shutil.which("brew"):
85+
libomp_path = subprocess.run(
86+
"brew --prefix libomp".split(" "),
87+
check=False,
88+
capture_output=True,
89+
text=True,
90+
).stdout.strip()
91+
if not Path(libomp_path).exists():
92+
libomp_path = ""
93+
configure_args += (
94+
[f"-DOpenMP_ROOT={libomp_path}/"] if libomp_path else ["-DENABLE_OPENMP=OFF"]
95+
)
14196
elif platform.system() == "Windows":
14297
configure_args += ["-DENABLE_OPENMP=OFF", "-DENABLE_BLAS=OFF"]
143-
elif platform.system() != "Linux":
98+
elif platform.system() not in ["Linux"]:
14499
raise RuntimeError(f"Unsupported '{platform.system()}' platform")
145100

146101
if not Path(self.build_temp).exists():
147102
os.makedirs(self.build_temp)
148103

149-
subprocess.run(
104+
if "CMAKE_ARGS" in os.environ.keys():
105+
configure_args += os.environ["CMAKE_ARGS"].split(" ")
106+
107+
subprocess.check_call(
150108
["cmake", str(ext.sourcedir)] + configure_args,
151109
cwd=self.build_temp,
152-
check=True,
110+
env=os.environ,
153111
)
154-
subprocess.run(
112+
subprocess.check_call(
155113
["cmake", "--build", ".", "--verbose"] + build_args,
156114
cwd=self.build_temp,
157-
check=True,
115+
env=os.environ,
158116
)
159117

160118

@@ -190,9 +148,9 @@ def build_extension(self, ext: CMakeExtension):
190148
"long_description_content_type": "text/x-rst",
191149
"provides": ["pennylane_lightning"],
192150
"install_requires": requirements,
193-
"ext_modules": [CMakeExtension("lightning_qubit_ops")]
194-
if not os.environ.get("SKIP_COMPILATION", False)
195-
else [],
151+
"ext_modules": []
152+
if os.environ.get("SKIP_COMPILATION", False)
153+
else [CMakeExtension("lightning_qubit_ops")],
196154
"cmdclass": {"build_ext": CMakeBuild},
197155
"ext_package": "pennylane_lightning",
198156
"extras_require": {"gpu": ["pennylane-lightning-gpu"]},

0 commit comments

Comments
 (0)