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 1 commit
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
Prev Previous commit
Next Next commit
🎨 assorted cleanups
  • Loading branch information
burgholzer committed Jun 9, 2023
commit 37592a6d2acd2863e210f179250f2ce617960a6c
6 changes: 3 additions & 3 deletions include/Executor.hpp
burgholzer marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ template <class T> class Executor {

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

virtual json execute(const T& task) = 0;
[[nodiscard]] virtual std::string getIdentifier() const = 0;
virtual json execute(const T& task) = 0;

[[nodiscard]] virtual std::string getIdentifier() const = 0;
};
3 changes: 2 additions & 1 deletion include/Task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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

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

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

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

json execute(const VerificationTask& task) override;
[[nodiscard]] std::string getIdentifier() const override {
return "alternating_verification";
}
Expand Down
4 changes: 1 addition & 3 deletions include/executors/CircuitSimulatorExecutor.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#pragma once

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

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

json execute(const SimulationTask& task) override;
[[nodiscard]] std::string getIdentifier() const override {
return "circuit_simulator";
};
Expand Down
13 changes: 6 additions & 7 deletions include/tasks/SimulationTask.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@

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

explicit SimulationTask(std::unique_ptr<qc::QuantumComputation> qc)
: qc(std::move(qc)) {}
[[nodiscard]] std::string getIdentifier() const override {
return "sim_" + qc->getName();
};

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

[[nodiscard]] std::string getIdentifier() const override {
return "sim_" + qc->getName();
};

protected:
std::unique_ptr<qc::QuantumComputation> qc;
};
18 changes: 9 additions & 9 deletions include/tasks/VerificationTask.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@

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)) {}
explicit VerificationTask() = default;
VerificationTask(std::unique_ptr<qc::QuantumComputation> circ1,
std::unique_ptr<qc::QuantumComputation> circ2)
: qc1(std::move(circ1)), qc2(std::move(circ2)) {}

[[nodiscard]] std::string getIdentifier() const override {
return "ver_" + qc1->getName() + "_" + qc2->getName();
};

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

public:
[[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;
};
4 changes: 2 additions & 2 deletions src/AlternatingVerificationExecutor.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "executors/AlternatingVerificationExecutor.hpp"

#include "EquivalenceCheckingManager.hpp"

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

auto qc1 = task.getQc1()->clone();
auto qc2 = task.getQc2()->clone();
auto equivalenceCheckingManager =
std::make_unique<ec::EquivalenceCheckingManager>(*task.getQc1(),
*task.getQc2());
Expand Down
2 changes: 2 additions & 0 deletions src/CircuitSimulatorExecutor.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "executors/CircuitSimulatorExecutor.hpp"

#include "CircuitSimulator.hpp"

json CircuitSimulatorExecutor::execute(const SimulationTask& task) {
json result;
auto const constructionStart = std::chrono::steady_clock::now();
Expand Down
12 changes: 6 additions & 6 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ if(NOT TARGET gtest OR NOT TARGET gmock)
add_subdirectory("${PROJECT_SOURCE_DIR}/${GTEST_PATH}" "${GTEST_PATH}"
EXCLUDE_FROM_ALL)
endif()
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.cpp test_qcecexec.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)
14 changes: 0 additions & 14 deletions test/equi_circuits.json

This file was deleted.

4 changes: 2 additions & 2 deletions test/circuits.json → test/sim_circuits.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[
{
"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",
"circuit": "OPENQASM 2.0;include \"qelib1.inc\";qreg q[2];x q[0];x q[1];\n",
"expected_meas_results": {
"11": 1024
}
},
{
"description": "two_qubit_circuit_with_h_z_controlled_x_swap",
"initial_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",
"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",
"expected_meas_results": {
"10": 1024
}
Expand Down
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.

30 changes: 13 additions & 17 deletions test/test_qcecexec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
struct TestConfigurationQCEC {
// given input
std::string description;
std::string initialCircuit1;
std::string initialCircuit2;
std::string circuit1;
std::string circuit2;

// expected output
std::string expectedEquivalence;
Expand All @@ -16,8 +16,8 @@ struct TestConfigurationQCEC {
// NOLINTNEXTLINE (readability-identifier-naming)
inline void from_json(const nlohmann::json& j, TestConfigurationQCEC& test) {
test.description = j.at("description").get<std::string>();
test.initialCircuit1 = j.at("initial_circuit1").get<std::string>();
test.initialCircuit2 = j.at("initial_circuit2").get<std::string>();
test.circuit1 = j.at("circuit1").get<std::string>();
test.circuit2 = j.at("circuit2").get<std::string>();
test.expectedEquivalence = j.at("expected_equivalence").get<std::string>();
}

Expand All @@ -33,12 +33,12 @@ class QCECExecTest : public ::testing::TestWithParam<TestConfigurationQCEC> {
void SetUp() override {
test = GetParam();

std::stringstream ss1(test.initialCircuit1);
std::stringstream ss1(test.circuit1);
auto qc1 = std::make_unique<qc::QuantumComputation>();
qc1->import(ss1, qc::Format::OpenQASM);
std::cout << "Circuit 1:\n" << *qc1 << std::endl;

std::stringstream ss2(test.initialCircuit2);
std::stringstream ss2(test.circuit2);
auto qc2 = std::make_unique<qc::QuantumComputation>();
qc2->import(ss2, qc::Format::OpenQASM);
std::cout << "Circuit 2:\n" << *qc2 << std::endl;
Expand All @@ -47,32 +47,28 @@ class QCECExecTest : public ::testing::TestWithParam<TestConfigurationQCEC> {

alternatingVerificationExecutor =
std::make_unique<AlternatingVerificationExecutor>();

result = alternatingVerificationExecutor->execute(verificationTask);
std::cout << "Results:" << std::endl;
std::cout << result.dump(2U) << std::endl;
}

void TearDown() override { std::cout << "Tearing down...\n"; }

VerificationTask verificationTask;
std::unique_ptr<AlternatingVerificationExecutor>
alternatingVerificationExecutor;
TestConfigurationQCEC test;
json result;
};

INSTANTIATE_TEST_SUITE_P(
Circuits, QCECExecTest, testing::ValuesIn(getTests("equi_circuits.json")),
Circuits, QCECExecTest, testing::ValuesIn(getTests("ver_circuits.json")),
[](const testing::TestParamInfo<QCECExecTest::ParamType>& inf) {
return inf.param.description;
});

TEST_P(QCECExecTest, Equivalence) {
TEST_P(QCECExecTest, Tests) {
const auto result =
alternatingVerificationExecutor->execute(verificationTask);
std::cout << "Results:\n" << result.dump(2U) << std::endl;

ASSERT_TRUE(result.contains("check_results"));
EXPECT_EQ(result["check_results"]["equivalence"], test.expectedEquivalence);
}

TEST_P(QCECExecTest, Entries) {
EXPECT_TRUE(result.contains("construction_time"));
EXPECT_TRUE(result.contains("execution_time"));
EXPECT_TRUE(result.contains("executor"));
Expand Down
33 changes: 16 additions & 17 deletions test/test_simexec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
struct TestConfigurationDDSIM {
// given input
std::string description;
std::string initialCircuit;
std::string circuit;

// expected output
json expectedResults{};
Expand All @@ -15,54 +15,53 @@ struct TestConfigurationDDSIM {
// NOLINTNEXTLINE (readability-identifier-naming)
inline void from_json(const nlohmann::json& j, TestConfigurationDDSIM& test) {
test.description = j.at("description").get<std::string>();
test.initialCircuit = j.at("initial_circuit").get<std::string>();
test.circuit = j.at("circuit").get<std::string>();
test.expectedResults = j.at("expected_meas_results").get<json>();
}

static std::vector<TestConfigurationDDSIM> getTests(const std::string& path) {
namespace {
std::vector<TestConfigurationDDSIM> getTests(const std::string& path) {
std::ifstream input(path);
nlohmann::json j;
input >> j;
return j;
}
} // namespace

class DDSIMExecTest : public ::testing::TestWithParam<TestConfigurationDDSIM> {
protected:
void SetUp() override {
test = GetParam();
std::stringstream ss(test.circuit);

std::stringstream ss(test.initialCircuit);
auto qc = std::make_unique<qc::QuantumComputation>();
auto qc = std::make_unique<qc::QuantumComputation>();
qc->import(ss, qc::Format::OpenQASM);
std::cout << "Circuit:\n" << *qc;

simulationTask = SimulationTask(std::move(qc));
circuitSimulatorExecutor = std::make_unique<CircuitSimulatorExecutor>();

result = circuitSimulatorExecutor->execute(simulationTask);
std::cout << "Results:" << std::endl;
std::cout << result.dump(2U) << std::endl;
}

void TearDown() override { std::cout << "Tearing down...\n"; }

SimulationTask simulationTask;
std::unique_ptr<CircuitSimulatorExecutor> circuitSimulatorExecutor;
TestConfigurationDDSIM test;
json result;
};

INSTANTIATE_TEST_SUITE_P(
Circuits, DDSIMExecTest, testing::ValuesIn(getTests("circuits.json")),
Circuits, DDSIMExecTest, testing::ValuesIn(getTests("sim_circuits.json")),
[](const testing::TestParamInfo<DDSIMExecTest::ParamType>& inf) {
return inf.param.description;
});

TEST_P(DDSIMExecTest, MeasResults) {
EXPECT_EQ(result["measurement_results"], test.expectedResults);
}
TEST_P(DDSIMExecTest, Tests) {
const auto result = circuitSimulatorExecutor->execute(simulationTask);
std::cout << "Results:\n" << result.dump(2U) << std::endl;

ASSERT_TRUE(result.contains("measurement_results"));
if (!result["measurement_results"].empty()) {
EXPECT_EQ(result["measurement_results"], test.expectedResults);
}

TEST_P(DDSIMExecTest, Entries) {
EXPECT_TRUE(result.contains("construction_time"));
EXPECT_TRUE(result.contains("execution_time"));
EXPECT_TRUE(result.contains("executor"));
Expand Down
14 changes: 14 additions & 0 deletions test/ver_circuits.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"description": "simple_circuits",
"circuit1": "OPENQASM 2.0;include \"qelib1.inc\";qreg q[2];x q[0];x q[1];\n",
"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"
},
{
"description": "non_equi_circuits",
"circuit1": "OPENQASM 2.0;include \"qelib1.inc\";qreg q[2];h q[0];t q[1];cx q[0], q[1];\n",
"circuit2": "OPENQASM 2.0;include \"qelib1.inc\";qreg q[2];h q[1];cx q[0], q[1];s q[0];\n",
"expected_equivalence": "not_equivalent"
}
]