From 60e1f6f89802e779d628dce1dd5298d536f68446 Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Fri, 3 Feb 2023 16:35:21 -0500 Subject: [PATCH 1/6] Assuming unavailability of ninja on certain platforms --- setup.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index be99550330..36b122f4ad 100644 --- a/setup.py +++ b/setup.py @@ -65,10 +65,11 @@ def build_extension(self, ext: CMakeExtension): "-T clangcl", ] else: - configure_args += [ - "-GNinja", - f"-DCMAKE_MAKE_PROGRAM={ninja_path}", - ] + if ninja_path: + configure_args += [ + "-GNinja", + f"-DCMAKE_MAKE_PROGRAM={ninja_path}", + ] build_args = [] @@ -114,7 +115,6 @@ def build_extension(self, ext: CMakeExtension): version = f.readlines()[-1].split()[-1].strip("\"'") requirements = [ - "ninja", "pennylane>=0.28", ] From 8294c62c17e0b03731139dd84415e532b470a7f8 Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Fri, 3 Feb 2023 16:37:05 -0500 Subject: [PATCH 2/6] Run black formatter --- .github/workflows/dev_version_script.py | 39 ++++++++------ .github/workflows/vb_script.py | 67 ++++++++++++++++--------- bin/utils.py | 18 ++++--- doc/conf.py | 12 +++-- setup.py | 36 +++++++------ 5 files changed, 104 insertions(+), 68 deletions(-) diff --git a/.github/workflows/dev_version_script.py b/.github/workflows/dev_version_script.py index 82d47e6656..f7ab794b26 100644 --- a/.github/workflows/dev_version_script.py +++ b/.github/workflows/dev_version_script.py @@ -17,61 +17,68 @@ import re -VERSION_FILE_PATH = 'pennylane_lightning/_version.py' +VERSION_FILE_PATH = "pennylane_lightning/_version.py" -rgx_ver = re.compile('^__version__ = \"(.*?)\"$') +rgx_ver = re.compile('^__version__ = "(.*?)"$') + +rgx_dev_ver = re.compile("^(\d*\.\d*\.\d*)-dev(\d*)$") -rgx_dev_ver = re.compile('^(\d*\.\d*\.\d*)-dev(\d*)$') def extract_version(package_path): - with package_path.joinpath(VERSION_FILE_PATH).open('r') as f: + with package_path.joinpath(VERSION_FILE_PATH).open("r") as f: for line in f.readlines(): - if line.startswith('__version__'): + if line.startswith("__version__"): line = line.strip() m = rgx_ver.match(line) return m.group(1) raise ValueError("Cannot parse version") + def is_dev(version_str): m = rgx_dev_ver.fullmatch(version_str) return m is not None + def update_dev_version(package_path, version_str): m = rgx_dev_ver.fullmatch(version_str) - if m.group(2) == '': + if m.group(2) == "": curr_dev_ver = 0 else: curr_dev_ver = int(m.group(2)) - new_version_str = '{}-dev{}'.format(m.group(1), str(curr_dev_ver + 1)) + new_version_str = "{}-dev{}".format(m.group(1), str(curr_dev_ver + 1)) lines = [] - with package_path.joinpath(VERSION_FILE_PATH).open('r') as f: + with package_path.joinpath(VERSION_FILE_PATH).open("r") as f: for line in f.readlines(): - if not line.startswith('__version__'): + if not line.startswith("__version__"): lines.append(line) else: - lines.append(f'__version__ = \"{new_version_str}\"\n') + lines.append(f'__version__ = "{new_version_str}"\n') - with package_path.joinpath(VERSION_FILE_PATH).open('w') as f: - f.write(''.join(lines)) + with package_path.joinpath(VERSION_FILE_PATH).open("w") as f: + f.write("".join(lines)) if __name__ == "__main__": parser = argparse.ArgumentParser() - parser.add_argument("--pr-path", dest = "pr", type=str, required=True, help="Path to the PR dir") - parser.add_argument("--master-path", dest = "master", type=str, required=True, help="Path to the master dir") + parser.add_argument("--pr-path", dest="pr", type=str, required=True, help="Path to the PR dir") + parser.add_argument( + "--master-path", dest="master", type=str, required=True, help="Path to the master dir" + ) args = parser.parse_args() pr_version = extract_version(Path(args.pr)) master_version = extract_version(Path(args.master)) - + if pr_version == master_version: if is_dev(pr_version): print("Automatically update version string.") update_dev_version(Path(args.pr), pr_version) else: - print("Even though version of this PR is different from the master, as the PR is not dev, we do nothing.") + print( + "Even though version of this PR is different from the master, as the PR is not dev, we do nothing." + ) else: print("Version of this PR is already different from master. Do nothing.") diff --git a/.github/workflows/vb_script.py b/.github/workflows/vb_script.py index 722cb31add..2595bfd850 100644 --- a/.github/workflows/vb_script.py +++ b/.github/workflows/vb_script.py @@ -13,20 +13,21 @@ # limitations under the License. import argparse import pennylane as qml + pl_version = '"' + qml.version() + '"' def remove_quotes(my_str): - """ A helper function to remove the quote chars (',") + """A helper function to remove the quote chars (',") from the provided str. """ - clean_str = my_str.replace('"', '') # remove " + clean_str = my_str.replace('"', "") # remove " clean_str = clean_str.replace("'", "") # remove ' return clean_str def bump_version(version_line, pre_release): - """ A helper function which takes the current version string and + """A helper function which takes the current version string and replaces it with the bumped version depending on the pre/post release flag. @@ -42,16 +43,20 @@ def bump_version(version_line, pre_release): bumped_version (string): The bumped version string. """ data = version_line.split(" ") - curr_version = data[-1].replace('\n', '') # remove any newline characters + curr_version = data[-1].replace("\n", "") # remove any newline characters if pre_release: curr_version = pl_version # get current Pennylane version split_version = curr_version.split(".") # "0.17.0" --> ["0,17,0"] - split_version[1] = str(int(split_version[1]) + 1) # take middle value and cast as int and bump it by 1 + split_version[1] = str( + int(split_version[1]) + 1 + ) # take middle value and cast as int and bump it by 1 if not pre_release: - split_version[2] = split_version[2].replace('"', '-dev"') # add -dev, ["0,18,0"] --> ["0,18,0-dev"] + split_version[2] = split_version[2].replace( + '"', '-dev"' + ) # add -dev, ["0,18,0"] --> ["0,18,0-dev"] bumped_version = ".".join(split_version) data[-1] = bumped_version @@ -61,7 +66,7 @@ def bump_version(version_line, pre_release): def update_version_file(path, pre_release=True): - """ Updates the __version__ attribute in a specific version file. + """Updates the __version__ attribute in a specific version file. Args: path (str): The path to the version file. @@ -71,21 +76,21 @@ def update_version_file(path, pre_release=True): Return: new_version (str): The bumped version string. """ - with open(path, 'r', encoding="utf8") as f: + with open(path, "r", encoding="utf8") as f: lines = f.readlines() - with open(path, 'w', encoding="utf8") as f: + with open(path, "w", encoding="utf8") as f: for line in lines: - if "__version__" in line.split(' '): + if "__version__" in line.split(" "): new_line, new_version = bump_version(line, pre_release) - f.write(new_line + '\n') + f.write(new_line + "\n") else: f.write(line) return new_version def remove_empty_headers(lines): - """ Takes a paragraph (list of strings) and removes sections which are empty. + """Takes a paragraph (list of strings) and removes sections which are empty. Where a section begins with a header (### Header_Title). Args: @@ -109,20 +114,20 @@ def remove_empty_headers(lines): pntr1 = pntr2 is_empty = True # reset the empty flag - elif line2 == '\n': + elif line2 == "\n": pass else: is_empty = False - cleaned_lines.extend(lines[pntr1:pntr1+1]) + cleaned_lines.extend(lines[pntr1 : pntr1 + 1]) pntr1 += 1 return cleaned_lines def update_changelog(path, new_version, pre_release=True): - """ Updates the Changelog file depending on whether it's a pre-release + """Updates the Changelog file depending on whether it's a pre-release or post-release version bump. Args: @@ -131,7 +136,7 @@ def update_changelog(path, new_version, pre_release=True): pre_release (bool): A flag which determines if this is a pre-release or post-release version bump. """ - with open(path, 'r', encoding="utf8") as f: + with open(path, "r", encoding="utf8") as f: lines = f.readlines() end_of_section_index = 0 for index, line in enumerate(lines): @@ -139,11 +144,13 @@ def update_changelog(path, new_version, pre_release=True): end_of_section_index = index break - with open(path, 'w', encoding="utf8") as f: + with open(path, "w", encoding="utf8") as f: if not pre_release: # post_release append template to top of the changelog - with open("./.github/workflows/changelog_template.txt", 'r', encoding="utf8") as template_f: + with open( + "./.github/workflows/changelog_template.txt", "r", encoding="utf8" + ) as template_f: template_lines = template_f.readlines() - template_lines[0] = template_lines[0].replace('x.x.x-dev', new_version) + template_lines[0] = template_lines[0].replace("x.x.x-dev", new_version) f.writelines(template_lines) f.writelines(lines) @@ -152,7 +159,7 @@ def update_changelog(path, new_version, pre_release=True): line = lines[0] split_line = line.split(" ") split_line[-1] = new_version # replace version (split_line = [#, Release, 0.17.0-dev]) - new_line = " ".join(split_line) + '\n' + new_line = " ".join(split_line) + "\n" f.write(new_line) # remover empty headers @@ -166,12 +173,22 @@ def update_changelog(path, new_version, pre_release=True): if __name__ == "__main__": parser = argparse.ArgumentParser() - parser.add_argument("--version_path", type=str, required=True, help="Path to the _version.py file") + parser.add_argument( + "--version_path", type=str, required=True, help="Path to the _version.py file" + ) parser.add_argument("--changelog_path", type=str, required=True, help="Path to the changelog") - parser.add_argument("--pre_release", dest="release_status", action="store_true", - help="True if this is a pre-release version bump, False if it is post release") - parser.add_argument("--post_release", dest="release_status", action="store_false", - help="True if this is a pre-release version bump, False if it is post release") + parser.add_argument( + "--pre_release", + dest="release_status", + action="store_true", + help="True if this is a pre-release version bump, False if it is post release", + ) + parser.add_argument( + "--post_release", + dest="release_status", + action="store_false", + help="True if this is a pre-release version bump, False if it is post release", + ) args = parser.parse_args() updated_version = update_version_file(args.version_path, args.release_status) diff --git a/bin/utils.py b/bin/utils.py index 6834078976..f33bf6a159 100644 --- a/bin/utils.py +++ b/bin/utils.py @@ -9,17 +9,18 @@ rgx_gitignore_comment = re_compile("#.*$") -def get_cpp_files_from_path(path, ignore_patterns = None, use_gitignore = True, header_only = False): + +def get_cpp_files_from_path(path, ignore_patterns=None, use_gitignore=True, header_only=False): """return set of C++ source files from a path Args: - paths (pathlib.Path or str): a path to process + paths (pathlib.Path or str): a path to process ignore_patterns: patterns to ignore use_gitignore: find ignore patterns from .gitignore header_only: find only header files when true """ path = Path(path) - files_rel = set() # file paths relative to path + files_rel = set() # file paths relative to path exts = HEADERFILE_EXT if not header_only: @@ -33,15 +34,15 @@ def get_cpp_files_from_path(path, ignore_patterns = None, use_gitignore = True, if use_gitignore: # simple gitignore parser - gitignore_file = path.joinpath('.gitignore') + gitignore_file = path.joinpath(".gitignore") if gitignore_file.exists(): with gitignore_file.open() as f: for line in f.readlines(): - line = rgx_gitignore_comment.sub('', line) + line = rgx_gitignore_comment.sub("", line) line = line.strip() if line: ignore_patterns.append(line) - + files_to_remove = set() for ignore_pattern in ignore_patterns: for f in files_rel: @@ -51,8 +52,9 @@ def get_cpp_files_from_path(path, ignore_patterns = None, use_gitignore = True, files_rel -= files_to_remove return set(str(path.joinpath(f)) for f in files_rel) - -def get_cpp_files(paths, ignore_patterns = None, use_gitignore = True, header_only = False): + + +def get_cpp_files(paths, ignore_patterns=None, use_gitignore=True, header_only=False): """return list of C++ source files from paths. Args: diff --git a/doc/conf.py b/doc/conf.py index 7a78043867..6ce30e22e2 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -105,7 +105,9 @@ def __getattr__(cls, name): breathe_projects = {"Lightning-Qubit": "./doxyoutput/xml"} breathe_default_project = "Lightning-Qubit" -mathjax_path = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML" +mathjax_path = ( + "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML" +) # Exhale extension # Setup the exhale extension @@ -130,6 +132,7 @@ def __getattr__(cls, name): # Add any paths that contain templates here, relative to this directory. from pennylane_sphinx_theme import templates_dir + templates_path = [templates_dir()] # The suffix(es) of source filenames. @@ -197,7 +200,7 @@ def __getattr__(cls, name): html_static_path = ["_static"] html_css_files = [ - 'css/custom.css', + "css/custom.css", ] # -- html theme --------------------------------------------------------- @@ -209,10 +212,9 @@ def __getattr__(cls, name): "navbar_active_link": 3, "google_analytics_tracking_id": "UA-130507810-1", "extra_copyrights": [ - "TensorFlow, the TensorFlow logo, and any related marks are trademarks " - "of Google Inc." + "TensorFlow, the TensorFlow logo, and any related marks are trademarks " "of Google Inc." ], - "toc_overview": True + "toc_overview": True, } edit_on_github_project = "PennyLaneAI/pennylane-lightning" diff --git a/setup.py b/setup.py index 36b122f4ad..23f3a2713a 100644 --- a/setup.py +++ b/setup.py @@ -20,6 +20,7 @@ from setuptools import setup, Extension, find_packages from setuptools.command.build_ext import build_ext + class CMakeExtension(Extension): def __init__(self, name, sourcedir=""): Extension.__init__(self, name, sources=[]) @@ -53,8 +54,8 @@ def build_extension(self, ext: CMakeExtension): # Set Python_EXECUTABLE instead if you use PYBIND11_FINDPYTHON configure_args = [ f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}", - f"-DPython_EXECUTABLE={sys.executable}", # (Windows) - f"-DPYTHON_EXECUTABLE={sys.executable}", # (Ubuntu) + f"-DPython_EXECUTABLE={sys.executable}", # (Windows) + f"-DPYTHON_EXECUTABLE={sys.executable}", # (Ubuntu) "-DENABLE_WARNINGS=OFF", # Ignore warnings ] @@ -83,17 +84,19 @@ def build_extension(self, ext: CMakeExtension): # Add more platform dependent options if platform.system() == "Darwin": - #To support ARM64 - if os.getenv('ARCHS') == "arm64": - configure_args += ["-DCMAKE_CXX_COMPILER_TARGET=arm64-apple-macos11", - "-DCMAKE_SYSTEM_NAME=Darwin", - "-DCMAKE_SYSTEM_PROCESSOR=ARM64"] - else: # X64 arch + # To support ARM64 + if os.getenv("ARCHS") == "arm64": + configure_args += [ + "-DCMAKE_CXX_COMPILER_TARGET=arm64-apple-macos11", + "-DCMAKE_SYSTEM_NAME=Darwin", + "-DCMAKE_SYSTEM_PROCESSOR=ARM64", + ] + else: # X64 arch llvmpath = subprocess.check_output(["brew", "--prefix", "llvm"]).decode().strip() configure_args += [ - f"-DCMAKE_CXX_COMPILER={llvmpath}/bin/clang++", - f"-DCMAKE_LINKER={llvmpath}/bin/lld", - ] # Use clang instead of appleclang + f"-DCMAKE_CXX_COMPILER={llvmpath}/bin/clang++", + f"-DCMAKE_LINKER={llvmpath}/bin/lld", + ] # Use clang instead of appleclang # Disable OpenMP in M1 Macs if os.environ.get("USE_OMP"): configure_args += [] @@ -109,7 +112,10 @@ def build_extension(self, ext: CMakeExtension): os.makedirs(self.build_temp) subprocess.check_call(["cmake", str(ext.sourcedir)] + configure_args, cwd=self.build_temp) - subprocess.check_call(["cmake", "--build", ".", "--verbose"] + build_args, cwd=self.build_temp) + subprocess.check_call( + ["cmake", "--build", ".", "--verbose"] + build_args, cwd=self.build_temp + ) + with open(os.path.join("pennylane_lightning", "_version.py")) as f: version = f.readlines()[-1].split()[-1].strip("\"'") @@ -126,7 +132,9 @@ 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": [os.path.join("src", "*"), os.path.join("src", "**", "*")]}, + "package_data": { + "pennylane_lightning": [os.path.join("src", "*"), os.path.join("src", "**", "*")] + }, "include_package_data": True, "entry_points": { "pennylane.plugins": [ @@ -143,7 +151,7 @@ def build_extension(self, ext: CMakeExtension): else [], "cmdclass": {"build_ext": CMakeBuild}, "ext_package": "pennylane_lightning", - "extras_require": {"gpu" : ["pennylane-lightning-gpu"]} + "extras_require": {"gpu": ["pennylane-lightning-gpu"]}, } classifiers = [ From b49e23e332afffc1c0459e8575e0791b537206f4 Mon Sep 17 00:00:00 2001 From: Dev version update bot Date: Fri, 3 Feb 2023 21:38:37 +0000 Subject: [PATCH 3/6] Auto update version --- pennylane_lightning/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pennylane_lightning/_version.py b/pennylane_lightning/_version.py index 4784f68305..caaa8b541b 100644 --- a/pennylane_lightning/_version.py +++ b/pennylane_lightning/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.29.0-dev6" +__version__ = "0.29.0-dev7" From 01a8ef8deada49acdb4b5d471c7e56ffa02c6d72 Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Fri, 3 Feb 2023 16:40:08 -0500 Subject: [PATCH 4/6] Update changelog --- .github/CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index c046dc327a..090c8034e6 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -6,6 +6,9 @@ ### Improvements +* Remove runtime dependench on ninja build system. +[(#414)](https://github.com/PennyLaneAI/pennylane-lightning/pull/414) + * Allow better integration and installation support with CMake targeted binary builds. [(#403)](https://github.com/PennyLaneAI/pennylane-lightning/pull/403) From 56667c60a75f5da28b7ca2aef7b4a530d5d1011f Mon Sep 17 00:00:00 2001 From: Lee James O'Riordan Date: Mon, 6 Feb 2023 10:55:05 -0500 Subject: [PATCH 5/6] Update .github/CHANGELOG.md Co-authored-by: Amintor Dusko <87949283+AmintorDusko@users.noreply.github.com> --- .github/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index 090c8034e6..faac7e0770 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -6,7 +6,7 @@ ### Improvements -* Remove runtime dependench on ninja build system. +* Remove runtime dependency on ninja build system. [(#414)](https://github.com/PennyLaneAI/pennylane-lightning/pull/414) * Allow better integration and installation support with CMake targeted binary builds. From 280ec9ea0ba02a953d93dcf39aaf4d4da02025fa Mon Sep 17 00:00:00 2001 From: Dev version update bot Date: Mon, 6 Feb 2023 19:47:09 +0000 Subject: [PATCH 6/6] Auto update version --- pennylane_lightning/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pennylane_lightning/_version.py b/pennylane_lightning/_version.py index caaa8b541b..143a7c36ed 100644 --- a/pennylane_lightning/_version.py +++ b/pennylane_lightning/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.29.0-dev7" +__version__ = "0.29.0-dev8"