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

Remove run-time dependency on ninja #414

Merged
merged 8 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
3 changes: 3 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

### Improvements

* Remove runtime dependench on ninja build system.
mlxd marked this conversation as resolved.
Show resolved Hide resolved
[(#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)

Expand Down
39 changes: 23 additions & 16 deletions .github/workflows/dev_version_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
67 changes: 42 additions & 25 deletions .github/workflows/vb_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -131,19 +136,21 @@ 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):
if (len(line) >= 3) and (line[:3] == "---"):
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)

Expand All @@ -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
Expand All @@ -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)
Expand Down
18 changes: 10 additions & 8 deletions bin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down
12 changes: 7 additions & 5 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -197,7 +200,7 @@ def __getattr__(cls, name):
html_static_path = ["_static"]

html_css_files = [
'css/custom.css',
"css/custom.css",
]

# -- html theme ---------------------------------------------------------
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion pennylane_lightning/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
Version number (major.minor.patch[-label])
"""

__version__ = "0.29.0-dev6"
__version__ = "0.29.0-dev7"
Loading