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 cpp-linter action #199

Merged
merged 50 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
ccf22bc
Add cpp-linter action
hillmich Mar 1, 2023
37715df
Run tests on all files
hillmich Mar 1, 2023
a50f8bd
Fixed first round of cpp-linter warnings
hillmich Mar 1, 2023
ed9df72
Fixed few more things
hillmich Mar 1, 2023
102e4e6
Add assertion
hillmich Mar 1, 2023
62e8893
More fixes + OpenCV
hillmich Mar 1, 2023
09f8584
More fixes
hillmich Mar 1, 2023
4c4b5e5
More fixes
hillmich Mar 1, 2023
3ef8820
More fixes
hillmich Mar 1, 2023
fa3c0a6
Clang-Tidy for Bindings
hillmich Mar 2, 2023
325fcdf
Fixed warning for benchmark.cpp
hillmich Mar 2, 2023
16adb16
Clang-Tidy for test_det_noise_sim.cpp
hillmich Mar 2, 2023
b422359
Clang-Format frqi.cpp
hillmich Mar 2, 2023
f45bc33
Clang-Tidy primebases.cpp
hillmich Mar 2, 2023
c35d452
Cland-tidy vectors.cpp
hillmich Mar 2, 2023
b6b9547
Cland-tidy noise_aware.cpp
hillmich Mar 2, 2023
0da4ebb
Fix overly eager rename
hillmich Mar 2, 2023
40423a2
Clang-Tidy fix test_det_noise_sim.cpp
hillmich Mar 2, 2023
b2e799d
Clang-Tidy noisy sim headers
hillmich Mar 2, 2023
5a0869c
Add to .gitignore
hillmich Mar 2, 2023
d6f90e7
Clang-Tidy Hybrid SchrFeyn header
hillmich Mar 2, 2023
d186452
Clang-Tidy UnitarySim header
hillmich Mar 2, 2023
eeb9926
Clang-Tidy simulator header and some fixes
hillmich Mar 2, 2023
c109b84
Clang-Tidy grover header
hillmich Mar 2, 2023
b5d1796
Clang-tidy path sim header
hillmich Mar 2, 2023
e80c3d7
Clang-Tidy fast shor header
hillmich Mar 2, 2023
2860a69
Fix warning on ShorFastSim
hillmich Mar 2, 2023
3e1e576
Clang-tidy shor sim
hillmich Mar 2, 2023
2375b93
Clang-tidy shor fast sim
hillmich Mar 2, 2023
1e63620
Clang-tidy hybrid sim
hillmich Mar 2, 2023
51147b0
Clang-tidy circuit sim
hillmich Mar 2, 2023
66f2e36
Clang-tidy base sim
hillmich Mar 2, 2023
61d5bf6
Clang-tidy grover sim
hillmich Mar 2, 2023
06b11f9
Clang-tidy det noise sim
hillmich Mar 2, 2023
8b811bc
Clang-tidy path sim
hillmich Mar 2, 2023
730d24f
Possible fix for div by zero warning
hillmich Mar 2, 2023
533d6f8
Clang-tidy stoch sim
hillmich Mar 2, 2023
1b3bcc6
Added tests/coverage
hillmich Mar 2, 2023
26dd1d8
Fixes clang-format and codeql
hillmich Mar 2, 2023
a30b677
Another fix for wrong dead code detection
hillmich Mar 2, 2023
298c2c5
Another fix for wrong dead code detection
hillmich Mar 2, 2023
384c622
Added more tests for shor sim
hillmich Mar 2, 2023
e229f7b
Fixed flaky test
hillmich Mar 2, 2023
8e16daf
Add nolint and fix test
hillmich Mar 3, 2023
dad970a
Refactored ShorSim to increase coverage
hillmich Mar 3, 2023
aae48a8
cpp-linter on changes only
hillmich Mar 3, 2023
62d6c0d
Remove non-emulated shor sim (see issue #26
hillmich Mar 3, 2023
3497574
Use plain std::unique_ptr
hillmich Mar 7, 2023
08f5949
Move semantics are hard
hillmich Mar 7, 2023
b3be5b8
Also moving from moved object is to be avoided
hillmich Mar 7, 2023
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
71 changes: 71 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
FormatStyle: file

Checks: |
clang-diagnostic-*,
clang-analyzer-*,
boost-*,
bugprone-*,
-bugprone-easily-swappable-parameters,
clang-analyzer-*,
cppcoreguidelines-*,
-cppcoreguidelines-non-private-member-variables-in-classes,
-cppcoreguidelines-special-member-functions,
-cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-macro-usage,
google-*,
-google-readability-todo,
-google-build-using-namespace,
misc-*,
-misc-no-recursion,
-misc-non-private-member-variables-in-classes,
modernize-*,
-modernize-use-trailing-return-type,
performance-*,
portability-*,
readability-*,
-readability-identifier-length,
-readability-magic-numbers,
-readability-function-cognitive-complexity
CheckOptions:
- key: readability-identifier-naming.ClassCase
value: CamelCase
- key: readability-identifier-naming.ClassIgnoredRegexp
value: ".*ZX.*|.*SWAP.*|.*CEX.*|.*DD.*|.*EQ.*"
- key: readability-identifier-naming.ConstantParameterCase
value: camelBack
- key: readability-identifier-naming.EnumCase
value: CamelCase
- key: readability-identifier-naming.EnumConstantCase
value: CamelCase
- key: readability-identifier-naming.FunctionCase
value: camelBack
- key: readability-identifier-naming.FunctionIgnoredRegexp
value: ".*ZX.*|.*SWAP.*|.*CEX.*|.*DD.*|.*EQ.*"
- key: readability-identifier-naming.GlobalConstantCase
value: UPPER_CASE
- key: readability-identifier-naming.IgnoreMainLikeFunctions
value: "true"
- key: readability-identifier-naming.LocalConstantCase
value: camelBack
- key: readability-identifier-naming.LocalVariableCase
value: camelBack
- key: readability-identifier-naming.MemberCase
value: camelBack
- key: readability-identifier-naming.MemberIgnoredRegexp
value: ".*ZX.*|.*SWAP.*|.*CEX.*|.*DD.*|.*EQ.*"
- key: readability-identifier-naming.MethodCase
value: camelBack
- key: readability-identifier-naming.ParameterCase
value: camelBack
- key: readability-identifier-naming.ParameterIgnoredRegexp
value: ".*ZX.*|.*SWAP.*|.*CEX.*|.*DD.*|.*EQ.*|.*_"
- key: readability-identifier-naming.ConstantParameterIgnoredRegexp
value: ".*ZX.*|.*SWAP.*|.*CEX.*|.*DD.*|.*EQ.*|.*_"
- key: readability-identifier-naming.NamespaceCase
value: lower_case
- key: readability-identifier-naming.StaticConstantCase
value: UPPER_CASE
- key: readability-identifier-naming.StructCase
value: CamelCase
- key: readability-identifier-naming.VariableCase
value: camelBack
41 changes: 41 additions & 0 deletions .github/workflows/cpp-linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: cpp-linter

on:
pull_request:
merge_group:
push:
branches:
- main
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
cpp-linter:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Install OpenCV
run: sudo apt install libopencv-dev
- name: Generate compilation database
run: CC=clang-14 CXX=clang++-14 cmake -S . -B build -DBINDINGS=ON -DBUILD_DDSIM_TESTS=ON
- name: Run cpp-linter
id: linter
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
pipx run cpp-linter \
--version=14 \
--style="file" \
--tidy-checks="" \
--thread-comments=true \
--files-changed-only=true \
--ignore="build" \
--database=build
- name: Fail if linter found errors
if: steps.linter.outputs.checks-failed > 0
run: echo "Linter found errors" && exit 1
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ __pycache__/
.pytest_cache/
.ipynb_checkpoints/
.ruff_cache/
.cpp-linter_cache/
.mypy_cache/
59 changes: 30 additions & 29 deletions apps/frqi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

using namespace dd::literals;

int main(int argc, char** argv) {
int main(int argc, char** argv) { // NOLINT(bugprone-exception-escape)
cxxopts::Options options("FRQI", "with MQT DDSIM by https://www.cda.cit.tum.de/ -- Allowed options");
// clang-format off
options.add_options()
Expand All @@ -24,22 +24,22 @@ int main(int argc, char** argv) {
;
// clang-format on
auto vm = options.parse(argc, argv);
if (vm.count("help")) {
if (vm.count("help") > 0) {
std::cout << options.help();
std::exit(0);
}

unsigned int numOfShots = vm["shots"].as<unsigned int>();
std::string filename = vm["file"].as<std::string>()
const unsigned int numOfShots = vm["shots"].as<unsigned int>();
const std::string filename = vm["file"].as<std::string>();

cv::Mat image,
dest;
cv::Mat genimg;
cv::Size size(32, 32);
dd::QubitCount nqubits = 11;
cv::Mat image;
cv::Mat dest;
const cv::Mat genimg;
const cv::Size size(32, 32);
const dd::QubitCount nqubits = 11;

image = imread(filename, cv::IMREAD_GRAYSCALE);
if (!image.data) {
if (image.data == nullptr) {
std::cerr << "Could not open or find the image '" << filename << "'" << std::endl;
return -1;
}
Expand All @@ -53,7 +53,9 @@ int main(int argc, char** argv) {
cv::resizeWindow("original", 128, 128);
cv::imshow("original", dest);

cv::MatIterator_<double> it, end;
cv::MatIterator_<double> it;
cv::MatIterator_<double> end;

for (it = dest.begin<double>(), end = dest.end<double>(); it != end; ++it) {
*it = std::asin(*it);
}
Expand All @@ -62,24 +64,24 @@ int main(int argc, char** argv) {
/* Preparation of the quantum circuit */
std::unique_ptr<qc::QuantumComputation> qc = std::make_unique<qc::QuantumComputation>(nqubits);

for (dd::Qubit i = 1; i < 11; i++) {
for (qc::Qubit i = 1; i < 11; i++) {
qc->h(i); // add Hadamard gates
}

int cnt = 0; // start with the x/y location at 0000000000b
for (it = dest.begin<double>(), end = dest.end<double>(); it != end; ++it) {
if (*it != 0) {
dd::Controls controls;
qc::Controls controls;
for (int i = 0; i < 10; i++) {
controls.insert({static_cast<dd::Qubit>(i + 1), (cnt & 1LL << i) ? dd::Control::Type::pos : dd::Control::Type::neg});
controls.insert({static_cast<qc::Qubit>(i + 1), (cnt & 1LL << i) != 0 ? qc::Control::Type::Pos : qc::Control::Type::Neg});
}
qc->ry(0, controls, (*it) * 2);
}
cnt++;
}
const auto t0end = std::chrono::steady_clock::now();

if (vm.count("verbose")) {
if (vm.count("verbose") > 0) {
qc->print(std::cout);
}

Expand All @@ -88,34 +90,33 @@ int main(int argc, char** argv) {
const auto t1start = std::chrono::steady_clock::now();
CircuitSimulator<> ddsim(std::move(qc));

std::vector<unsigned int> counts(1024, 0);
int cols = dest.cols;
int rows = dest.rows;
int colrows = cols * rows;
const int cols = dest.cols;
const int rows = dest.rows;
const int colrows = cols * rows;

std::map<std::string, std::size_t> m_counter = ddsim.Simulate(numOfShots);
const std::map<std::string, std::size_t> mCounter = ddsim.simulate(numOfShots);

const auto t1end = std::chrono::steady_clock::now();

std::clog << "Elapsed time for quantum simulation and measurement " << std::chrono::duration<float>(t1end - t1start).count() << " s" << std::endl;
std::clog << "size of image: " << colrows << std::endl;

unsigned int result = 0;
for (auto& elem: m_counter) {
result += elem.second;
for (const auto& [bitstring, count]: mCounter) {
result += count;
}
std::clog << "Number of distinct measurements: " << m_counter.size() << "\n";
std::clog << "Number of distinct measurements: " << mCounter.size() << "\n";
std::clog << "RESULT: " << result << std::endl;

std::vector<double> prob(1024, 0);

for (auto& elem: m_counter) {
std::size_t fixed_index = std::stoi(elem.first.substr(0, 10), nullptr, 2);
double tmp = std::sqrt(static_cast<double>(elem.second) / numOfShots) * 32. * 255.;
if (vm.count("verbose")) {
std::clog << elem.first << " (" << fixed_index << ") : " << elem.second << " (" << tmp << ")\n";
for (const auto& [bitstring, count]: mCounter) {
const std::size_t fixedIndex = std::stoul(bitstring.substr(0, 10), nullptr, 2);
const double tmp = std::sqrt(static_cast<double>(count) / numOfShots) * 32. * 255.;
if (vm.count("verbose") > 0) {
std::clog << bitstring << " (" << fixedIndex << ") : " << count << " (" << tmp << ")\n";
}
prob.at(fixed_index) = tmp;
prob.at(fixedIndex) = tmp;
}

cv::Mat final = cv::Mat(prob).reshape(0, 32);
Expand Down
Loading