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

✨ Add SyReC synthesis with Additional Lines #65

Merged
merged 14 commits into from
Sep 5, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 1 addition & 10 deletions include/algorithms/simulation/simple_simulation.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
/**
* @file simple_simulation.hpp
*
* @brief Very simple simulation, only efficient for small circuits
*/

#ifndef SIMPLE_SIMULATION_HPP
#define SIMPLE_SIMULATION_HPP
#pragma once

#include "core/circuit.hpp"
#include "core/properties.hpp"
Expand Down Expand Up @@ -60,5 +53,3 @@ namespace syrec {
const properties::ptr& statistics = properties::ptr());

} // namespace syrec

#endif /* SIMPLE_SIMULATION_HPP */
183 changes: 88 additions & 95 deletions include/algorithms/synthesis/syrec_synthesis.hpp

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions include/algorithms/synthesis/syrec_synthesis_additional_lines.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once

#include "algorithms/synthesis/syrec_synthesis.hpp"

namespace syrec {
class SyrecSynthesisAdditionalLines: public SyrecSynthesis {
public:
using SyrecSynthesis::SyrecSynthesis;

static bool synthesize(circuit& circ, const program& program, const properties::ptr& settings = std::make_shared<properties>(), const properties::ptr& statistics = std::make_shared<properties>());

protected:
bool process_statement(const statement::ptr& statement) override {
return !SyrecSynthesis::on_statement(statement);
}

void assign_add(bool& status, std::vector<unsigned>& lhs, std::vector<unsigned>& rhs, [[maybe_unused]] const unsigned& op) override {
status = SyrecSynthesis::increase(lhs, rhs);
}

void assign_subtract(bool& status, std::vector<unsigned>& lhs, std::vector<unsigned>& rhs, [[maybe_unused]] const unsigned& op) override {
status = SyrecSynthesis::decrease(lhs, rhs);
}

void assign_exor(bool& status, std::vector<unsigned>& lhs, std::vector<unsigned>& rhs, [[maybe_unused]] const unsigned& op) override {
status = SyrecSynthesis::bitwise_cnot(lhs, rhs);
}

void exp_add(const unsigned& bitwidth, std::vector<unsigned>& lines, const std::vector<unsigned>& lhs, const std::vector<unsigned>& rhs) override;
void exp_subtract(const unsigned& bitwidth, std::vector<unsigned>& lines, const std::vector<unsigned>& lhs, const std::vector<unsigned>& rhs) override;

void exp_exor(const unsigned& bitwidth, std::vector<unsigned>& lines, const std::vector<unsigned>& lhs, const std::vector<unsigned>& rhs) override;
};
} // namespace syrec
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#pragma once

#include "algorithms/synthesis/syrec_synthesis.hpp"

namespace syrec {
class SyrecSynthesisNoAdditionalLines: public SyrecSynthesis {
public:
using SyrecSynthesis::SyrecSynthesis;

static bool synthesize(circuit& circ, const program& program, const properties::ptr& settings = std::make_shared<properties>(), const properties::ptr& statistics = std::make_shared<properties>());

protected:
bool process_statement(const statement::ptr& statement) override {
return !full_statement(statement) && !SyrecSynthesis::on_statement(statement);
}

bool full_statement(const statement::ptr& statement);
bool full_statement(const assign_statement& statement);

bool op_rhs_lhs_expression(const expression::ptr& expression, std::vector<unsigned>& v) override;

bool op_rhs_lhs_expression(const variable_expression& expression, std::vector<unsigned>& v) override;

bool op_rhs_lhs_expression(const binary_expression& expression, std::vector<unsigned>& v) override;

void pop_exp();

void inverse();

void assign_add(bool& status, std::vector<unsigned>& lhs, std::vector<unsigned>& rhs, const unsigned& op) override;

void assign_subtract(bool& status, std::vector<unsigned>& lhs, std::vector<unsigned>& rhs, const unsigned& op) override;

void assign_exor(bool& status, std::vector<unsigned>& lhs, std::vector<unsigned>& rhs, const unsigned& op) override;

bool solver(const std::vector<unsigned>& stat_lhs, unsigned stat_op, const std::vector<unsigned>& exp_lhs, unsigned exp_op, const std::vector<unsigned>& exp_rhs);

bool flow(const expression::ptr& expression, std::vector<unsigned>& v);
bool flow(const variable_expression& expression, std::vector<unsigned>& v);
bool flow(const binary_expression& expression, const std::vector<unsigned>& v);

void exp_add([[maybe_unused]] const unsigned& bitwidth, std::vector<unsigned>& lines, const std::vector<unsigned>& lhs, const std::vector<unsigned>& rhs) override {
SyrecSynthesis::increase(rhs, lhs);
lines = rhs;
}

void exp_subtract([[maybe_unused]] const unsigned& bitwidth, std::vector<unsigned>& lines, const std::vector<unsigned>& lhs, const std::vector<unsigned>& rhs) override {
decrease_new_assign(rhs, lhs);
lines = rhs;
}

void exp_exor([[maybe_unused]] const unsigned& bitwidth, std::vector<unsigned>& lines, const std::vector<unsigned>& lhs, const std::vector<unsigned>& rhs) override {
bitwise_cnot(rhs, lhs); // duplicate lhs
lines = rhs;
}

bool exp_evaluate(std::vector<unsigned>& lines, unsigned op, const std::vector<unsigned>& lhs, const std::vector<unsigned>& rhs);

bool expression_single_op(unsigned op, const std::vector<unsigned>& exp_lhs, const std::vector<unsigned>& exp_rhs);

bool decrease_new_assign(const std::vector<unsigned>& rhs, const std::vector<unsigned>& lhs);

bool expression_op_inverse(unsigned op, const std::vector<unsigned>& exp_lhs, const std::vector<unsigned>& exp_rhs) override;
};
} // namespace syrec
11 changes: 1 addition & 10 deletions include/core/circuit.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
/**
* @file circuit.hpp
*
* @brief Circuit class
*/

#ifndef CIRCUIT_HPP
#define CIRCUIT_HPP
#pragma once

#include "core/gate.hpp"

Expand Down Expand Up @@ -501,5 +494,3 @@ namespace syrec {
};

} // namespace syrec

#endif /* CIRCUIT_HPP */
11 changes: 1 addition & 10 deletions include/core/gate.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
/**
* @file gate.hpp
*
* @brief Gate class
*/

#ifndef GATE_HPP
#define GATE_HPP
#pragma once

#include <algorithm>
#include <any>
Expand Down Expand Up @@ -118,5 +111,3 @@ namespace syrec {
};

} // namespace syrec

#endif /* GATE_HPP */
11 changes: 1 addition & 10 deletions include/core/properties.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
/**
* @file properties.hpp
*
* @brief Property Map Implementation for Algorithms
*/

#ifndef PROPERTIES_HPP
#define PROPERTIES_HPP
#pragma once

#include <any>
#include <iostream>
Expand Down Expand Up @@ -148,5 +141,3 @@ namespace syrec {
}

} // namespace syrec

#endif /* PROPERTIES_HPP */
10 changes: 1 addition & 9 deletions include/core/syrec/expression.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
/**
* @file expression.hpp
*
* @brief SyReC expression data types
*/
#ifndef EXPRESSION_HPP
#define EXPRESSION_HPP
#pragma once

#include "core/syrec/variable.hpp"

Expand Down Expand Up @@ -347,5 +341,3 @@ namespace syrec {
};

} // namespace syrec

#endif /* EXPRESSION_HPP */
5 changes: 1 addition & 4 deletions include/core/syrec/grammar.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef GRAMMAR_HPP
#define GRAMMAR_HPP
#pragma once

#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/fusion/include/io.hpp>
Expand Down Expand Up @@ -315,5 +314,3 @@ namespace syrec {

class program;
} // namespace syrec

#endif /* GRAMMAR_HPP */
10 changes: 1 addition & 9 deletions include/core/syrec/module.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
/**
* @file module.hpp
*
* @brief SyReC module data type
*/
#ifndef MODULE_HPP
#define MODULE_HPP
#pragma once

#include "core/syrec/statement.hpp"
#include "core/syrec/variable.hpp"
Expand Down Expand Up @@ -89,5 +83,3 @@ namespace syrec {
};

} // namespace syrec

#endif /* MODULE_HPP */
10 changes: 1 addition & 9 deletions include/core/syrec/number.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
/**
* @file number.hpp
*
* @brief SyReC number data type
*/
#ifndef NUMBER_HPP
#define NUMBER_HPP
#pragma once

#include <cassert>
#include <map>
Expand Down Expand Up @@ -63,5 +57,3 @@ namespace syrec {
};

} // namespace syrec

#endif /* NUMBER_HPP */
10 changes: 1 addition & 9 deletions include/core/syrec/parser.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
/**
* @file parser.hpp
*
* @brief SyReC parser routines
*/
#ifndef PARSER_HPP
#define PARSER_HPP
#pragma once

#include "core/syrec/expression.hpp"
#include "core/syrec/grammar.hpp"
Expand Down Expand Up @@ -43,5 +37,3 @@ namespace syrec {

variable_access::ptr parse_variable_access(const ast_variable& ast_var, const module& proc, parser_context& context);
} // namespace syrec

#endif /* PARSER_HPP */
10 changes: 1 addition & 9 deletions include/core/syrec/program.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
/**
* @file program.hpp
*
* @brief SyReC program
*/
#ifndef PROGRAM_HPP
#define PROGRAM_HPP
#pragma once

#include "core/syrec/expression.hpp"
#include "core/syrec/grammar.hpp"
Expand Down Expand Up @@ -70,5 +64,3 @@ namespace syrec {
};

} // namespace syrec

#endif /* PROGRAM_HPP */
10 changes: 1 addition & 9 deletions include/core/syrec/statement.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
/**
* @file statement.hpp
*
* @brief SyReC statement data types
*/
#ifndef STATEMENT_HPP
#define STATEMENT_HPP
#pragma once

#include "core/syrec/expression.hpp"
#include "core/syrec/module.hpp"
Expand Down Expand Up @@ -358,5 +352,3 @@ namespace syrec {
}

} // namespace syrec

#endif /* STATEMENT_HPP */
10 changes: 1 addition & 9 deletions include/core/syrec/variable.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
/**
* @file variable.hpp
*
* @brief SyReC variable data type
*/
#ifndef VARIABLE_HPP
#define VARIABLE_HPP
#pragma once

#include "core/syrec/number.hpp"

Expand Down Expand Up @@ -124,5 +118,3 @@ namespace syrec {
};

} // namespace syrec

#endif /* VARIABLE_HPP */
11 changes: 1 addition & 10 deletions include/core/utils/timer.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
/**
* @file timer.hpp
*
* @brief A generic way for measuring time
*/

#ifndef TIMER_HPP
#define TIMER_HPP
#pragma once

#include "core/properties.hpp"

Expand Down Expand Up @@ -99,5 +92,3 @@ namespace syrec {
};

} // namespace syrec

#endif
6 changes: 4 additions & 2 deletions mqt/syrec/bindings.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "algorithms/simulation/simple_simulation.hpp"
#include "algorithms/synthesis/syrec_synthesis.hpp"
#include "algorithms/synthesis/syrec_synthesis_additional_lines.hpp"
#include "algorithms/synthesis/syrec_synthesis_no_additional_lines.hpp"
#include "core/circuit.hpp"
#include "core/gate.hpp"
#include "core/properties.hpp"
Expand Down Expand Up @@ -84,7 +85,8 @@ PYBIND11_MODULE(pysyrec, m) {
.def_readwrite("targets", &gate::targets)
.def_readwrite("type", &gate::type);

m.def("synthesis", &syrec_synthesis, "circ"_a, "program"_a, "settings"_a = properties::ptr(), "statistics"_a = properties::ptr());
m.def("syrec_synthesis_additional_lines", &SyrecSynthesisAdditionalLines::synthesize, "circ"_a, "program"_a, "settings"_a = properties::ptr(), "statistics"_a = properties::ptr());
m.def("syrec_synthesis_no_additional_lines", &SyrecSynthesisNoAdditionalLines::synthesize, "circ"_a, "program"_a, "settings"_a = properties::ptr(), "statistics"_a = properties::ptr());
m.def("simple_simulation", &simple_simulation, "output"_a, "circ"_a, "input"_a, "statistics"_a = properties::ptr());

#ifdef VERSION_INFO
Expand Down
Loading