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 33 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
18 changes: 18 additions & 0 deletions include/AlternatingVerificationExecutor.hpp
burgholzer marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include "EquivalenceCheckingManager.hpp"
#include "VerificationExecutor.hpp"

class AlternatingVerificationExecutor : public VerificationExecutor {
public:
AlternatingVerificationExecutor() = delete;

explicit AlternatingVerificationExecutor(
std::unique_ptr<VerificationTask> verificationTask);

json executeTask() override;
std::string getIdentifier() override;

private:
std::unique_ptr<ec::EquivalenceCheckingManager> mEquivalenceCheckingManager;
};
18 changes: 18 additions & 0 deletions include/CircuitSimulatorExecutor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include "CircuitSimulator.hpp"
#include "SimulationExecutor.hpp"

class CircuitSimulatorExecutor : public SimulationExecutor {
public:
CircuitSimulatorExecutor() = delete;

explicit CircuitSimulatorExecutor(
std::unique_ptr<SimulationTask> simulationTask);

json executeTask() override;
std::string getIdentifier() override;

private:
std::unique_ptr<CircuitSimulator<>> mCircuitSimulator;
};
17 changes: 17 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,17 @@
#pragma once

#include "Task.hpp"

#include <memory>
burgholzer marked this conversation as resolved.
Show resolved Hide resolved

class Executor {
public:
virtual ~Executor() = default;
explicit Executor() = default;

virtual json executeTask() = 0;
burgholzer marked this conversation as resolved.
Show resolved Hide resolved
virtual std::string getIdentifier() = 0;

private:
std::unique_ptr<Task> task;
burgholzer marked this conversation as resolved.
Show resolved Hide resolved
};
16 changes: 16 additions & 0 deletions include/SimulationExecutor.hpp
burgholzer marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include "Executor.hpp"
#include "SimulationTask.hpp"

class SimulationExecutor : public Executor {
public:
SimulationExecutor() = default;

const std::unique_ptr<SimulationTask>& getTask();

void setTask(std::unique_ptr<SimulationTask>& task);

protected:
std::unique_ptr<SimulationTask> mTask;
};
18 changes: 18 additions & 0 deletions include/SimulationTask.hpp
burgholzer marked this conversation as resolved.
Show resolved Hide resolved
burgholzer marked this conversation as resolved.
Show resolved Hide resolved
burgholzer marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include "QuantumComputation.hpp"
#include "Task.hpp"

class SimulationTask : public Task {
public:
SimulationTask() = default;

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

[[nodiscard]] const std::unique_ptr<qc::QuantumComputation>& getQc() const;
std::string getIdentifier() override;

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

#include <nlohmann/json.hpp>

using json = nlohmann::json;
burgholzer marked this conversation as resolved.
Show resolved Hide resolved

class Task {
public:
virtual ~Task() = default;
virtual std::string getIdentifier() = 0;
};
5 changes: 5 additions & 0 deletions include/TestHelpers.hpp
burgholzer marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#include <nlohmann/json.hpp>

void printAll(const nlohmann::json& json);
16 changes: 16 additions & 0 deletions include/VerificationExecutor.hpp
burgholzer marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include "Executor.hpp"
#include "VerificationTask.hpp"

class VerificationExecutor : public Executor {
public:
VerificationExecutor() = default;

[[nodiscard]] const std::unique_ptr<VerificationTask>& getTask() const;

void setTask(std::unique_ptr<VerificationTask>& task);

protected:
std::unique_ptr<VerificationTask> mTask;
};
22 changes: 22 additions & 0 deletions include/VerificationTask.hpp
burgholzer marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include "QuantumComputation.hpp"
#include "Task.hpp"

class VerificationTask : public Task {
public:
VerificationTask() = default;
VerificationTask(std::unique_ptr<qc::QuantumComputation> qc1,
std::unique_ptr<qc::QuantumComputation> qc2)
: qc1(std::move(qc1)), qc2(std::move(qc2)) {}
std::string getIdentifier() override;

protected:
std::unique_ptr<qc::QuantumComputation> qc1;
std::unique_ptr<qc::QuantumComputation> qc2;

public:
[[nodiscard]] const std::unique_ptr<qc::QuantumComputation>& getQc1() const;

[[nodiscard]] const std::unique_ptr<qc::QuantumComputation>& getQc2() const;
};
36 changes: 36 additions & 0 deletions src/AlternatingVerificationExecutor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "AlternatingVerificationExecutor.hpp"

AlternatingVerificationExecutor::AlternatingVerificationExecutor(
std::unique_ptr<VerificationTask> verificationTask) {
mTask = std::move(verificationTask);
auto qc1 = mTask->getQc1()->clone();
auto qc2 = mTask->getQc2()->clone();
burgholzer marked this conversation as resolved.
Show resolved Hide resolved
mEquivalenceCheckingManager =
std::make_unique<ec::EquivalenceCheckingManager>(qc1, qc2);
mEquivalenceCheckingManager->setAlternatingChecker(true);
mEquivalenceCheckingManager->setSimulationChecker(false);
mEquivalenceCheckingManager->setConstructionChecker(false);
mEquivalenceCheckingManager->setZXChecker(false);
burgholzer marked this conversation as resolved.
Show resolved Hide resolved
}

std::string AlternatingVerificationExecutor::getIdentifier() {
return "alt_ver_exe" + mTask->getIdentifier();
}

json AlternatingVerificationExecutor::executeTask() {
json result;
auto start = std::chrono::high_resolution_clock::now();

mEquivalenceCheckingManager->run();
result = mEquivalenceCheckingManager->getResults().json();
burgholzer marked this conversation as resolved.
Show resolved Hide resolved
// Add memory usage
auto stop = std::chrono::high_resolution_clock::now();
auto runtime =
std::chrono::duration_cast<std::chrono::microseconds>(stop - start);
result["runtime"] = runtime.count();
std::string const identifier =
this->getTask()->getIdentifier() + "_" + this->getIdentifier();
result["identifier"] = identifier;

return result;
}
48 changes: 28 additions & 20 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,34 @@ 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/SimulationExecutor.hpp
${PROJECT_SOURCE_DIR}/include/VerificationExecutor.hpp
${PROJECT_SOURCE_DIR}/include/CircuitSimulatorExecutor.hpp
${PROJECT_SOURCE_DIR}/include/AlternatingVerificationExecutor.hpp
${PROJECT_SOURCE_DIR}/include/Task.hpp
${PROJECT_SOURCE_DIR}/include/SimulationTask.hpp
${PROJECT_SOURCE_DIR}/include/VerificationTask.hpp
${PROJECT_SOURCE_DIR}/include/TestHelpers.hpp
TestHelpers.cpp
SimulationExecutor.cpp
CircuitSimulatorExecutor.cpp
VerificationExecutor.cpp
AlternatingVerificationExecutor.cpp
SimulationTask.cpp
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()
38 changes: 38 additions & 0 deletions src/CircuitSimulatorExecutor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "CircuitSimulatorExecutor.hpp"

CircuitSimulatorExecutor::CircuitSimulatorExecutor(
std::unique_ptr<SimulationTask> simulationTask) {
mTask = std::move(simulationTask);
auto qc = std::make_unique<qc::QuantumComputation>(mTask->getQc()->clone());
mCircuitSimulator = std::make_unique<CircuitSimulator<>>(std::move(qc));
burgholzer marked this conversation as resolved.
Show resolved Hide resolved
}

std::string CircuitSimulatorExecutor::getIdentifier() {
return "circ_sim_exe" + mTask->getIdentifier();
burgholzer marked this conversation as resolved.
Show resolved Hide resolved
}

template <typename KTy, typename VTy>
inline void toJson(json& j, const std::map<KTy, VTy>& m) {
for (const auto& entry : m) {
j[entry.first] = entry.second;
}
}
burgholzer marked this conversation as resolved.
Show resolved Hide resolved

json CircuitSimulatorExecutor::executeTask() {
json result;
auto start = std::chrono::high_resolution_clock::now();
burgholzer marked this conversation as resolved.
Show resolved Hide resolved

const auto results = mCircuitSimulator->simulate(1024U);
toJson(result, results);
tyi1025 marked this conversation as resolved.
Show resolved Hide resolved
// Add memory usage
burgholzer marked this conversation as resolved.
Show resolved Hide resolved

auto stop = std::chrono::high_resolution_clock::now();
auto runtime =
std::chrono::duration_cast<std::chrono::microseconds>(stop - start);
burgholzer marked this conversation as resolved.
Show resolved Hide resolved
result["runtime"] = runtime.count();
std::string const identifier =
this->getTask()->getIdentifier() + "_" + this->getIdentifier();
result["identifier"] = identifier;
burgholzer marked this conversation as resolved.
Show resolved Hide resolved

return result;
}
5 changes: 5 additions & 0 deletions src/SimulationExecutor.cpp
burgholzer marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "SimulationExecutor.hpp"

const std::unique_ptr<SimulationTask>& SimulationExecutor::getTask() {
return mTask;
}
7 changes: 7 additions & 0 deletions src/SimulationTask.cpp
burgholzer marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "SimulationTask.hpp"

std::string SimulationTask::getIdentifier() { return "sim_" + qc->getName(); }

const std::unique_ptr<qc::QuantumComputation>& SimulationTask::getQc() const {
return qc;
}
11 changes: 11 additions & 0 deletions src/TestHelpers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "TestHelpers.hpp"

#include <iostream>

void printAll(const nlohmann::json& jsonObject) {
for (auto it = jsonObject.begin(); it != jsonObject.end(); ++it) {
const auto& key = it.key();
const auto& value = it.value();
std::cout << key << ": " << value << std::endl;
}
burgholzer marked this conversation as resolved.
Show resolved Hide resolved
}
5 changes: 5 additions & 0 deletions src/VerificationExecutor.cpp
burgholzer marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "VerificationExecutor.hpp"

const std::unique_ptr<VerificationTask>& VerificationExecutor::getTask() const {
return mTask;
}
15 changes: 15 additions & 0 deletions src/VerificationTask.cpp
burgholzer marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "VerificationTask.hpp"

std::string VerificationTask::getIdentifier() {
return "ver_" + qc1->getName() + "_" + qc2->getName();
}

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

const std::unique_ptr<qc::QuantumComputation>&
VerificationTask::getQc2() const {
return qc2;
}
16 changes: 13 additions & 3 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ 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/circuits.json
${CMAKE_CURRENT_BINARY_DIR}/circuits.json COPYONLY)
configure_file(${CMAKE_SOURCE_DIR}/test/equi_circuits.json
${CMAKE_CURRENT_BINARY_DIR}/equi_circuits.json COPYONLY)
package_add_test(
${PROJECT_NAME}_test
${PROJECT_NAME}
test_ddsim_simple.cpp
test_qcec_simple.cpp
test_simexec_simple.cpp
test_simexec.cpp
test_qcecexec_simple.cpp
test_qcecexec.cpp)
7 changes: 7 additions & 0 deletions test/circuits.json
burgholzer marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"description": "two_qubit_circuit_with_two_x_gates",
"initial_circuit": "OPENQASM 2.0;include \"qelib1.inc\";qreg q[2];x q[0];x q[1];\n",
"expected_11": 1024
burgholzer marked this conversation as resolved.
Show resolved Hide resolved
}
]
8 changes: 8 additions & 0 deletions test/equi_circuits.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"description": "simple_circuits",
"initial_circuit1": "OPENQASM 2.0;include \"qelib1.inc\";qreg q[2];x q[0];x q[1];\n",
"initial_circuit2": "OPENQASM 2.0;include \"qelib1.inc\";qreg q[2];x q[0];x q[1];x q[0];x q[0];\n",
"expected_equivalence": "equivalent"
burgholzer marked this conversation as resolved.
Show resolved Hide resolved
}
]
Loading