Skip to content

Commit

Permalink
🐛 Fixed an inconsistency in SiDB layout printing (#396)
Browse files Browse the repository at this point in the history
* 🐛 Fixed an inconsistency in SiDB layout printing

* 🎨 Renamed `cs_color` to `lat_color` to better reflect its usage
  • Loading branch information
marcelwa committed Mar 15, 2024
1 parent d9e149e commit bcc0d95
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 27 deletions.
26 changes: 13 additions & 13 deletions include/fiction/io/print_layout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#define FICTION_PRINT_LAYOUT_HPP

#include "fiction/layouts/bounding_box.hpp"
#include "fiction/technology/charge_distribution_surface.hpp"
#include "fiction/technology/cell_technologies.hpp"
#include "fiction/technology/sidb_charge_state.hpp"
#include "fiction/technology/sidb_defects.hpp"
#include "fiction/technology/sidb_surface.hpp"
#include "fiction/traits.hpp"
#include "fiction/types.hpp"
#include "fiction/utils/layout_utils.hpp"
Expand All @@ -33,7 +33,7 @@ namespace detail
static const auto INP_COLOR = fmt::fg(fmt::color::green);
// Escape color sequence for output colors (red).
static const auto OUT_COLOR = fmt::fg(fmt::color::red);
//// Escape color sequence for latch colors (yellow on black).
// Escape color sequence for latch colors (yellow on black).
static const auto SE_COLOR = fmt::fg(fmt::color::yellow) | fmt::bg(fmt::color::black);
// Escape color sequences for clock background colors (white to dark grey).
static const std::array<fmt::text_style, 4> CLOCK_COLOR{{fmt::fg(fmt::color::black) | fmt::bg(fmt::color::white),
Expand Down Expand Up @@ -341,13 +341,13 @@ void print_cell_level_layout(std::ostream& os, const Lyt& layout, const bool io_
* `charge_distribution_surface` or `sidb_surface`.
* @param os Output stream to write into.
* @param lyt The layout of which the information is to be printed.
* @param cs_color Flag to utilize color escapes for charge states.
* @param lat_color Flag to utilize color escapes for the lattice, charge states, and atomic defects.
* @param crop_layout Flag to print the 2D bounding box of the layout, while leaving a maximum padding of one dimer row
* and two columns.
* @param draw_lattice Flag to enable lattice background drawing.
*/
template <typename Lyt>
void print_sidb_layout(std::ostream& os, const Lyt& lyt, const bool cs_color = true, const bool crop_layout = false,
void print_sidb_layout(std::ostream& os, const Lyt& lyt, const bool lat_color = true, const bool crop_layout = false,
const bool draw_lattice = true)
{
static_assert(is_cell_level_layout_v<Lyt>, "Lyt is not a cell-level layout");
Expand Down Expand Up @@ -425,19 +425,19 @@ void print_sidb_layout(std::ostream& os, const Lyt& lyt, const bool cs_color = t
{
case sidb_charge_state::NEGATIVE:
{
os << fmt::format(cs_color ? detail::SIDB_NEG_COLOR : detail::NO_COLOR, "");
os << fmt::format(lat_color ? detail::SIDB_NEG_COLOR : detail::NO_COLOR, "");
already_printed = true;
break;
}
case sidb_charge_state::POSITIVE:
{
os << fmt::format(cs_color ? detail::SIDB_POS_COLOR : detail::NO_COLOR, "");
os << fmt::format(lat_color ? detail::SIDB_POS_COLOR : detail::NO_COLOR, "");
already_printed = true;
break;
}
case sidb_charge_state::NEUTRAL:
{
os << fmt::format(cs_color ? detail::SIDB_NEUT_COLOR : detail::NO_COLOR, "");
os << fmt::format(lat_color ? detail::SIDB_NEUT_COLOR : detail::NO_COLOR, "");
already_printed = true;
break;
}
Expand All @@ -454,31 +454,31 @@ void print_sidb_layout(std::ostream& os, const Lyt& lyt, const bool cs_color = t
{
if (is_negatively_charged_defect(lyt.get_sidb_defect(loop_coordinate)))
{
os << fmt::format(cs_color ? detail::SIDB_DEF_NEG_COLOR : detail::NO_COLOR, "");
os << fmt::format(lat_color ? detail::SIDB_DEF_NEG_COLOR : detail::NO_COLOR, "");
already_printed = true;
}
else if (is_positively_charged_defect(lyt.get_sidb_defect(loop_coordinate)))
{
os << fmt::format(cs_color ? detail::SIDB_DEF_POS_COLOR : detail::NO_COLOR, "");
os << fmt::format(lat_color ? detail::SIDB_DEF_POS_COLOR : detail::NO_COLOR, "");
already_printed = true;
}
else if (is_neutrally_charged_defect(lyt.get_sidb_defect(loop_coordinate)))
{
os << fmt::format(cs_color ? detail::SIDB_DEF_NEU_COLOR : detail::NO_COLOR, "");
os << fmt::format(lat_color ? detail::SIDB_DEF_NEU_COLOR : detail::NO_COLOR, "");
already_printed = true;
}
}
}

if (!already_printed && lyt.get_cell_type(loop_coordinate) != sidb_technology::cell_type::EMPTY)
{
os << fmt::format(cs_color ? detail::SIDB_DEF_NEU_COLOR : detail::NO_COLOR, " o ");
os << fmt::format(lat_color ? detail::SIDB_DEF_NEU_COLOR : detail::NO_COLOR, " ");
already_printed = true;
}

if (!already_printed)
{
os << (draw_lattice ? fmt::format(cs_color ? detail::SIDB_LAT_COLOR : detail::NO_COLOR, " · ") : " ");
os << (draw_lattice ? fmt::format(lat_color ? detail::SIDB_LAT_COLOR : detail::NO_COLOR, " · ") : " ");
}

// if the x-coordinate of loop_coordinate is still less than the x-coordinate of the south-west cell, the
Expand Down
34 changes: 20 additions & 14 deletions test/io/print_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

#include <catch2/catch_test_macros.hpp>

#include "fiction/layouts/cell_level_layout.hpp"
#include "fiction/layouts/clocking_scheme.hpp"
#include "fiction/layouts/coordinates.hpp"
#include "fiction/technology/sidb_defects.hpp"
#include "fiction/technology/sidb_surface.hpp"
#include "fiction/utils/layout_utils.hpp"
#include "utils/blueprints/layout_blueprints.hpp"

#include <fiction/algorithms/physical_design/apply_gate_library.hpp>
Expand Down Expand Up @@ -586,16 +592,16 @@ TEST_CASE("Print Bestagon OR-gate", "[print-charge-layout]")
" · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · \n"
" · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · \n"
"\n"
" · · o · · · · · · · · · · · · · · · · · · · · · · · · · o · · \n"
" · · · · · · · · · · · · · · · · · · · · · · · · · · · · · \n"
" · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · \n"
"\n"
" · · · · o · · · · · · · · · · · · · · · · · · · · · o · · · · \n"
" · · · · · · · · · · · · · · · · · · · · · · · · · · · · · \n"
" · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · \n"
"\n"
" · · · · · · · · o · · · · · · · · · · · · · o · · · · · · · · \n"
" · · · · · · · · · · · · · · · · · · · · · · · · · · · · · \n"
" · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · \n"
"\n"
" · · · · · · · · · · o · · · · · · · · · o · · · · · · · · · · \n"
" · · · · · · · · · · · · · · · · · · · · · · · · · · · · · \n"
" · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · \n"
"\n"
" · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · \n"
Expand All @@ -604,37 +610,37 @@ TEST_CASE("Print Bestagon OR-gate", "[print-charge-layout]")
" · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · \n"
" · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · \n"
"\n"
" · · · · · · · · · · · · · o · · · · · · · · · · · · · · · · · \n"
" · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · \n"
" · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · \n"
"\n"
" · · · · · · · · · · · · · · · · · · o · · · · · · · · · · · · \n"
" · · · · · · · · · · · · · o · · · · · · · · · · · · · · · · · \n"
" · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · \n"
" · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · \n"
"\n"
" · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · \n"
" · · · · · · · · · · · · · · · o · · · · · · · · · · · · · · · \n"
" · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · \n"
"\n"
" · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · \n"
" · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · \n"
"\n"
" · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · \n"
" · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · \n"
"\n"
" · · · · · · · · · · · · · · · o · · · · · · · · · · · · · · · \n"
" · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · \n"
" · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · \n"
"\n"
" · · · · · · · · · · · · · · · · o · · · · · · · · · · · · · · \n"
" · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · \n"
" · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · \n"
"\n"
" · · · · · · · · · · · · · · · · · · · · o · · · · · · · · · · \n"
" · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · \n"
" · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · \n"
"\n"
" · · · · · · · · · · · · · · · · · · · · · · o · · · · · · · · \n"
" · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · \n"
" · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · \n"
"\n"
" · · · · · · · · · · · · · · · · · · · · · · · · · · o · · · · \n"
" · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · \n"
" · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · \n"
"\n"
" · · · · · · · · · · · · · · · · · · · · · · · · · · · · o · · \n"
" · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · \n"
" · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · \n"
"\n"
" · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · \n"
Expand Down

0 comments on commit bcc0d95

Please sign in to comment.