Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decoding the irreversible function. #120

Merged
merged 7 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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 include/algorithms/simulation/circuit_to_truthtable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

namespace syrec {

auto buildTruthTable(const qc::QuantumComputation& qc, TruthTable& tt) -> void;
auto buildTruthTable(const qc::QuantumComputation* qc, TruthTable& tt) -> void;
burgholzer marked this conversation as resolved.
Show resolved Hide resolved

} // namespace syrec
36 changes: 25 additions & 11 deletions include/algorithms/synthesis/dd_synthesis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "QuantumComputation.hpp"
#include "algorithms/optimization/esop_minimization.hpp"
#include "algorithms/synthesis/encoding.hpp"
#include "core/truthTable/truth_table.hpp"

#include <chrono>
Expand All @@ -14,10 +15,15 @@ namespace syrec {
public:
DDSynthesizer() = default;

explicit DDSynthesizer(const std::size_t nqubits):
qc(nqubits) {}
explicit DDSynthesizer(TruthTable const& tt):
m(tt.nOutputs()), totalNoBits(tt.nOutputs()) {}

auto synthesize(dd::mEdge src, std::unique_ptr<dd::Package<>>& dd) -> qc::QuantumComputation&;
auto synthesize(TruthTable const& tt) -> std::shared_ptr<qc::QuantumComputation>;
burgholzer marked this conversation as resolved.
Show resolved Hide resolved
auto synthesize(dd::mEdge src, std::unique_ptr<dd::Package<>>& dd, const std::shared_ptr<qc::QuantumComputation>& qc) -> void;
burgholzer marked this conversation as resolved.
Show resolved Hide resolved

[[nodiscard]] auto getNbits() const -> std::size_t {
return totalNoBits;
}

[[nodiscard]] auto numGate() const -> std::size_t {
return numGates;
Expand All @@ -28,9 +34,15 @@ namespace syrec {
}

private:
double runtime = 0.;
std::size_t numGates = 0U;
qc::QuantumComputation qc;
double runtime = 0.;
std::size_t numGates = 0U;

// m -> No. of primary outputs.
// totalNoBits -> Total no. of bits required to create the circuit

std::size_t m = 0U;
std::size_t totalNoBits = 0U;
bool garbageFlag = false;

auto pathFromSrcDst(dd::mEdge const& src, dd::mNode* const& dst, TruthTable::Cube::Set& sigVec) const -> void;
auto pathFromSrcDst(dd::mEdge const& src, dd::mNode* const& dst, TruthTable::Cube::Set& sigVec, TruthTable::Cube& cube) const -> void;
Expand All @@ -42,20 +54,22 @@ namespace syrec {

static auto completeUniCubes(TruthTable::Cube::Set const& p1SigVec, TruthTable::Cube::Set const& p2SigVec, TruthTable::Cube::Set& uniqueCubeVec) -> void;

auto applyOperation(dd::QubitCount const& totalBits, dd::Qubit const& targetBit, dd::mEdge& to, dd::Controls const& ctrl, std::unique_ptr<dd::Package<>>& dd) -> void;
auto applyOperation(dd::QubitCount const& totalBits, dd::Qubit const& targetBit, dd::mEdge& to, dd::Controls const& ctrl, std::unique_ptr<dd::Package<>>& dd, const std::shared_ptr<qc::QuantumComputation>& qc) -> void;

static auto controlRoot(dd::mEdge const& current, dd::Controls& ctrl, TruthTable::Cube const& ctrlCube) -> void;
static auto controlNonRoot(dd::mEdge const& current, dd::Controls& ctrl, TruthTable::Cube const& ctrlCube) -> void;

static auto dcNodeCondition(dd::mEdge const& current) -> bool;

auto swapPaths(dd::mEdge src, dd::mEdge const& current, TruthTable::Cube::Set const& p1SigVec, TruthTable::Cube::Set const& p2SigVec, TruthTable::Cube::Set const& p3SigVec, TruthTable::Cube::Set const& p4SigVec, std::unique_ptr<dd::Package<>>& dd) -> dd::mEdge;
auto swapPaths(dd::mEdge src, dd::mEdge const& current, TruthTable::Cube::Set const& p1SigVec, TruthTable::Cube::Set const& p2SigVec, TruthTable::Cube::Set const& p3SigVec, TruthTable::Cube::Set const& p4SigVec, std::unique_ptr<dd::Package<>>& dd, const std::shared_ptr<qc::QuantumComputation>& qc) -> dd::mEdge;

auto shiftUniquePaths(dd::mEdge src, dd::mEdge const& current, TruthTable::Cube::Set const& p1SigVec, TruthTable::Cube::Set const& p2SigVec, TruthTable::Cube::Set const& p3SigVec, TruthTable::Cube::Set const& p4SigVec, bool& changePaths, std::unique_ptr<dd::Package<>>& dd) -> dd::mEdge;
auto shiftUniquePaths(dd::mEdge src, dd::mEdge const& current, TruthTable::Cube::Set const& p1SigVec, TruthTable::Cube::Set const& p2SigVec, TruthTable::Cube::Set const& p3SigVec, TruthTable::Cube::Set const& p4SigVec, bool& changePaths, std::unique_ptr<dd::Package<>>& dd, const std::shared_ptr<qc::QuantumComputation>& qc) -> dd::mEdge;
static auto terminate(dd::mEdge const& current, TruthTable::Cube::Set const& p1SigVec, TruthTable::Cube::Set const& p2SigVec, TruthTable::Cube::Set const& p3SigVec, TruthTable::Cube::Set const& p4SigVec) -> bool;

auto unifyPath(dd::mEdge src, dd::mEdge const& current, TruthTable::Cube::Set const& p1SigVec, TruthTable::Cube::Set const& p2SigVec, bool const& changePaths, std::unique_ptr<dd::Package<>>& dd) -> dd::mEdge;
auto shiftingPaths(dd::mEdge const& src, dd::mEdge const& current, std::unique_ptr<dd::Package<>>& dd) -> dd::mEdge;
auto unifyPath(dd::mEdge src, dd::mEdge const& current, TruthTable::Cube::Set const& p1SigVec, TruthTable::Cube::Set const& p2SigVec, bool const& changePaths, std::unique_ptr<dd::Package<>>& dd, const std::shared_ptr<qc::QuantumComputation>& qc) -> dd::mEdge;
auto shiftingPaths(dd::mEdge const& src, dd::mEdge const& current, std::unique_ptr<dd::Package<>>& dd, const std::shared_ptr<qc::QuantumComputation>& qc) -> dd::mEdge;

auto decoder(TruthTable::CubeMap const& codewords, std::size_t const& r, std::unique_ptr<dd::Package<>>& dd, const std::shared_ptr<qc::QuantumComputation>& qc) -> void;
};

} // namespace syrec
6 changes: 4 additions & 2 deletions include/algorithms/synthesis/encoding.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ namespace syrec {

auto extend(TruthTable& tt) -> void;

auto encodeHuffman(TruthTable& tt) -> void;
auto completeTruthTable(TruthTable& tt, std::size_t const& totalNoBits) -> void;

auto augmentWithConstants(TruthTable& tt) -> void;
auto encodeHuffman(TruthTable& tt) -> std::pair<TruthTable::CubeMap, std::size_t>;

auto augmentWithConstants(TruthTable& tt, std::size_t const& nBits) -> void;

} //namespace syrec
5 changes: 3 additions & 2 deletions include/core/truthTable/truth_table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,9 @@ namespace syrec {
CubeMap cubeMap{};

public:
TruthTable() = default;
TruthTable(TruthTable& tt) = default;
TruthTable() = default;
TruthTable(TruthTable& tt) = default;
TruthTable(TruthTable const& tt) = default;
burgholzer marked this conversation as resolved.
Show resolved Hide resolved

auto operator==(const TruthTable& tt) const -> bool {
return (cubeMap == tt.cubeMap);
Expand Down
6 changes: 3 additions & 3 deletions src/algorithms/simulation/circuit_to_truthtable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace syrec {

auto buildTruthTable(const qc::QuantumComputation& qc, TruthTable& tt) -> void {
const auto nBits = qc.getNqubits();
auto buildTruthTable(const qc::QuantumComputation* qc, TruthTable& tt) -> void {
const auto nBits = qc->getNqubits();
assert(nBits < 65U);

auto dd = std::make_unique<dd::Package<>>(nBits);
Expand All @@ -18,7 +18,7 @@ namespace syrec {
const auto inCube = TruthTable::Cube::fromInteger(n, nBits);

auto const inEdge = dd->makeBasisState(nBits, inCube.toBoolVec());
const auto out = dd::simulate(&qc, inEdge, dd, 1);
const auto out = dd::simulate(qc, inEdge, dd, 1);
const auto outString = out.begin()->first;

tt.try_emplace(inCube, TruthTable::Cube::fromString(outString));
Expand Down
Loading