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

Commit

Permalink
Merge pull request #9 from tyi1025/4-benchmark-suite-setup
Browse files Browse the repository at this point in the history
4 benchmark suite setup
  • Loading branch information
tyi1025 authored Jun 9, 2023
2 parents e032131 + bf32253 commit 1788d78
Show file tree
Hide file tree
Showing 20 changed files with 422 additions and 74 deletions.
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
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

0 comments on commit 1788d78

Please sign in to comment.