Skip to content

Commit

Permalink
Merge pull request #473 from sfc-aqua/graph-state-backend
Browse files Browse the repository at this point in the history
introduce graph state backend into quisp
  • Loading branch information
Naphann authored Jan 24, 2023
2 parents d66ab32 + 39eecde commit 79d417f
Show file tree
Hide file tree
Showing 39 changed files with 2,745 additions and 1,035 deletions.
7 changes: 5 additions & 2 deletions quisp/backends/Backends.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include "ErrorTracking/Backend.h"
#include "ErrorTracking/Configuration.h"
#include "GraphState/Backend.h"
#include "backends/QubitConfiguration.h"
#include "interfaces/IConfiguration.h"
#include "interfaces/IQuantumBackend.h"
#include "interfaces/IQubit.h"
Expand All @@ -18,8 +19,10 @@ using abstract::MeasurementOutcome;
using abstract::MeasureXResult;
using abstract::MeasureYResult;
using abstract::MeasureZResult;
// using backends::StationaryQubitConfiguration;
using error_tracking::ErrorTrackingBackend;
using error_tracking::ErrorTrackingConfiguration;
using error_tracking::ErrorTrackingQubit;
using graph_state::GraphStateBackend;
using graph_state::GraphStateQubit;

} // namespace quisp::backends
12 changes: 6 additions & 6 deletions quisp/backends/ErrorTracking/Backend.cc
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#include "Backend.h"
#include "Qubit.h"
#include "backends/ErrorTracking/Configuration.h"
#include "backends/QubitConfiguration.h"
#include "backends/interfaces/IConfiguration.h"

namespace quisp::backends::error_tracking {
using error_tracking::ErrorTrackingQubit;

ErrorTrackingBackend::ErrorTrackingBackend(std::unique_ptr<IRandomNumberGenerator> rng, std::unique_ptr<ErrorTrackingConfiguration> configuration)
ErrorTrackingBackend::ErrorTrackingBackend(std::unique_ptr<IRandomNumberGenerator> rng, std::unique_ptr<StationaryQubitConfiguration> configuration)
: current_time(SimTime()), rng(std::move(rng)) {
config = std::move(configuration);
}
ErrorTrackingBackend::ErrorTrackingBackend(std::unique_ptr<IRandomNumberGenerator> rng, std::unique_ptr<ErrorTrackingConfiguration> configuration, ICallback* cb)
ErrorTrackingBackend::ErrorTrackingBackend(std::unique_ptr<IRandomNumberGenerator> rng, std::unique_ptr<StationaryQubitConfiguration> configuration, ICallback* cb)
: ErrorTrackingBackend(std::move(rng), std::move(configuration)) {
callback = cb;
}
Expand All @@ -37,14 +37,14 @@ IQubit* ErrorTrackingBackend::createQubit(const IQubitId* id, std::unique_ptr<IC
auto original_qubit = std::make_unique<ErrorTrackingQubit>(id, this);

IConfiguration* raw_conf = conf.release();
ErrorTrackingConfiguration* et_conf = dynamic_cast<ErrorTrackingConfiguration*>(raw_conf);
StationaryQubitConfiguration* et_conf = dynamic_cast<StationaryQubitConfiguration*>(raw_conf);

if (et_conf == nullptr) {
delete raw_conf;
throw std::runtime_error("ErrorTrackingBackend::getQubit: failed to cast. got invalid configulation.");
}

original_qubit->configure(std::unique_ptr<ErrorTrackingConfiguration>(et_conf));
original_qubit->configure(std::unique_ptr<StationaryQubitConfiguration>(et_conf));
auto* qubit_ptr = original_qubit.get();
qubits.insert({id, std::move(original_qubit)});
return qubit_ptr;
Expand All @@ -62,7 +62,7 @@ void ErrorTrackingBackend::deleteQubit(const IQubitId* id) {

std::unique_ptr<IConfiguration> ErrorTrackingBackend::getDefaultConfiguration() const {
// copy the default backend configuration for each qubit
return std::make_unique<ErrorTrackingConfiguration>(*config.get());
return std::make_unique<StationaryQubitConfiguration>(*config.get());
}
const SimTime& ErrorTrackingBackend::getSimTime() {
if (callback != nullptr) callback->willUpdate(*this);
Expand Down
8 changes: 4 additions & 4 deletions quisp/backends/ErrorTracking/Backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#include "../interfaces/IQuantumBackend.h"
#include "../interfaces/IQubitId.h"
#include "../interfaces/IRandomNumberGenerator.h"
#include "Configuration.h"
#include "Qubit.h"
#include "backends/QubitConfiguration.h"

namespace quisp::backends::error_tracking {
using abstract::IConfiguration;
Expand All @@ -26,8 +26,8 @@ class ErrorTrackingBackend : public IQuantumBackend {
virtual ~ICallback() {}
virtual void willUpdate(ErrorTrackingBackend& backend) = 0;
};
ErrorTrackingBackend(std::unique_ptr<IRandomNumberGenerator> rng, std::unique_ptr<ErrorTrackingConfiguration> configuration);
ErrorTrackingBackend(std::unique_ptr<IRandomNumberGenerator> rng, std::unique_ptr<ErrorTrackingConfiguration> configuration, ICallback* callback);
ErrorTrackingBackend(std::unique_ptr<IRandomNumberGenerator> rng, std::unique_ptr<StationaryQubitConfiguration> configuration);
ErrorTrackingBackend(std::unique_ptr<IRandomNumberGenerator> rng, std::unique_ptr<StationaryQubitConfiguration> configuration, ICallback* callback);
~ErrorTrackingBackend();
IQubit* createQubit(const IQubitId* id, std::unique_ptr<IConfiguration> conf) override;
IQubit* createQubit(const IQubitId* id) override;
Expand All @@ -42,7 +42,7 @@ class ErrorTrackingBackend : public IQuantumBackend {
std::unordered_map<const IQubitId*, std::unique_ptr<ErrorTrackingQubit>, IQubitId::Hash, IQubitId::Pred> qubits;
SimTime current_time;
const std::unique_ptr<IRandomNumberGenerator> rng;
std::unique_ptr<ErrorTrackingConfiguration> config;
std::unique_ptr<StationaryQubitConfiguration> config;
ICallback* callback = nullptr;
};

Expand Down
12 changes: 6 additions & 6 deletions quisp/backends/ErrorTracking/Backend_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
#include <gtest/gtest.h>
#include <omnetpp.h>
#include "../interfaces/IRandomNumberGenerator.h"
#include "Configuration.h"
#include "Qubit.h"
#include "backends/QubitConfiguration.h"
#include "backends/interfaces/IConfiguration.h"
#include "test.h"

namespace {
using namespace quisp::backends::error_tracking;
using namespace quisp_test::backends;
using namespace quisp_test::backends::error_tracking;
using namespace omnetpp;

class TestEtQubit : public ErrorTrackingQubit {
Expand Down Expand Up @@ -46,15 +46,15 @@ class TestEtQubit : public ErrorTrackingQubit {
class EtBackend : public ErrorTrackingBackend {
public:
using ErrorTrackingBackend::qubits;
EtBackend(std::unique_ptr<IRandomNumberGenerator> rng, std::unique_ptr<ErrorTrackingConfiguration> config) : ErrorTrackingBackend(std::move(rng), std::move(config)) {}
EtBackend(std::unique_ptr<IRandomNumberGenerator> rng, std::unique_ptr<StationaryQubitConfiguration> config) : ErrorTrackingBackend(std::move(rng), std::move(config)) {}
};

class EtBackendTest : public ::testing::Test {
protected:
virtual void SetUp() {
SimTime::setScaleExp(-9);
rng = new TestRNG();
backend = std::make_unique<EtBackend>(std::unique_ptr<IRandomNumberGenerator>(rng), std::make_unique<ErrorTrackingConfiguration>());
backend = std::make_unique<EtBackend>(std::unique_ptr<IRandomNumberGenerator>(rng), std::make_unique<StationaryQubitConfiguration>());
}
TestRNG* rng;
std::unique_ptr<EtBackend> backend;
Expand Down Expand Up @@ -100,7 +100,7 @@ TEST_F(EtBackendTest, createQubitWithInvalidConfiguration) {
}

TEST_F(EtBackendTest, createQubitWithConfiguration) {
auto conf = new ErrorTrackingConfiguration;
auto conf = new StationaryQubitConfiguration;
conf->cnot_gate_err_rate = 0.75;
conf->cnot_gate_ix_err_ratio = 0.75 / 9.;
conf->cnot_gate_xi_err_ratio = 0.75 / 9.;
Expand Down Expand Up @@ -133,7 +133,7 @@ TEST_F(EtBackendTest, createQubitWithConfiguration) {
conf->memory_excitation_rate = 0.30;
conf->memory_completely_mixed_rate = 0.31;

auto conf2 = std::make_unique<ErrorTrackingConfiguration>(*conf);
auto conf2 = std::make_unique<StationaryQubitConfiguration>(*conf);

auto* id = new QubitId(123);
EXPECT_EQ(backend->qubits.size(), 0);
Expand Down
53 changes: 0 additions & 53 deletions quisp/backends/ErrorTracking/Configuration.h

This file was deleted.

2 changes: 1 addition & 1 deletion quisp/backends/ErrorTracking/Qubit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ErrorTrackingQubit::ErrorTrackingQubit(const IQubitId* id, ErrorTrackingBackend*

ErrorTrackingQubit::~ErrorTrackingQubit() {}

void ErrorTrackingQubit::configure(std::unique_ptr<ErrorTrackingConfiguration> c) {
void ErrorTrackingQubit::configure(std::unique_ptr<StationaryQubitConfiguration> c) {
setMemoryErrorRates(c->memory_x_err_rate, c->memory_y_err_rate, c->memory_z_err_rate, c->memory_excitation_rate, c->memory_relaxation_rate, c->memory_completely_mixed_rate);
measurement_err.setParams(c->measurement_x_err_rate, c->measurement_y_err_rate, c->measurement_z_err_rate);
gate_err_h.setParams(c->h_gate_x_err_ratio, c->h_gate_y_err_ratio, c->h_gate_z_err_ratio, c->h_gate_err_rate);
Expand Down
4 changes: 2 additions & 2 deletions quisp/backends/ErrorTracking/Qubit.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <unsupported/Eigen/MatrixFunctions>
#include "../interfaces/IQuantumBackend.h"
#include "../interfaces/IQubit.h"
#include "backends/ErrorTracking/Configuration.h"
#include "backends/QubitConfiguration.h"
#include "omnetpp/simtime.h"
#include "types.h"

Expand Down Expand Up @@ -39,7 +39,7 @@ class ErrorTrackingQubit : public IQubit {
~ErrorTrackingQubit();
void setMemoryErrorRates(double x_error_rate, double y_error_rate, double z_error_rate, double excitation_rate, double relaxation_rate, double completely_mixed_rate);
void reset();
void configure(std::unique_ptr<ErrorTrackingConfiguration> configuration);
void configure(std::unique_ptr<StationaryQubitConfiguration> configuration);
const IQubitId* const getId() const override;
void setFree() override;
MeasureXResult correlationMeasureX() override;
Expand Down
5 changes: 3 additions & 2 deletions quisp/backends/ErrorTracking/Qubit_gate_error_test.cc
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include <gtest/gtest.h>
#include <test_utils/TestUtils.h>
#include <unsupported/Eigen/MatrixFunctions>
#include "backends/QubitConfiguration.h"
#include "test.h"

namespace {

using namespace quisp_test::backends;
using namespace quisp_test::backends::error_tracking;

class EtQubitGateErrorTest : public ::testing::Test {
protected:
Expand All @@ -14,7 +15,7 @@ class EtQubitGateErrorTest : public ::testing::Test {
SimTime::setScaleExp(-9);
rng = new TestRNG();
rng->double_value = .0;
backend = std::make_unique<Backend>(std::unique_ptr<IRandomNumberGenerator>(rng), std::make_unique<ErrorTrackingConfiguration>());
backend = std::make_unique<Backend>(std::unique_ptr<IRandomNumberGenerator>(rng), std::make_unique<StationaryQubitConfiguration>());
qubit = dynamic_cast<Qubit*>(backend->createQubit(0));
if (qubit == nullptr) throw std::runtime_error("Qubit is nullptr");
qubit2 = dynamic_cast<Qubit*>(backend->createQubit(1));
Expand Down
5 changes: 3 additions & 2 deletions quisp/backends/ErrorTracking/Qubit_measurement_test.cc
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#include <gtest/gtest.h>
#include <test_utils/TestUtils.h>
#include <unsupported/Eigen/MatrixFunctions>
#include "backends/QubitConfiguration.h"
#include "test.h"

namespace {
using namespace quisp_test::backends;
using namespace quisp_test::backends::error_tracking;

class EtQubitMeasurementTest : public ::testing::Test {
protected:
Expand All @@ -14,7 +15,7 @@ class EtQubitMeasurementTest : public ::testing::Test {
rng = new TestRNG();
rng->double_value = .0;

backend = std::make_unique<Backend>(std::unique_ptr<IRandomNumberGenerator>(rng), std::make_unique<ErrorTrackingConfiguration>());
backend = std::make_unique<Backend>(std::unique_ptr<IRandomNumberGenerator>(rng), std::make_unique<StationaryQubitConfiguration>());
qubit = dynamic_cast<Qubit*>(backend->createQubit(0));
another_qubit = dynamic_cast<Qubit*>(backend->createQubit(2));

Expand Down
5 changes: 3 additions & 2 deletions quisp/backends/ErrorTracking/Qubit_memory_error_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
#include <Eigen/Eigen>
#include <unsupported/Eigen/MatrixFunctions>
#include "backends/ErrorTracking/types.h"
#include "backends/QubitConfiguration.h"
#include "test.h"

namespace {
using namespace quisp_test::backends;
using namespace quisp_test::backends::error_tracking;
using Eigen::Matrix2cd;
using Eigen::Matrix4cd;
using Eigen::Vector4cd;
Expand All @@ -20,7 +21,7 @@ class ETQubitMemoryErrorTest : public ::testing::Test {
SimTime::setScaleExp(-9);
rng = new TestRNG();
rng->double_value = .0;
backend = std::make_unique<Backend>(std::unique_ptr<IRandomNumberGenerator>(rng), std::make_unique<ErrorTrackingConfiguration>());
backend = std::make_unique<Backend>(std::unique_ptr<IRandomNumberGenerator>(rng), std::make_unique<StationaryQubitConfiguration>());
qubit = dynamic_cast<Qubit*>(backend->createQubit(0));
partner_qubit = dynamic_cast<Qubit*>(backend->createQubit(1));
if (qubit == nullptr) throw std::runtime_error("Qubit is nullptr");
Expand Down
5 changes: 3 additions & 2 deletions quisp/backends/ErrorTracking/Qubit_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
#include <Eigen/Eigen>
#include <unsupported/Eigen/MatrixFunctions>
#include "backends/ErrorTracking/types.h"
#include "backends/QubitConfiguration.h"
#include "test.h"

namespace {
using namespace quisp_test::backends;
using namespace quisp_test::backends::error_tracking;
using Eigen::Matrix2cd;
using Eigen::Matrix4cd;
using Eigen::Vector4cd;
Expand All @@ -20,7 +21,7 @@ class EtQubitTest : public ::testing::Test {
SimTime::setScaleExp(-9);
rng = new TestRNG();
rng->double_value = .0;
backend = std::make_unique<Backend>(std::unique_ptr<IRandomNumberGenerator>(rng), std::make_unique<ErrorTrackingConfiguration>());
backend = std::make_unique<Backend>(std::unique_ptr<IRandomNumberGenerator>(rng), std::make_unique<StationaryQubitConfiguration>());
qubit = dynamic_cast<Qubit*>(backend->createQubit(0));
partner_qubit = dynamic_cast<Qubit*>(backend->createQubit(1));
if (qubit == nullptr) throw std::runtime_error("Qubit is nullptr");
Expand Down
10 changes: 5 additions & 5 deletions quisp/backends/ErrorTracking/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
#include "../interfaces/IQubitId.h"
#include "../interfaces/IRandomNumberGenerator.h"
#include "Backend.h"
#include "Configuration.h"
#include "Qubit.h"
#include "backends/QubitConfiguration.h"

namespace quisp_test::backends {
namespace quisp_test::backends::error_tracking {
using omnetpp::SimTime;
using ::quisp::backends::StationaryQubitConfiguration;
using ::quisp::backends::abstract::IQubit;
using ::quisp::backends::abstract::IQubitId;
using ::quisp::backends::error_tracking::ErrorTrackingBackend;
using ::quisp::backends::error_tracking::ErrorTrackingConfiguration;
using ::quisp::backends::error_tracking::ErrorTrackingQubit;
using namespace ::quisp::backends;
using namespace ::quisp::backends::abstract;
Expand Down Expand Up @@ -80,7 +80,7 @@ class Qubit : public ErrorTrackingQubit {
class Backend : public ErrorTrackingBackend {
public:
using ErrorTrackingBackend::qubits;
Backend(std::unique_ptr<IRandomNumberGenerator> rng, std::unique_ptr<ErrorTrackingConfiguration> config) : ErrorTrackingBackend(std::move(rng), std::move(config)) {}
Backend(std::unique_ptr<IRandomNumberGenerator> rng, std::unique_ptr<StationaryQubitConfiguration> config) : ErrorTrackingBackend(std::move(rng), std::move(config)) {}
IQubit* createQubit(int id) { return this->createQubitInternal(new QubitId(id)); }
IQubit* getQubit(int id) { return this->getQubitInternal(new QubitId(id)); }
IQubit* getQubitInternal(const IQubitId* id) { return qubits.find(id)->second.get(); }
Expand All @@ -96,4 +96,4 @@ class Backend : public ErrorTrackingBackend {
}
};

} // namespace quisp_test::backends
} // namespace quisp_test::backends::error_tracking
Loading

0 comments on commit 79d417f

Please sign in to comment.