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

Include C++ source files in binary wheels #225

Merged
merged 4 commits into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
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 @@ -60,7 +60,7 @@ jobs:
regex: '.*[0-9]+.[0-9]+.[0-9]+[-]?rc[0-9]+'

- uses: actions/upload-artifact@v2
if: ${{ github.event_name == 'release' || github.ref == 'refs/heads/master' || steps.rc_build.outputs.match != ''}}
#if: ${{ github.event_name == 'release' || github.ref == 'refs/heads/master' || steps.rc_build.outputs.match != ''}}
with:
name: ${{ runner.os }}-wheels.zip
path: ./wheelhouse/*.whl
43 changes: 18 additions & 25 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@

from distutils.util import get_platform


class CMakeExtension(Extension):
def __init__(self, name, sourcedir = ""):
Extension.__init__(self, name, sources = [])
def __init__(self, name, sourcedir=""):
Extension.__init__(self, name, sources=[])
self.sourcedir = Path(sourcedir).absolute()


Expand All @@ -34,9 +35,7 @@ class CMakeBuild(build_ext):
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
"""

user_options = build_ext.user_options + [
("define=", "D", "Define variables for CMake")
]
user_options = build_ext.user_options + [("define=", "D", "Define variables for CMake")]

def initialize_options(self):
super().initialize_options()
Expand All @@ -53,21 +52,21 @@ def build_extension(self, ext: CMakeExtension):
extdir = str(Path(self.get_ext_fullpath(ext.name)).parent.absolute())

debug = int(os.environ.get("DEBUG", 0)) if self.debug is None else self.debug
ninja_path = str(shutil.which('ninja'))
ninja_path = str(shutil.which("ninja"))

# Set Python_EXECUTABLE instead if you use PYBIND11_FINDPYTHON
configure_args = [
"-GNinja",
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}",
f"-DPYTHON_EXECUTABLE={sys.executable}",
f"-DCMAKE_MAKE_PROGRAM={ninja_path}",
"-DENABLE_WARNINGS=OFF", # Ignore warnings
"-DENABLE_WARNINGS=OFF", # Ignore warnings
]

if debug:
configure_args += ["-DCMAKE_BUILD_TYPE=Debug"]
configure_args += self.cmake_defines

build_args = []

# Add more platform dependent options
Expand All @@ -79,33 +78,24 @@ def build_extension(self, ext: CMakeExtension):
configure_args += ["-DENABLE_OPENMP=OFF"]
elif platform.system() == "Linux":
if platform.machine() == "x86_64":
configure_args += [
"-DENABLE_AVX=ON"
] # Enable AVX if x64 on Linux
configure_args += ["-DENABLE_AVX=ON"] # Enable AVX if x64 on Linux
elif platform.system() == "Windows":
configure_args += [
"-DENABLE_OPENMP=OFF",
"-DENABLE_BLAS=OFF"
]
configure_args += ["-DENABLE_OPENMP=OFF", "-DENABLE_BLAS=OFF"]
else:
raise RuntimeError(f"Unsupported '{platform.system()}' platform")

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

subprocess.check_call(
["cmake", str(ext.sourcedir)] + configure_args, cwd = self.build_temp
)
subprocess.check_call(
["cmake", "--build", "."] + build_args, cwd = self.build_temp
)

subprocess.check_call(["cmake", str(ext.sourcedir)] + configure_args, cwd=self.build_temp)
subprocess.check_call(["cmake", "--build", "."] + build_args, cwd=self.build_temp)


with open("pennylane_lightning/_version.py") as f:
version = f.readlines()[-1].split()[-1].strip("\"'")

requirements = [
"ninja",
"ninja",
"numpy",
"pennylane>=0.19",
]
Expand All @@ -118,7 +108,8 @@ def build_extension(self, ext: CMakeExtension):
"url": "https://github.com/XanaduAI/pennylane-lightning",
"license": "Apache License 2.0",
"packages": find_packages(where="."),
"package_data": {"pennylane_lightning": ["src/*"]},
"package_data": {"pennylane_lightning": ["src/*", "src/**/*"]},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @mlxd, I just change this line. All other changes are from black. You can check wheels here: https://github.com/PennyLaneAI/pennylane-lightning/actions/runs/1796752045. If it looks good, I will revert workflow file and merge.

"include_package_data": True,
"entry_points": {
"pennylane.plugins": [
"lightning.qubit = pennylane_lightning:LightningQubit",
Expand All @@ -129,7 +120,9 @@ def build_extension(self, ext: CMakeExtension):
"long_description_content_type": "text/x-rst",
"provides": ["pennylane_lightning"],
"install_requires": requirements,
"ext_modules": [CMakeExtension("lightning_qubit_ops")] if not os.environ.get("SKIP_COMPILATION", False) else [],
"ext_modules": [CMakeExtension("lightning_qubit_ops")]
if not os.environ.get("SKIP_COMPILATION", False)
else [],
"cmdclass": {"build_ext": CMakeBuild},
"ext_package": "pennylane_lightning",
}
Expand Down