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

Conversation

mlxd
Copy link
Member

@mlxd mlxd commented Oct 8, 2021

Context: To ensure modern C++ standards, we require testing of newly added code to ensure it is standards-conforming with all newly supported features. This PR enables clang-tidy with warnings-as-errors support for a variety of tidy options as defined from here

Description of the Change: Add CI-enabled checking of code-base builds with clang-tidy for the following options:

clang-tidy \
-extra-arg=-std=c++17 \
-warnings-as-errors=* \
-header-filter=.* \
-checks=-*,-llvmlibc-*,clang-analyzer-*,modernize-*,clang-analyzer-cplusplus*,openmp-*,performance-*,portability-*,readability-*

Benefits: This will ensure our codebase uses non-legacy and/or deprecated language features, as well as ensuring strict conformance to the modern C++ standard (currently C++17). In addition, this can prevent compiler-specific bugs being uncaught, which can be difficult to find between compiler versions.

Possible Drawbacks: May add additional development time to new features as developer become comfortable with the requirements of the standard.

Related GitHub Issues:

@github-actions
Copy link
Contributor

github-actions bot commented Oct 8, 2021

Hello. You may have forgotten to update the changelog!
Please edit .github/CHANGELOG.md with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name (or GitHub username) in the contributors section.

@codecov
Copy link

codecov bot commented Oct 8, 2021

Codecov Report

Merging #153 (972bf34) into master (238f4d0) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #153   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            4         4           
  Lines          182       182           
=========================================
  Hits           182       182           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 238f4d0...972bf34. Read the comment docs.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 8, 2021

Test Report (C++) on Ubuntu

       1 files  ±0         1 suites  ±0   0s ⏱️ ±0s
   327 tests ±0     327 ✔️ ±0  0 💤 ±0  0 ±0 
1 185 runs  ±0  1 185 ✔️ ±0  0 💤 ±0  0 ±0 

Results for commit 972bf34. ± Comparison against base commit 238f4d0.

This pull request removes 9 and adds 9 tests. Note that renamed tests count towards both.
runner.global ‑ AdjointJacobian::adjointJacobian/Decomposed Rot gate, non computational basis state
runner.global ‑ AdjointJacobian::adjointJacobian/Mixed gradient, tensor expval
runner.global ‑ AdjointJacobian::adjointJacobian/Multiple RX gradient, single expval per wire
runner.global ‑ AdjointJacobian::adjointJacobian/Multiple RX gradient, single expval per wire, subset of params
runner.global ‑ AdjointJacobian::adjointJacobian/Multiple RX gradient, tensor expval
runner.global ‑ AdjointJacobian::adjointJacobian/RX gradient
runner.global ‑ AdjointJacobian::adjointJacobian/RY gradient
runner.global ‑ AdjointJacobian::adjointJacobian/Single RX gradient, 2 expval
runner.global ‑ AdjointJacobian::adjointJacobian/Trainable params subset
runner.global ‑ AdjointJacobian::adjointJacobian Decomposed Rot gate, non computational basis state
runner.global ‑ AdjointJacobian::adjointJacobian Mixed Ops, Obs and TParams
runner.global ‑ AdjointJacobian::adjointJacobian Op=Mixed, Obs=[XXX]
runner.global ‑ AdjointJacobian::adjointJacobian Op=RX, Obs=Z
runner.global ‑ AdjointJacobian::adjointJacobian Op=RX, Obs=[Z,Z]
runner.global ‑ AdjointJacobian::adjointJacobian Op=RY, Obs=X
runner.global ‑ AdjointJacobian::adjointJacobian Op=[RX,RX,RX], Obs=[Z,Z,Z]
runner.global ‑ AdjointJacobian::adjointJacobian Op=[RX,RX,RX], Obs=[Z,Z,Z], TParams=[0,2]
runner.global ‑ AdjointJacobian::adjointJacobian Op=[RX,RX,RX], Obs=[ZZZ]

♻️ This comment has been updated with latest results.

@mlxd mlxd closed this Oct 8, 2021
@mlxd mlxd reopened this Oct 8, 2021
@mlxd mlxd changed the title Enable clang-tidy in CI checks Ensure Lightning adheres to C++17 modernization standard with clang-tidy Oct 8, 2021
@mlxd
Copy link
Member Author

mlxd commented Oct 13, 2021

image
As an example of the usefulness of the above changes.

@mlxd mlxd requested a review from trbromley October 13, 2021 16:23
Copy link
Member

@maliasadi maliasadi left a comment

Choose a reason for hiding this comment

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

Great PR! I didn't know that clang-tidy is this powerful really.

pennylane_lightning/src/.clang-tidy Show resolved Hide resolved
pennylane_lightning/src/.clang-tidy Show resolved Hide resolved
@mlxd
Copy link
Member Author

mlxd commented Oct 14, 2021

Hi @maliasadi , what changes were made to the clang-tidy files? I am having a hard time tracking and comparing them. These are auto-generated with 1 or 2 minor amendments, so I'm having a tough time comparing the new changes you added.

Were yours autogenerated too?

@maliasadi
Copy link
Member

Hi @maliasadi , what changes were made to the clang-tidy files? I am having a hard time tracking and comparing them. These are auto-generated with 1 or 2 minor amendments, so I'm having a tough time comparing the new changes you added.

Were yours autogenerated too?

I only re-ordered them w.r.t. their categories and didn't add any new checks there.

@mlxd
Copy link
Member Author

mlxd commented Oct 14, 2021

I only re-ordered them w.r.t. their categories and didn't add any new checks there.

Ah okay. I think we can undo these commits, as any further edits to the autogenerated files will cause a large number of line-changes here. The config used to get these is clang-tidy -extra-arg=-std=c++17 -warnings-as-errors=* -header-filter=.* -checks=-*,-llvmlibc-*,modernize-*,clang-analyzer-cplusplus*,openmp-*,performance-*,portability-*,readability-* --dump-config with an edit made to the expected complexity number. Can you revert them?

Copy link
Contributor

@trbromley trbromley left a comment

Choose a reason for hiding this comment

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

Thanks @mlxd, looks great and amazing to see the speedup! I wonder if it's worth discussing next time we meet about some of the new concepts that may be unfamiliar (at least to me), such as [[nodiscard]].

.github/workflows/format.yml Outdated Show resolved Hide resolved
.github/workflows/tests.yml Show resolved Hide resolved
pennylane_lightning/src/algorithms/AdjointDiff.hpp Outdated Show resolved Hide resolved
pennylane_lightning/src/algorithms/AdjointDiff.hpp Outdated Show resolved Hide resolved
pennylane_lightning/src/algorithms/AdjointDiff.hpp Outdated Show resolved Hide resolved
@mlxd
Copy link
Member Author

mlxd commented Oct 15, 2021

Thanks for the reviews and suggestions all!

@mlxd mlxd merged commit 410cdd4 into master Oct 15, 2021
@mlxd mlxd deleted the clang_tidy_checks branch October 15, 2021 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants