Skip to content

Commit

Permalink
✨ Add hexagonalization algorithm to pyfiction (#295)
Browse files Browse the repository at this point in the history
  • Loading branch information
simon1hofmann authored Sep 22, 2023
1 parent 14fdb3b commit 00dd5e7
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// Created by simon on 22.09.23.
//

#ifndef PYFICTION_HEXAGONALIZATION_HPP
#define PYFICTION_HEXAGONALIZATION_HPP

#include "pyfiction/documentation.hpp"

#include <fiction/algorithms/physical_design/hexagonalization.hpp>
#include <fiction/types.hpp>

#include <pybind11/pybind11.h>

namespace pyfiction
{

namespace detail
{

template <typename Lyt>
void hexagonalization(pybind11::module& m)
{
using namespace pybind11::literals;

m.def(
"hexagonalization",
[](const Lyt& lyt) -> py_hexagonal_gate_layout { return fiction::hexagonalization<Lyt>(lyt); }, "layout"_a,
DOC(fiction_hexagonalization));
}

} // namespace detail

inline void hexagonalization(pybind11::module& m)
{
detail::hexagonalization<py_cartesian_gate_layout>(m);
}

} // namespace pyfiction

#endif // PYFICTION_HEXAGONALIZATION_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@
#include <fiction/traits.hpp>

#include <fmt/format.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

#include <algorithm>
#include <cctype>
#include <set>
#include <string>
#include <type_traits>

#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

namespace pyfiction
{

Expand Down Expand Up @@ -78,9 +79,9 @@ void fcn_technology_cell_level_layout(pybind11::module& m)
/**
* Cell-level clocked Cartesian layout.
*/
py::class_<py_cartesian_technology_cell_layout,
fiction::synchronization_element_layout<fiction::clocked_layout<
fiction::tile_based_layout<fiction::cartesian_layout<fiction::offset::ucoord_t>>>>>(
py::class_<
py_cartesian_technology_cell_layout,
fiction::clocked_layout<fiction::tile_based_layout<fiction::cartesian_layout<fiction::offset::ucoord_t>>>>(
m, fmt::format("{}_layout", tech_name).c_str(), DOC(fiction_cell_level_layout))
.def(py::init<>())
.def(py::init<const fiction::aspect_ratio<py_cartesian_technology_cell_layout>&>(), "dimension"_a,
Expand Down
11 changes: 4 additions & 7 deletions bindings/pyfiction/include/pyfiction/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <fiction/layouts/hexagonal_layout.hpp>
#include <fiction/layouts/obstruction_layout.hpp>
#include <fiction/layouts/shifted_cartesian_layout.hpp>
#include <fiction/layouts/synchronization_element_layout.hpp>
#include <fiction/layouts/tile_based_layout.hpp>
#include <fiction/networks/technology_network.hpp>
#include <fiction/technology/cell_technologies.hpp>
Expand Down Expand Up @@ -55,18 +54,16 @@ using py_hexagonal_layout = fiction::hexagonal_layout<py_offset_coordinate, fict
/**
* Cartesian clocked layout.
*/
using py_cartesian_clocked_layout =
fiction::synchronization_element_layout<fiction::clocked_layout<fiction::tile_based_layout<py_cartesian_layout>>>;
using py_cartesian_clocked_layout = fiction::clocked_layout<fiction::tile_based_layout<py_cartesian_layout>>;
/**
* Shifted Cartesian clocked layout.
*/
using py_shifted_cartesian_clocked_layout = fiction::synchronization_element_layout<
fiction::clocked_layout<fiction::tile_based_layout<py_shifted_cartesian_layout>>>;
using py_shifted_cartesian_clocked_layout =
fiction::clocked_layout<fiction::tile_based_layout<py_shifted_cartesian_layout>>;
/**
* Hexagonal clocked layout.
*/
using py_hexagonal_clocked_layout =
fiction::synchronization_element_layout<fiction::clocked_layout<fiction::tile_based_layout<py_hexagonal_layout>>>;
using py_hexagonal_clocked_layout = fiction::clocked_layout<fiction::tile_based_layout<py_hexagonal_layout>>;
/**
* Cartesian gate layout.
*/
Expand Down
2 changes: 2 additions & 0 deletions bindings/pyfiction/pyfiction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "pyfiction/algorithms/physical_design/apply_gate_library.hpp"
#include "pyfiction/algorithms/physical_design/color_routing.hpp"
#include "pyfiction/algorithms/physical_design/exact.hpp"
#include "pyfiction/algorithms/physical_design/hexagonalization.hpp"
#include "pyfiction/algorithms/physical_design/orthogonal.hpp"
#include "pyfiction/algorithms/physical_design/post_layout_optimization.hpp"
#include "pyfiction/algorithms/properties/critical_path_length_and_throughput.hpp"
Expand Down Expand Up @@ -88,6 +89,7 @@ PYBIND11_MODULE(pyfiction, m)
pyfiction::orthogonal(m);
pyfiction::apply_gate_library(m);
pyfiction::color_routing(m);
pyfiction::hexagonalization(m);
pyfiction::post_layout_optimization(m);
/**
* Algorithms: Network Transformation
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from fiction.pyfiction import *
import unittest
import os

dir_path = os.path.dirname(os.path.realpath(__file__))


class TestHexagonalization(unittest.TestCase):

def test_hexagonalization(self):
network = read_logic_network(dir_path + "/../../resources/mux21.v")
layout = orthogonal(network)
hex_layout = hexagonalization(layout)
self.assertEqual(equivalence_checking(layout, hex_layout), eq_type.STRONG)
11 changes: 8 additions & 3 deletions docs/algorithms/hexagonalization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
Mapping Cartesian to Hexagonal Layouts
--------------------------------------

**Header:** ``fiction/algorithms/physical_design/hexagonalization.hpp``

This algorithm maps Cartesian 2DDWave-clocked layouts used for Quantum-dot Cellular Automata (QCA) to hexagonal row-clocked layouts,
which are suitable for Silicon Dangling Bonds (SiDBs).

Expand All @@ -21,4 +19,11 @@ The respective coordinates on the hexagonal grid are calculated as follows:
.. figure:: /_static/hexagonalization.svg
:width: 600

.. doxygenfunction:: fiction::hexagonalization
.. tabs::
.. tab:: C++
**Header:** ``fiction/algorithms/physical_design/hexagonalization.hpp``

.. doxygenfunction:: fiction::hexagonalization

.. tab:: Python
.. autofunction:: fiction.pyfiction.hexagonalization

0 comments on commit 00dd5e7

Please sign in to comment.