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

Add clang-tidy checks, runtime and compile time information, a C++ kernel test #253

Merged
merged 48 commits into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
b6569dc
Update Util; Update doc
chaeyeunpark Mar 10, 2022
1f9590b
Add tests
chaeyeunpark Mar 10, 2022
66ceab5
Add runtime/compile info in binary
chaeyeunpark Mar 10, 2022
d237ceb
Auto update version
chaeyeunpark Mar 10, 2022
386edb6
Fix for non-biary
chaeyeunpark Mar 10, 2022
db00391
Merge branch 'pre_better_kernel_dispatch' of github.com:PennyLaneAI/p…
chaeyeunpark Mar 10, 2022
cd9027f
Format
chaeyeunpark Mar 10, 2022
da3d9ec
Update tidy
chaeyeunpark Mar 10, 2022
6f7d770
Fix for tidy
chaeyeunpark Mar 10, 2022
16df125
Trigger CI
chaeyeunpark Mar 10, 2022
6908f20
Futher update in tests
chaeyeunpark Mar 10, 2022
fd2c3f6
Apply suggestions from code review
chaeyeunpark Mar 14, 2022
de62ece
Update pennylane_lightning/src/bindings/Bindings.cpp
chaeyeunpark Mar 14, 2022
6507b59
Fix PLApprox
chaeyeunpark Mar 14, 2022
1c450d2
Update pennylane_lightning/src/tests/CreateAllWires.cpp
chaeyeunpark Mar 14, 2022
131c626
Fix createAllWires; Add NVCC/NVHPC compiler info
chaeyeunpark Mar 14, 2022
02b5e33
Fix
chaeyeunpark Mar 14, 2022
351841c
Add test for squaredNorm
chaeyeunpark Mar 14, 2022
92f0ee6
Add correct arg
chaeyeunpark Mar 15, 2022
cbe36ac
Slightly refactor static_lookup
chaeyeunpark Mar 15, 2022
26a508d
Rename AMD64 to x86_64
chaeyeunpark Mar 15, 2022
8cbef26
Add docstring
chaeyeunpark Mar 15, 2022
3ea7b49
add docstring
chaeyeunpark Mar 15, 2022
d259198
Merge remote-tracking branch 'origin/master' into pre_better_kernel_d…
chaeyeunpark Mar 15, 2022
cb3256e
Auto update version
chaeyeunpark Mar 15, 2022
4be5ac6
Format
chaeyeunpark Mar 15, 2022
ebbcf68
Small fix
chaeyeunpark Mar 16, 2022
97bc9b9
Auto update version
chaeyeunpark Mar 16, 2022
f9ec2af
Some more fix
chaeyeunpark Mar 16, 2022
34f5754
Merge remote-tracking branch 'origin/master' into pre_better_kernel_d…
chaeyeunpark Mar 16, 2022
865557e
Trigger CI
chaeyeunpark Mar 16, 2022
b5fb3ae
Merge remote-tracking branch 'origin/master' into pre_better_kernel_d…
chaeyeunpark Mar 17, 2022
86531d5
Auto update version
chaeyeunpark Mar 17, 2022
466b8ad
Merge remote-tracking branch 'origin/master' into pre_better_kernel_d…
chaeyeunpark Mar 17, 2022
cf654a7
Auto update version
chaeyeunpark Mar 17, 2022
b341f8c
Trigger CI
chaeyeunpark Mar 17, 2022
ac985c6
Trigger CI
chaeyeunpark Mar 17, 2022
00f4dc7
Trigger CI
chaeyeunpark Mar 18, 2022
a46a41f
Auto update version
chaeyeunpark Mar 18, 2022
7970643
Merge remote-tracking branch 'origin/master' into pre_better_kernel_d…
chaeyeunpark Mar 18, 2022
de3457e
Merge branch 'pre_better_kernel_dispatch' of github.com:PennyLaneAI/p…
chaeyeunpark Mar 18, 2022
b5b043a
Merge remote-tracking branch 'origin/master' into pre_better_kernel_d…
chaeyeunpark Mar 19, 2022
3bcba89
Fix doc
chaeyeunpark Mar 19, 2022
5ebb7b2
Fix for tidy
chaeyeunpark Mar 20, 2022
275c389
Remove some internal keyworks from docs
chaeyeunpark Mar 20, 2022
855e1bc
Fix test squaredNorm
chaeyeunpark Mar 20, 2022
5f2975d
Update CHANGELOG
chaeyeunpark Mar 21, 2022
dcb9a95
Trigger CI
chaeyeunpark Mar 21, 2022
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/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
python-version: 3.7

- name: Install dependencies
run: sudo apt update && sudo apt -y install clang-tidy-12 cmake g++
run: sudo apt update && sudo apt -y install clang-tidy-12 cmake g++ libomp-12-dev
chaeyeunpark marked this conversation as resolved.
Show resolved Hide resolved
env:
DEBIAN_FRONTEND: noninteractive

Expand Down
7 changes: 5 additions & 2 deletions bin/cpp-files
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ if __name__ == '__main__':
parser = argparse.ArgumentParser(
description="Output C/C++ files in json list"
)
parser.add_argument(
"--header-only", action='store_true', dest='header_only', help="whether only include header files"
)
parser.add_argument(
"paths", nargs="+", metavar="DIR", help="paths to the root source directories"
)
Expand All @@ -23,9 +26,9 @@ if __name__ == '__main__':

args = parser.parse_args()

files = set(get_cpp_files(args.paths))
files = set(get_cpp_files(args.paths, header_only = args.header_only))
if args.exclude_dirs:
files_excludes = set(get_cpp_files(args.exclude_dirs))
files_excludes = set(get_cpp_files(args.exclude_dirs, header_only = args.header_only))
files -= files_excludes

json.dump(list(files), sys.stdout)
15 changes: 10 additions & 5 deletions bin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
import re
chaeyeunpark marked this conversation as resolved.
Show resolved Hide resolved
import fnmatch

SRCFILE_EXT = ("c", "cc", "cpp", "cxx", "h", "hh", "hpp", "hxx", "cu", "cuh")
SRCFILE_EXT = ["c", "cc", "cpp", "cxx", "cu"]
HEADERFILE_EXT = ["h", "hh", "hpp", "hxx", "cuh"]

LIGHTNING_SOURCE_DIR = Path(__file__).resolve().parent.parent

rgx_gitignore_comment = re.compile("#.*$")

def get_cpp_files_from_path(path, ignore_patterns = None, use_gitignore = True):
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:
chaeyeunpark marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -18,7 +19,11 @@ def get_cpp_files_from_path(path, ignore_patterns = None, use_gitignore = True):
"""
path = Path(path)
files_rel = set() # file paths relative to path
for ext in SRCFILE_EXT:

exts = HEADERFILE_EXT
if not header_only:
exts += SRCFILE_EXT
for ext in exts:
for file_path in path.rglob(f"*.{ext}"):
files_rel.add(file_path.relative_to(path))

Expand Down Expand Up @@ -46,7 +51,7 @@ def get_cpp_files_from_path(path, ignore_patterns = None, use_gitignore = True):

return set(str(path.joinpath(f)) for f in files_rel)

def get_cpp_files(paths, ignore_patterns = None, use_gitignore = True):
def get_cpp_files(paths, ignore_patterns = None, use_gitignore = True, header_only = False):
"""return list of C++ source files from paths.

Args:
chaeyeunpark marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -56,5 +61,5 @@ def get_cpp_files(paths, ignore_patterns = None, use_gitignore = True):
"""
files = set()
for path in paths:
files |= get_cpp_files_from_path(path, ignore_patterns, use_gitignore)
files |= get_cpp_files_from_path(path, ignore_patterns, use_gitignore, header_only)
return list(files)
14 changes: 14 additions & 0 deletions cmake/process_options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ else()
message(STATUS "ENABLE_AVX is OFF")
endif()

if(ENABLE_AVX2)
chaeyeunpark marked this conversation as resolved.
Show resolved Hide resolved
message(STATUS "ENABLE_AVX2 is ON.")
target_compile_options(lightning_compile_options INTERFACE -mavx2)
else()
message(STATUS "ENABLE_AVX2 is OFF")
endif()

if(ENABLE_AVX512)
message(STATUS "ENABLE_AVX512 is ON.")
target_compile_options(lightning_compile_options INTERFACE -mavx512f) # Now we only use avx512f
else()
message(STATUS "ENABLE_AVX512 is OFF")
endif()

if(ENABLE_OPENMP)
message(STATUS "ENABLE_OPENMP is ON.")
find_package(OpenMP)
Expand Down
27 changes: 14 additions & 13 deletions doc/_ext/edit_on_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@
import warnings
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This file is also just formatted with black



__licence__ = 'BSD (3 clause)'
__licence__ = "BSD (3 clause)"


def get_github_url(app, view, path):
return 'https://github.com/{project}/{view}/{branch}/{path}'.format(
return "https://github.com/{project}/{view}/{branch}/{path}".format(
project=app.config.edit_on_github_project,
view=view,
branch=app.config.edit_on_github_branch,
path=path)
path=path,
)


def html_page_context(app, pagename, templatename, context, doctree):
if templatename != 'page.html':
if templatename != "page.html":
return

if not app.config.edit_on_github_project:
Expand All @@ -29,16 +30,16 @@ def html_page_context(app, pagename, templatename, context, doctree):

if not doctree:
return

path = os.path.relpath(doctree.get('source'), app.builder.srcdir)
show_url = get_github_url(app, 'blob', path)
edit_url = get_github_url(app, 'edit', path)

context['show_on_github_url'] = show_url
context['edit_on_github_url'] = edit_url
path = os.path.relpath(doctree.get("source"), app.builder.srcdir)
show_url = get_github_url(app, "blob", path)
edit_url = get_github_url(app, "edit", path)

context["show_on_github_url"] = show_url
context["edit_on_github_url"] = edit_url


def setup(app):
app.add_config_value('edit_on_github_project', '', True)
app.add_config_value('edit_on_github_branch', 'master', True)
app.connect('html-page-context', html_page_context)
app.add_config_value("edit_on_github_project", "", True)
app.add_config_value("edit_on_github_branch", "master", True)
app.connect("html-page-context", html_page_context)
94 changes: 47 additions & 47 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,46 +20,50 @@
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0, os.path.abspath(''))
sys.path.insert(0, os.path.abspath('_ext'))
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath('doc')), 'doc'))
sys.path.insert(0, os.path.abspath(""))
sys.path.insert(0, os.path.abspath("_ext"))
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath("doc")), "doc"))


# For obtaining all relevant C++ source files
currdir = Path(__file__).resolve().parent # PROJECT_SOURCE_DIR/docs
currdir = Path(__file__).resolve().parent # PROJECT_SOURCE_DIR/docs
PROJECT_SOURCE_DIR = currdir.parent
CPP_SOURCE_DIR = PROJECT_SOURCE_DIR.joinpath('pennylane_lightning/src')
CPP_EXCLUDE_DIRS = ['examples', 'tests'] # relative to CPP_SOURCE_DIR
CPP_SOURCE_DIR = PROJECT_SOURCE_DIR.joinpath("pennylane_lightning/src")
CPP_EXCLUDE_DIRS = ["examples", "tests"] # relative to CPP_SOURCE_DIR


def obtain_cpp_files():
script_path = PROJECT_SOURCE_DIR.joinpath('bin/cpp-files')
script_path = PROJECT_SOURCE_DIR.joinpath("bin/cpp-files")

if not script_path.exists():
print('The project directory structure is corrupted.')
print("The project directory structure is corrupted.")
sys.exit(1)

exclude_dirs = [CPP_SOURCE_DIR.joinpath(exclude_dir) for exclude_dir in CPP_EXCLUDE_DIRS]

p = subprocess.run([str(script_path), CPP_SOURCE_DIR, '--exclude-dirs', *exclude_dirs], capture_output = True)
p = subprocess.run(
[str(script_path), "--header-only", CPP_SOURCE_DIR, "--exclude-dirs", *exclude_dirs],
capture_output=True,
)
file_list = json.loads(p.stdout)

file_list = ['../' + str(Path(f).relative_to(PROJECT_SOURCE_DIR)) for f in file_list]
file_list = ["../" + str(Path(f).relative_to(PROJECT_SOURCE_DIR)) for f in file_list]
return file_list


CPP_FILES = obtain_cpp_files()
print(CPP_FILES)



class Mock(MagicMock):
__name__ = 'foo'
__name__ = "foo"

@classmethod
def __getattr__(cls, name):
return MagicMock()


MOCK_MODULES = ['pennylane_lightning.lightning_qubit_ops']
MOCK_MODULES = ["pennylane_lightning.lightning_qubit_ops"]

mock = Mock()
for mod_name in MOCK_MODULES:
Expand All @@ -68,7 +72,7 @@ def __getattr__(cls, name):
# -- General configuration ------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
needs_sphinx = '1.6'
needs_sphinx = "1.6"
chaeyeunpark marked this conversation as resolved.
Show resolved Hide resolved

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
Expand All @@ -85,9 +89,9 @@ def __getattr__(cls, name):
"sphinx.ext.mathjax",
"sphinx.ext.napoleon",
"sphinx.ext.todo",
'sphinx.ext.viewcode',
"sphinx.ext.viewcode",
"sphinx_automodapi.automodapi",
'sphinx_automodapi.smart_resolver'
"sphinx_automodapi.smart_resolver",
]

intersphinx_mapping = {"https://pennylane.readthedocs.io/en/stable/": None}
Expand All @@ -114,10 +118,7 @@ def __getattr__(cls, name):
# TIP: if using the sphinx-bootstrap-theme, you need
# "treeViewIsBootstrap": True,
"exhaleExecutesDoxygen": True,
"exhaleDoxygenStdin": (
"INPUT = " + ' '.join(CPP_FILES) + ' '
"EXCLUDE_SYMBOLS = std::* "
),
"exhaleDoxygenStdin": ("INPUT = " + " ".join(CPP_FILES) + " " "EXCLUDE_SYMBOLS = std::* "),
"afterTitleDescription": inspect.cleandoc(
"""
The Pennylane Lightning C++ API is intended to be called from Python through Pybind11. Direct use of the C++ API is currently unsupported and is provided for reference only.
Expand All @@ -126,21 +127,21 @@ def __getattr__(cls, name):
}

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates', 'xanadu_theme']
templates_path = ["_templates", "xanadu_theme"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
source_suffix = ".rst"

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# General information about the project.
project = 'PennyLane-Lightning'
project = "PennyLane-Lightning"
copyright = "Copyright 2021"
author = 'Xanadu Inc.'
author = "Xanadu Inc."

add_module_names = False

Expand All @@ -149,11 +150,12 @@ def __getattr__(cls, name):
# built documents.

import pennylane_lightning

# The full version, including alpha/beta/rc tags.
release = pennylane_lightning.__version__

# The short X.Y version.
version = re.match(r'^(\d+\.\d+)', release).expand(r'\1')
version = re.match(r"^(\d+\.\d+)", release).expand(r"\1")

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand All @@ -163,19 +165,19 @@ def __getattr__(cls, name):
language = None

# today_fmt is used as the format for a strftime call.
today_fmt = '%Y-%m-%d'
today_fmt = "%Y-%m-%d"

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
show_authors = True

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = True
Expand All @@ -186,39 +188,37 @@ def __getattr__(cls, name):
# The name of an image file (relative to this directory) to use as a favicon of
# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
html_favicon = '_static/favicon.ico'
html_favicon = "_static/favicon.ico"

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
#
# This is required for the alabaster theme
# refs: http://alabaster.readthedocs.io/en/latest/installation.html#sidebars
html_sidebars = {
'**' : [
'logo-text.html',
'searchbox.html',
'globaltoc.html',
"**": [
"logo-text.html",
"searchbox.html",
"globaltoc.html",
]
}


# -- Xanadu theme ---------------------------------------------------------
html_theme = 'xanadu_theme'
html_theme_path = ['.']
html_theme = "xanadu_theme"
html_theme_path = ["."]

# xanadu theme options (see theme.conf for more information)
html_theme_options = {
# Set the name of the project to appear in the left sidebar.
"project_nav_name": "PennyLane-Lightning",

# Path to a touch icon
"touch_icon": "logo_new.png",

"large_toc": True,
"navigation_button": "#19b37b",
"navigation_button_hover": "#0e714d",
Expand All @@ -229,22 +229,22 @@ def __getattr__(cls, name):
"download_button": "#19b37b",
}

edit_on_github_project = 'XanaduAI/pennylane-lightning'
edit_on_github_branch = 'master/doc'
edit_on_github_project = "XanaduAI/pennylane-lightning"
chaeyeunpark marked this conversation as resolved.
Show resolved Hide resolved
edit_on_github_branch = "master/doc"

#============================================================
# ============================================================

# the order in which autodoc lists the documented members
autodoc_member_order = 'bysource'
autodoc_member_order = "bysource"

# inheritance_diagram graphviz attributes
inheritance_node_attrs = dict(color='lightskyblue1', style='filled')
inheritance_node_attrs = dict(color="lightskyblue1", style="filled")

#autodoc_default_flags = ['members']
# autodoc_default_flags = ['members']
autosummary_generate = True

from directives import CustomDeviceGalleryItemDirective

def setup(app):
app.add_directive('devicegalleryitem', CustomDeviceGalleryItemDirective)

def setup(app):
app.add_directive("devicegalleryitem", CustomDeviceGalleryItemDirective)
Loading