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

Ensure Lightning adheres to C++17 modernization standard with clang-tidy #153

Merged
merged 47 commits into from
Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
b368a32
Enable clang-tidy in CI checks
mlxd Oct 8, 2021
aeda590
Update clang-tidy binary name
mlxd Oct 8, 2021
e530112
Ensure formatting run within PRs
mlxd Oct 8, 2021
4b99607
Remove path details from CI
mlxd Oct 8, 2021
df8751d
Fix envvar for Github Actions
mlxd Oct 8, 2021
16e8787
Fix fix binary path for tidy
mlxd Oct 8, 2021
ab2771c
Favour trailing return type in gate definition templates
mlxd Oct 8, 2021
4466175
Fix formatting after tidying
mlxd Oct 8, 2021
a300c19
Ensure consistent use of trailing returns
mlxd Oct 8, 2021
b25c863
Update error objects
mlxd Oct 8, 2021
cc6e91f
Remove redundant const in gate defns
mlxd Oct 8, 2021
41b1029
Ensure perfect forwarding of exception strings
mlxd Oct 8, 2021
3694768
Define literals before returns
mlxd Oct 8, 2021
3c26750
Ensure trialing returns, replace of bind with lambda and const adjust…
mlxd Oct 8, 2021
741d422
Enable C++20-like remove cv-ness
mlxd Oct 12, 2021
65f3dbf
Ensure correct offloading handled in lightning error types
mlxd Oct 12, 2021
7592f1a
Favour trailing return types for SV managed
mlxd Oct 12, 2021
0b0857f
Update init'ing and add nosdiscard where applicable to SV
mlxd Oct 12, 2021
6d6590e
Move clang-tidy options to source tree
mlxd Oct 12, 2021
c28d10e
Fix env var setup on Github Actions
mlxd Oct 12, 2021
3d334ad
Modernize adjoint diff implementation
mlxd Oct 12, 2021
d9996b8
Add auto fixes to Bindings
mlxd Oct 12, 2021
66f896d
Fix formatting
mlxd Oct 12, 2021
b533b89
Fix binding modernization
mlxd Oct 12, 2021
7458417
Fix test conformance
mlxd Oct 12, 2021
592e963
Avoid errors across diff compiler versions
mlxd Oct 12, 2021
eabc84a
Fix warning in adjdif
mlxd Oct 12, 2021
962083a
Avoid OMP compile failure in manylinux2010 gcc
mlxd Oct 12, 2021
dd9cce9
Remove empty lines
mlxd Oct 12, 2021
2a51586
Add test-only clang-tidy options
mlxd Oct 13, 2021
5024ac5
Fix logic error in adjdiff
mlxd Oct 13, 2021
8b90cb4
Add Python setup to format checks
mlxd Oct 13, 2021
6a015b5
Ensure Python env setup prior to test build CI
mlxd Oct 13, 2021
8f31cce
Refactor adjoint diff to reduce complexity
mlxd Oct 13, 2021
60fea62
Update changelog
mlxd Oct 13, 2021
052ef9c
Update .clang-tidy
maliasadi Oct 13, 2021
107d9d4
Update Bindings.cpp
maliasadi Oct 14, 2021
f160319
Trigger CI
mlxd Oct 14, 2021
feae1f2
Merge branch 'clang_tidy_checks' of github.com:PennyLaneAI/pennylane-…
mlxd Oct 14, 2021
d758ded
Revert my changes
maliasadi Oct 14, 2021
17e0be9
Merge branch 'clang_tidy_checks' of github.com:PennyLaneAI/pennylane-…
mlxd Oct 14, 2021
025d3b1
Disable format rules for OpenMP pragmas
mlxd Oct 14, 2021
6638b4b
Fix misplaced format selector
mlxd Oct 14, 2021
0d649f4
Update formatting CI env
mlxd Oct 14, 2021
96711f5
Remove deleted method
mlxd Oct 14, 2021
ee5fda3
Fix comment issues for clang-format
mlxd Oct 14, 2021
972bf34
Avoid ARM mac wheels built during PRs
mlxd Oct 15, 2021
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 @@ -4,6 +4,9 @@

### Improvements

* PennyLane-Lightning has been updated to conform with clang-tidy recommendations for modernization, offering performance improvements across all use-cases.
[(#153)](https://github.com/PennyLaneAI/pennylane-lightning/pull/153)

### Documentation

### Breaking changes
Expand Down
37 changes: 31 additions & 6 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
name: Formatting check
on:
pull_request:
push:
branches:
- master
paths:
- "pennylane_lightning/**"
- "tests/**"
push:
branches:
- master

jobs:
black:
Expand All @@ -32,6 +29,34 @@ jobs:
- name: Run Black
run: black -l 100 pennylane_lightning/ --check

tidy-cpp:
name: Tidy (C++)
runs-on: ubuntu-20.04

steps:
- name: Cancel previous runs
uses: styfle/cancel-workflow-action@0.4.1
with:
access_token: ${{ github.token }}

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8

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

- name: Checkout code
uses: actions/checkout@v2

- name: Run clang-tidy compilation
run: |
cmake -BBuild -DENABLE_CLANG_TIDY=on -DCLANG_TIDY_BINARY=clang-tidy-11 .
cmake --build ./Build

format-cpp:
name: Format (C++)
runs-on: ubuntu-20.04
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ jobs:
with:
access_token: ${{ github.token }}

- uses: actions/setup-python@v2
name: Install Python
with:
python-version: '3.7'
trbromley marked this conversation as resolved.
Show resolved Hide resolved

- uses: actions/checkout@v2

- name: Install dependencies
Expand Down Expand Up @@ -55,7 +60,6 @@ jobs:
os: [ubuntu-20.04]

steps:

- name: Checkout PennyLane-Lightning
uses: actions/checkout@v2
with:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/wheel_linux_x86_64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ env:
CIBW_TEST_COMMAND: |
pl-device-test --device=lightning.qubit --skip-ops -x --tb=short --no-flaky-report

CIBW_MANYLINUX_X86_64_IMAGE: manylinux2014

jobs:
linux-wheels-x86-64:
strategy:
Expand Down
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ endif()
option(ENABLE_NATIVE "Enable native CPU build tuning" OFF)
option(BUILD_TESTS "Build cpp tests" OFF)
option(ENABLE_WARNINGS "Enable warnings" ON)
option(ENABLE_CLANG_TIDY "Enable clang-tidy build checks" OFF)

if(ENABLE_CLANG_TIDY)
if (NOT DEFINED CLANG_TIDY_BINARY)
set(CLANG_TIDY_BINARY clang-tidy)
endif()
set(CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_BINARY};
-extra-arg=-std=c++17;
)
endif()

# Add pybind11
include(FetchContent)
Expand Down
232 changes: 232 additions & 0 deletions pennylane_lightning/src/.clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
---
Checks: 'clang-diagnostic-*,clang-analyzer-*,-*,-llvmlibc-*,modernize-*,-modernize-use-trailing-return-type,clang-analyzer-cplusplus*,openmp-*,performance-*,portability-*,readability-*'
WarningsAsErrors: '*'
HeaderFilterRegex: '.*'
AnalyzeTemporaryDtors: false
FormatStyle: none
InheritParentConfig: true
User: mlxd
CheckOptions:
- key: modernize-replace-auto-ptr.IncludeStyle
maliasadi marked this conversation as resolved.
Show resolved Hide resolved
value: llvm
- key: performance-move-const-arg.CheckTriviallyCopyableMove
value: 'true'
- key: modernize-use-auto.MinTypeNameLength
value: '5'
- key: readability-static-accessed-through-instance.NameSpecifierNestingThreshold
value: '3'
- key: readability-function-size.VariableThreshold
value: '4294967295'
- key: cert-dcl16-c.NewSuffixes
value: 'L;LL;LU;LLU'
- key: readability-identifier-naming.GetConfigPerFile
value: 'true'
- key: readability-inconsistent-declaration-parameter-name.Strict
value: 'false'
- key: readability-magic-numbers.IgnoredIntegerValues
value: '1;2;3;4;'
- key: modernize-use-default-member-init.UseAssignment
value: 'false'
- key: readability-function-size.NestingThreshold
value: '4294967295'
- key: modernize-use-override.AllowOverrideAndFinal
value: 'false'
- key: readability-function-size.ParameterThreshold
value: '4294967295'
- key: openmp-exception-escape.IgnoredExceptions
value: ''
- key: modernize-pass-by-value.ValuesOnly
value: 'false'
- key: modernize-loop-convert.IncludeStyle
value: llvm
- key: cert-str34-c.DiagnoseSignedUnsignedCharComparisons
value: '0'
- key: readability-identifier-naming.AggressiveDependentMemberLookup
value: 'false'
- key: readability-redundant-smartptr-get.IgnoreMacros
value: 'true'
- key: modernize-use-emplace.TupleTypes
value: '::std::pair;::std::tuple'
- key: modernize-use-emplace.TupleMakeFunctions
value: '::std::make_pair;::std::make_tuple'
- key: modernize-use-nodiscard.ReplacementString
value: '[[nodiscard]]'
- key: modernize-loop-convert.MakeReverseRangeHeader
value: ''
- key: modernize-replace-random-shuffle.IncludeStyle
value: llvm
- key: modernize-use-bool-literals.IgnoreMacros
value: 'true'
- key: google-readability-namespace-comments.ShortNamespaceLines
value: '10'
- key: modernize-avoid-bind.PermissiveParameterList
value: 'false'
- key: modernize-use-override.FinalSpelling
value: final
- key: performance-move-constructor-init.IncludeStyle
value: llvm
- key: modernize-loop-convert.UseCxx20ReverseRanges
value: 'true'
- key: modernize-use-noexcept.ReplacementString
value: ''
- key: modernize-use-using.IgnoreMacros
value: 'true'
- key: performance-type-promotion-in-math-fn.IncludeStyle
value: llvm
- key: modernize-loop-convert.NamingStyle
value: CamelCase
- key: modernize-loop-convert.MakeReverseRangeFunction
value: ''
- key: readability-inconsistent-declaration-parameter-name.IgnoreMacros
value: 'true'
- key: performance-no-automatic-move.AllowedTypes
value: ''
- key: performance-for-range-copy.WarnOnAllAutoCopies
value: 'false'
- key: readability-identifier-naming.IgnoreFailedSplit
value: 'false'
- key: modernize-pass-by-value.IncludeStyle
value: llvm
- key: readability-qualified-auto.AddConstToQualified
value: 'true'
- key: readability-simplify-boolean-expr.ChainedConditionalReturn
value: 'false'
- key: readability-else-after-return.WarnOnConditionVariables
value: 'true'
- key: readability-uppercase-literal-suffix.IgnoreMacros
value: 'true'
- key: modernize-use-nullptr.NullMacros
value: 'NULL'
- key: modernize-make-shared.IgnoreMacros
value: 'true'
- key: performance-unnecessary-copy-initialization.AllowedTypes
value: ''
- key: modernize-use-transparent-functors.SafeMode
value: 'false'
- key: modernize-make-shared.IgnoreDefaultInitialization
value: 'true'
- key: modernize-make-shared.IncludeStyle
value: llvm
- key: readability-simplify-boolean-expr.ChainedConditionalAssignment
value: 'false'
- key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField
value: '0'
- key: readability-function-size.LineThreshold
value: '4294967295'
- key: performance-inefficient-vector-operation.EnableProto
value: 'false'
- key: modernize-use-override.IgnoreDestructors
value: 'false'
- key: modernize-loop-convert.MaxCopySize
value: '16'
- key: modernize-make-shared.MakeSmartPtrFunction
value: 'std::make_shared'
- key: portability-simd-intrinsics.Suggest
value: 'false'
- key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors
value: '1'
- key: modernize-make-unique.IgnoreMacros
value: 'true'
- key: modernize-make-shared.MakeSmartPtrFunctionHeader
value: '<memory>'
- key: performance-for-range-copy.AllowedTypes
value: ''
- key: readability-redundant-string-init.StringNames
value: '::std::basic_string_view;::std::basic_string'
- key: modernize-make-unique.IgnoreDefaultInitialization
value: 'true'
- key: modernize-use-emplace.ContainersWithPushBack
value: '::std::vector;::std::list;::std::deque'
- key: readability-magic-numbers.IgnoreBitFieldsWidths
value: 'true'
- key: modernize-make-unique.IncludeStyle
value: llvm
- key: readability-braces-around-statements.ShortStatementLines
value: '0'
- key: modernize-use-override.OverrideSpelling
value: override
- key: readability-magic-numbers.IgnoredFloatingPointValues
value: '1.0;100.0;'
- key: performance-inefficient-string-concatenation.StrictMode
value: 'false'
- key: readability-implicit-bool-conversion.AllowPointerConditions
value: 'false'
- key: readability-redundant-declaration.IgnoreMacros
value: 'true'
- key: google-readability-braces-around-statements.ShortStatementLines
value: '1'
- key: modernize-make-unique.MakeSmartPtrFunction
value: 'std::make_unique'
- key: portability-restrict-system-includes.Includes
value: '*'
- key: readability-else-after-return.WarnOnUnfixable
value: 'true'
- key: modernize-use-emplace.IgnoreImplicitConstructors
value: 'false'
- key: modernize-make-unique.MakeSmartPtrFunctionHeader
value: '<memory>'
- key: modernize-use-equals-delete.IgnoreMacros
value: 'true'
- key: readability-magic-numbers.IgnoreAllFloatingPointValues
value: 'false'
- key: readability-uppercase-literal-suffix.NewSuffixes
value: ''
- key: modernize-loop-convert.MinConfidence
value: reasonable
- key: performance-unnecessary-value-param.AllowedTypes
value: ''
- key: modernize-use-noexcept.UseNoexceptFalse
value: 'true'
- key: google-readability-namespace-comments.SpacesBeforeComments
value: '2'
- key: readability-function-cognitive-complexity.Threshold
value: '45'
- key: readability-function-cognitive-complexity.IgnoreMacros
value: 'true'
- key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
value: '1'
- key: performance-faster-string-find.StringLikeClasses
value: '::std::basic_string;::std::basic_string_view'
- key: readability-function-size.BranchThreshold
value: '4294967295'
- key: readability-implicit-bool-conversion.AllowIntegerConditions
value: 'false'
- key: readability-function-size.StatementThreshold
value: '800'
- key: modernize-use-default-member-init.IgnoreMacros
value: 'true'
- key: llvm-qualified-auto.AddConstToQualified
value: '0'
- key: readability-identifier-naming.IgnoreMainLikeFunctions
value: 'false'
- key: google-readability-function-size.StatementThreshold
value: '800'
- key: llvm-else-after-return.WarnOnConditionVariables
value: '0'
- key: modernize-raw-string-literal.DelimiterStem
value: lit
- key: modernize-use-equals-default.IgnoreMacros
value: 'true'
- key: modernize-raw-string-literal.ReplaceShorterLiterals
value: 'false'
- key: modernize-use-emplace.SmartPointers
value: '::std::shared_ptr;::std::unique_ptr;::std::auto_ptr;::std::weak_ptr'
- key: performance-inefficient-vector-operation.VectorLikeClasses
value: '::std::vector'
- key: modernize-use-auto.RemoveStars
value: 'false'
- key: readability-magic-numbers.IgnorePowersOf2IntegerValues
value: 'false'
- key: portability-simd-intrinsics.Std
value: ''
- key: readability-redundant-member-init.IgnoreBaseInCopyConstructors
value: 'false'
- key: performance-unnecessary-value-param.IncludeStyle
value: llvm
- key: modernize-replace-disallow-copy-and-assign-macro.MacroName
value: DISALLOW_COPY_AND_ASSIGN
- key: llvm-else-after-return.WarnOnUnfixable
value: '0'
- key: readability-simplify-subscript-expr.Types
value: '::std::basic_string;::std::basic_string_view;::std::vector;::std::array'
...
maliasadi marked this conversation as resolved.
Show resolved Hide resolved
Loading