-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
expose gate-level layout reader and writer
- Loading branch information
1 parent
2d43a91
commit 256edb0
Showing
6 changed files
with
303 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
bindings/pyfiction/include/pyfiction/io/read_fgl_layout.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// Created by simon on 09.10.22. | ||
// | ||
|
||
#ifndef PYFICTION_READ_FGL_LAYOUT_HPP | ||
#define PYFICTION_READ_FGL_LAYOUT_HPP | ||
|
||
#include "pyfiction/documentation.hpp" | ||
#include "pyfiction/types.hpp" | ||
|
||
#include <fiction/io/read_fgl_layout.hpp> | ||
#include <fiction/traits.hpp> | ||
|
||
#include <pybind11/pybind11.h> | ||
|
||
#include <string_view> | ||
|
||
namespace pyfiction | ||
{ | ||
|
||
namespace detail | ||
{ | ||
|
||
template <typename Lyt> | ||
void read_fgl_layout(pybind11::module& m) | ||
{ | ||
using namespace pybind11::literals; | ||
|
||
Lyt (*read_fgl_layout_function_pointer)(const std::string_view&, const std::string_view&) = | ||
&fiction::read_fgl_layout<Lyt>; | ||
|
||
m.def("read_fgl_layout", read_fgl_layout_function_pointer, "filename"_a, "layout_name"_a = "", DOC(fiction_read_fgl_layout_3)); | ||
} | ||
|
||
} // namespace detail | ||
|
||
inline void read_fgl_layout(pybind11::module& m) | ||
{ | ||
detail::read_fgl_layout<py_cartesian_gate_layout>(m); | ||
detail::read_fgl_layout<py_shifted_cartesian_gate_layout>(m); | ||
detail::read_fgl_layout<py_hexagonal_gate_layout>(m); | ||
} | ||
|
||
} // namespace pyfiction | ||
|
||
#endif // PYFICTION_READ_FGL_LAYOUT_HPP |
49 changes: 49 additions & 0 deletions
49
bindings/pyfiction/include/pyfiction/io/write_fgl_layout.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// Created by simon on 09.10.22. | ||
// | ||
|
||
#ifndef PYFICTION_WRITE_FGL_LAYOUT_HPP | ||
#define PYFICTION_WRITE_FGL_LAYOUT_HPP | ||
|
||
#include "pyfiction/documentation.hpp" | ||
#include "pyfiction/types.hpp" | ||
|
||
#include <fiction/io/write_fgl_layout.hpp> | ||
#include <fiction/traits.hpp> | ||
|
||
#include <pybind11/pybind11.h> | ||
|
||
#include <string_view> | ||
|
||
namespace pyfiction | ||
{ | ||
|
||
namespace detail | ||
{ | ||
|
||
template <typename Lyt> | ||
void write_fgl_layout(pybind11::module& m) | ||
{ | ||
using namespace pybind11::literals; | ||
|
||
m.def( | ||
"write_fgl_layout", | ||
[](const Lyt& lyt, const std::string_view& filename) | ||
{ | ||
fiction::write_fgl_layout<Lyt>(lyt, filename); | ||
}, | ||
"layout"_a, "filename"_a, DOC(fiction_write_fgl_layout_2)); | ||
} | ||
|
||
} // namespace detail | ||
|
||
inline void write_fgl_layout(pybind11::module& m) | ||
{ | ||
detail::write_fgl_layout<py_cartesian_gate_layout>(m); | ||
detail::write_fgl_layout<py_shifted_cartesian_gate_layout>(m); | ||
detail::write_fgl_layout<py_hexagonal_gate_layout>(m); | ||
} | ||
|
||
} // namespace pyfiction | ||
|
||
#endif // PYFICTION_WRITE_FGL_LAYOUT_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from os.path import dirname, basename, isfile, join | ||
import glob | ||
import os | ||
import sys | ||
from pathlib import Path | ||
|
||
if sys.platform == "win32" and sys.version_info > (3, 8, 0) and "Z3_ROOT" in os.environ: | ||
lib_path = Path(os.environ["Z3_ROOT"]) / "lib" | ||
if lib_path.exists(): | ||
os.add_dll_directory(str(lib_path)) | ||
bin_path = Path(os.environ["Z3_ROOT"]) / "bin" | ||
if bin_path.exists(): | ||
os.add_dll_directory(str(bin_path)) | ||
|
||
modules = glob.glob(join(dirname(__file__), "*.py")) | ||
__all__ = [basename(f)[:-3] for f in modules if isfile(f) and not f.endswith('__init__.py')] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from fiction.pyfiction import * | ||
from dotenv import load_dotenv | ||
import unittest | ||
import os | ||
|
||
dir_path = os.path.dirname(os.path.realpath(__file__)) | ||
load_dotenv() | ||
z3 = os.environ.get("z3", "OFF") | ||
|
||
|
||
class TestReadWriteFglLayout(unittest.TestCase): | ||
|
||
def test_read_write_cartesian(self): | ||
network = read_logic_network(dir_path + "/../resources/mux21.v") | ||
layout = orthogonal(network) | ||
write_fgl_layout(layout, "mux21.fgl") | ||
read_layout = read_fgl_layout("mux21.fgl") | ||
self.assertEqual(equivalence_checking(read_layout, layout), eq_type.STRONG) | ||
|
||
@unittest.skipIf(z3 == "OFF", "Z3 not enabled") | ||
def test_read_write_hexagonal(self): | ||
network = read_logic_network(dir_path + "/../resources/mux21.v") | ||
layout = exact_hexagonal(network) | ||
write_fgl_layout(layout, "mux21_hex.fgl") | ||
read_layout = read_fgl_layout("mux21_hex.fgl") | ||
self.assertEqual(equivalence_checking(read_layout, layout), eq_type.STRONG) | ||
|
||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |