Skip to content
This repository has been archived by the owner on Dec 20, 2023. It is now read-only.

4 benchmark suite setup #9

Merged
merged 47 commits into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
bb6a28b
Merge branch 'main' into 4-benchmark-suite-setup
tyi1025 May 9, 2023
a7ba06e
✅ add Task, Executor and Result classes
tyi1025 May 15, 2023
f13c774
🎨 pre-commit fixes
pre-commit-ci[bot] May 15, 2023
5b501ea
First review suggestions taken
tyi1025 May 16, 2023
adf6e81
Merge remote-tracking branch 'origin/4-benchmark-suite-setup' into 4-…
tyi1025 May 16, 2023
ce8ba49
🎨 pre-commit fixes
pre-commit-ci[bot] May 16, 2023
3db7fe5
Refactored executor-task architecture
tyi1025 May 18, 2023
4e13383
Refactored naming
tyi1025 May 18, 2023
26c31d4
Merge remote-tracking branch 'origin/main' into 4-benchmark-suite-setup
tyi1025 May 24, 2023
d602218
Refactor simulation executor
tyi1025 May 24, 2023
d5000f4
Refactored executor and simulatorexecutor
tyi1025 May 31, 2023
0091d35
Added dummy test (other tests WIP)
tyi1025 May 31, 2023
19883eb
Refactored test code to not let the task consume the qc
tyi1025 Jun 1, 2023
62db93e
Fixed a getter function in SimulationExecutor to address a warning
tyi1025 Jun 1, 2023
e54c574
Move non-parameterized simple test case to a separate file
tyi1025 Jun 1, 2023
7911477
Clean up the test suite for SimulatorExecutors
tyi1025 Jun 1, 2023
032226e
Remove redundant comments
tyi1025 Jun 2, 2023
60c8c09
Replace absolute path with relative path
tyi1025 Jun 2, 2023
30350b2
Refactor the results json
tyi1025 Jun 2, 2023
d03e661
Added verification executor classes and a simple test
tyi1025 Jun 2, 2023
2f7032d
Delete temporarily obsolete Results class
tyi1025 Jun 2, 2023
ed137ab
Add qcec tests (incl. refactoring ddsim tests to avoid name collisions)
tyi1025 Jun 2, 2023
10cfd3b
Refactored exec and task identifier
tyi1025 Jun 2, 2023
9ae7715
Refactor Task and Executor inheritance
tyi1025 Jun 2, 2023
505053c
Clean-up
tyi1025 Jun 2, 2023
8bfad92
Make sure the alternating checker was run in alternating executor
tyi1025 Jun 2, 2023
3927554
Make sure the alternating checker was run in alternating executor
tyi1025 Jun 2, 2023
3712b00
Merge remote-tracking branch 'origin/4-benchmark-suite-setup' into 4-…
tyi1025 Jun 2, 2023
a7fea9a
Fix CI issues (WIP)
tyi1025 Jun 2, 2023
1bb3de7
Refactor architecture: set all necessary members inside of constructor
tyi1025 Jun 2, 2023
11c5ecf
Refactor simulator test to avoid empty circuits
tyi1025 Jun 2, 2023
f80e730
Refactor verification tests to avoid empty circuits
tyi1025 Jun 2, 2023
f3fea11
Remove obsolete code for coverage
tyi1025 Jun 2, 2023
e737f71
Apply suggestions from code review
tyi1025 Jun 6, 2023
0a3f956
🎨 pre-commit fixes
pre-commit-ci[bot] Jun 6, 2023
2688923
Refactoring the source code according to the review suggestions
tyi1025 Jun 8, 2023
a397089
Refactor test files to remove redundant copy
tyi1025 Jun 8, 2023
a4e752f
Track both times in execution
tyi1025 Jun 8, 2023
61c45d0
Fix ci issues
tyi1025 Jun 9, 2023
49f92f1
Fix CI issues (continued)
tyi1025 Jun 9, 2023
fa3c7e5
Refactor tests to be more flexible
tyi1025 Jun 9, 2023
37592a6
🎨 assorted cleanups
burgholzer Jun 9, 2023
f8e3dec
⚗️ try newer cpp-linter config
burgholzer Jun 9, 2023
7a96d3c
🩹 fix CI coverage configuration
burgholzer Jun 9, 2023
1b750ea
🚨 another clang-tidy warning fixed
burgholzer Jun 9, 2023
f68f5fb
♻️ remove expected output from simulation test
burgholzer Jun 9, 2023
bf32253
♻️ some restructuring
burgholzer Jun 9, 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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
name: Coverage
run: |
cmake -S . -B buildCov -DCMAKE_BUILD_TYPE=Debug -DBUILD_DD_EVAL_TESTS=ON -DENABLE_COVERAGE=ON
cmake --build buildCov --config Debug --target DDEval_test
cmake --build buildCov --config Debug
ctest -C Debug --output-on-failure --test-dir buildCov --repeat until-pass:3 --timeout 300
- if: runner.os == 'Linux'
name: Upload coverage to Codecov
Expand Down
45 changes: 34 additions & 11 deletions .github/workflows/cpp-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: cpp-linter

on:
pull_request:
merge_group:
push:
branches:
- main
Expand All @@ -12,28 +11,52 @@ concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

env:
clang-version: 16

jobs:
cpp-linter:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Install clang-${{ env.clang-version }}
run: |
sudo apt-get update
wget https://apt.llvm.org/llvm.sh -O ${{ runner.temp }}/llvm_install.sh
chmod +x ${{ runner.temp }}/llvm_install.sh
if sudo ${{ runner.temp }}/llvm_install.sh ${{ env.clang-version }}; then
sudo apt-get install -y clang-format-${{ env.clang-version }} clang-tidy-${{ env.clang-version }}
fi
echo "CC=clang-${{ env.clang-version }}" >> $GITHUB_ENV
echo "CXX=clang++-${{ env.clang-version }}" >> $GITHUB_ENV

- name: Generate compilation database
run: CC=clang-14 CXX=clang++-14 cmake -S . -B build -DBUILD_DD_EVAL_TESTS=ON
run: |
echo $CC
echo $CXX
$CC --version
$CXX --version
cmake -S . -B build -DBUILD_DD_EVAL_TESTS=ON

- name: Run cpp-linter
uses: cpp-linter/cpp-linter-action@v2
id: linter
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
pipx run cpp-linter \
--version=14 \
--style="" \
--tidy-checks="" \
--thread-comments=true \
--files-changed-only=true \
--ignore="build" \
--database=build
with:
style: ""
tidy-checks: ""
version: 16
ignore: build
thread-comments: true
step-summary: true
database: "build"
extra-args: -std=c++17
files-changed-only: true

- name: Fail if linter found errors
if: steps.linter.outputs.checks-failed > 0
run: echo "Linter found errors" && exit 1
19 changes: 19 additions & 0 deletions include/Executor.hpp
burgholzer marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include "Task.hpp"

#include <nlohmann/json.hpp>
#include <type_traits>

using json = nlohmann::json;

template <class T> class Executor {
static_assert(std::is_base_of_v<Task, T>);

public:
virtual ~Executor() = default;

virtual json execute(const T& task) = 0;

[[nodiscard]] virtual std::string getIdentifier() const = 0;
};
10 changes: 10 additions & 0 deletions include/Task.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

#include <string>

class Task {
public:
virtual ~Task() = default;

[[nodiscard]] virtual std::string getIdentifier() const = 0;
};
13 changes: 13 additions & 0 deletions include/executors/AlternatingVerificationExecutor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include "Executor.hpp"
#include "tasks/VerificationTask.hpp"

class AlternatingVerificationExecutor : public Executor<VerificationTask> {
public:
json execute(const VerificationTask& task) override;

[[nodiscard]] std::string getIdentifier() const override {
return "alternating_verification";
}
};
13 changes: 13 additions & 0 deletions include/executors/CircuitSimulatorExecutor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include "Executor.hpp"
#include "tasks/SimulationTask.hpp"

class CircuitSimulatorExecutor : public Executor<SimulationTask> {
public:
json execute(const SimulationTask& task) override;

[[nodiscard]] std::string getIdentifier() const override {
return "circuit_simulator";
};
};
24 changes: 24 additions & 0 deletions include/tasks/SimulationTask.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include "Task.hpp"

#include <memory>

namespace qc {
class QuantumComputation;
}

class SimulationTask : public Task {
public:
explicit SimulationTask() = default;
explicit SimulationTask(std::unique_ptr<qc::QuantumComputation> circ);

[[nodiscard]] std::string getIdentifier() const override;

[[nodiscard]] const std::unique_ptr<qc::QuantumComputation>& getQc() const {
return qc;
};

protected:
std::unique_ptr<qc::QuantumComputation> qc;
};
30 changes: 30 additions & 0 deletions include/tasks/VerificationTask.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

#include "Task.hpp"

#include <memory>

namespace qc {
class QuantumComputation;
}

class VerificationTask : public Task {
public:
explicit VerificationTask() = default;
VerificationTask(std::unique_ptr<qc::QuantumComputation> circ1,
std::unique_ptr<qc::QuantumComputation> circ2);

[[nodiscard]] std::string getIdentifier() const override;

[[nodiscard]] const std::unique_ptr<qc::QuantumComputation>& getQc1() const {
return qc1;
};

[[nodiscard]] const std::unique_ptr<qc::QuantumComputation>& getQc2() const {
return qc2;
};

protected:
std::unique_ptr<qc::QuantumComputation> qc1;
std::unique_ptr<qc::QuantumComputation> qc2;
};
42 changes: 22 additions & 20 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,28 @@ add_subdirectory("${PROJECT_SOURCE_DIR}/extern/ddsim" "extern/ddsim"
add_subdirectory("${PROJECT_SOURCE_DIR}/extern/qcec" "extern/qcec"
EXCLUDE_FROM_ALL)

# add_library( ${PROJECT_NAME} ${PROJECT_SOURCE_DIR}/include/checker
# ${PROJECT_SOURCE_DIR}/include/Configuration.hpp
# ${PROJECT_SOURCE_DIR}/include/EquivalenceCriterion.hpp
# ${PROJECT_SOURCE_DIR}/include/EquivalenceCheckingManager.hpp
# ${PROJECT_SOURCE_DIR}/include/ThreadSafeQueue.hpp
# EquivalenceCheckingManager.cpp checker/EquivalenceChecker.cpp
# checker/dd/DDEquivalenceChecker.cpp checker/dd/DDConstructionChecker.cpp
# checker/dd/DDSimulationChecker.cpp checker/dd/DDAlternatingChecker.cpp
# checker/dd/applicationscheme/GateCostApplicationScheme.cpp
# checker/dd/simulation/StateGenerator.cpp checker/zx/ZXChecker.cpp)
if(NOT TARGET ${PROJECT_NAME})
add_library(
${PROJECT_NAME}
${PROJECT_SOURCE_DIR}/include/Executor.hpp
${PROJECT_SOURCE_DIR}/include/executors/CircuitSimulatorExecutor.hpp
${PROJECT_SOURCE_DIR}/include/executors/AlternatingVerificationExecutor.hpp
${PROJECT_SOURCE_DIR}/include/Task.hpp
${PROJECT_SOURCE_DIR}/include/tasks/SimulationTask.hpp
${PROJECT_SOURCE_DIR}/include/tasks/VerificationTask.hpp
executors/CircuitSimulatorExecutor.cpp
executors/AlternatingVerificationExecutor.cpp
tasks/SimulationTask.cpp
tasks/VerificationTask.cpp)

add_library(${PROJECT_NAME} INTERFACE)
# set include directories
target_include_directories(
${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/include
${PROJECT_BINARY_DIR}/include)

# set include directories
target_include_directories(
${PROJECT_NAME} INTERFACE ${PROJECT_SOURCE_DIR}/include
${PROJECT_BINARY_DIR}/include)
# link to the MQT libraries
target_link_libraries(${PROJECT_NAME} PUBLIC MQT::ddsim MQT::qcec)

# link to the MQT libraries
target_link_libraries(${PROJECT_NAME} INTERFACE MQT::ddsim MQT::qcec)

# add MQT alias
add_library(MQT::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
# add MQT alias
add_library(MQT::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
endif()
33 changes: 33 additions & 0 deletions src/executors/AlternatingVerificationExecutor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "executors/AlternatingVerificationExecutor.hpp"

#include "EquivalenceCheckingManager.hpp"

json AlternatingVerificationExecutor::execute(const VerificationTask& task) {
json result;
auto const constructionStart = std::chrono::steady_clock::now();

auto equivalenceCheckingManager =
std::make_unique<ec::EquivalenceCheckingManager>(*task.getQc1(),
*task.getQc2());
equivalenceCheckingManager->disableAllCheckers();
equivalenceCheckingManager->setAlternatingChecker(true);

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

equivalenceCheckingManager->run();
result["check_results"] = equivalenceCheckingManager->getResults().json();
// Add memory usage
auto const executionStop = std::chrono::steady_clock::now();
auto const constructionTime =
std::chrono::duration_cast<std::chrono::microseconds>(executionStart -
constructionStart);
auto const execTime = std::chrono::duration_cast<std::chrono::microseconds>(
executionStop - executionStart);
result["construction_time"] = constructionTime.count();
result["execution_time"] = execTime.count();

result["executor"] = getIdentifier();
result["task"] = task.getIdentifier();

return result;
}
30 changes: 30 additions & 0 deletions src/executors/CircuitSimulatorExecutor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "executors/CircuitSimulatorExecutor.hpp"

#include "CircuitSimulator.hpp"

json CircuitSimulatorExecutor::execute(const SimulationTask& task) {
json result;
auto const constructionStart = std::chrono::steady_clock::now();

auto qc = std::make_unique<qc::QuantumComputation>(task.getQc()->clone());
auto circuitSimulator = std::make_unique<CircuitSimulator<>>(std::move(qc));

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

result["measurement_results"] = circuitSimulator->simulate(1024U);
// Add memory usage

auto const executionStop = std::chrono::steady_clock::now();
auto const constructionTime =
std::chrono::duration_cast<std::chrono::microseconds>(executionStart -
constructionStart);
auto const execTime = std::chrono::duration_cast<std::chrono::microseconds>(
executionStop - executionStart);
result["construction_time"] = constructionTime.count();
result["execution_time"] = execTime.count();

result["executor"] = getIdentifier();
result["task"] = task.getIdentifier();

return result;
}
10 changes: 10 additions & 0 deletions src/tasks/SimulationTask.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "tasks/SimulationTask.hpp"

#include "QuantumComputation.hpp"

SimulationTask::SimulationTask(std::unique_ptr<qc::QuantumComputation> circ)
: qc(std::move(circ)) {}

std::string SimulationTask::getIdentifier() const {
return "sim_" + qc->getName();
}
12 changes: 12 additions & 0 deletions src/tasks/VerificationTask.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "tasks/VerificationTask.hpp"

#include "QuantumComputation.hpp"

VerificationTask::VerificationTask(
std::unique_ptr<qc::QuantumComputation> circ1,
std::unique_ptr<qc::QuantumComputation> circ2)
: qc1(std::move(circ1)), qc2(std::move(circ2)) {}

std::string VerificationTask::getIdentifier() const {
return "ver_" + qc1->getName() + "_" + qc2->getName();
}
9 changes: 6 additions & 3 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ if(NOT TARGET gtest OR NOT TARGET gmock)
add_subdirectory("${PROJECT_SOURCE_DIR}/${GTEST_PATH}" "${GTEST_PATH}"
EXCLUDE_FROM_ALL)
endif()

package_add_test(${PROJECT_NAME}_test ${PROJECT_NAME} test_ddsim_simple.cpp
test_qcec_simple.cpp)
configure_file(${CMAKE_SOURCE_DIR}/test/sim_circuits.json
${CMAKE_CURRENT_BINARY_DIR}/sim_circuits.json COPYONLY)
configure_file(${CMAKE_SOURCE_DIR}/test/ver_circuits.json
${CMAKE_CURRENT_BINARY_DIR}/ver_circuits.json COPYONLY)
package_add_test(${PROJECT_NAME}_sim_test ${PROJECT_NAME} test_simexec.cpp)
package_add_test(${PROJECT_NAME}_ver_test ${PROJECT_NAME} test_qcecexec.cpp)
10 changes: 10 additions & 0 deletions test/sim_circuits.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"description": "two_qubit_circuit_with_two_x_gates",
"circuit": "OPENQASM 2.0;include \"qelib1.inc\";qreg q[2];x q[0];x q[1];\n"
},
{
"description": "two_qubit_circuit_with_h_z_controlled_x_swap",
"circuit": "OPENQASM 2.0;include \"qelib1.inc\";qreg q[2];cx q[0], q[1];h q[0];z q[0];h q[0];swap q[0], q[1];\n"
}
]
20 changes: 0 additions & 20 deletions test/test_ddsim_simple.cpp

This file was deleted.

19 changes: 0 additions & 19 deletions test/test_qcec_simple.cpp

This file was deleted.

Loading