Skip to content

Commit

Permalink
✨ Add option to hide lattice points in the SiDB layout SVG writer (#590)
Browse files Browse the repository at this point in the history
* 📝 Update pyfiction docstrings

Signed-off-by: GitHub Actions <actions@github.com>

* 🎨 Incorporated pre-commit fixes

* 🎨 small fix.

* 🐍 small fix.

* 🎨 small fix.

* 🎨 small fix.

* 🎨 small fix.

* 📝 Update pyfiction docstrings

Signed-off-by: GitHub Actions <actions@github.com>

* 🐍 small fix.

---------

Signed-off-by: GitHub Actions <actions@github.com>
Co-authored-by: GitHub Actions <actions@github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 22, 2024
1 parent 21d9c06 commit c8da54f
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ void write_svg_layout(pybind11::module& m)
.value("DARK", fiction::write_sidb_layout_svg_params::color_mode::DARK,
DOC(fiction_write_sidb_layout_svg_params_color_mode_DARK));

py::enum_<fiction::write_sidb_layout_svg_params::sidb_lattice_mode>(
m, "sidb_lattice_mode", DOC(fiction_write_sidb_layout_svg_params_sidb_lattice_mode))
.value("SHOW_LATTICE", fiction::write_sidb_layout_svg_params::sidb_lattice_mode::SHOW_LATTICE,
DOC(fiction_write_sidb_layout_svg_params_sidb_lattice_mode_SHOW_LATTICE))
.value("HIDE_LATTICE", fiction::write_sidb_layout_svg_params::sidb_lattice_mode::HIDE_LATTICE,
DOC(fiction_write_sidb_layout_svg_params_sidb_lattice_mode_HIDE_LATTICE));

py::class_<fiction::write_sidb_layout_svg_params>(m, "write_sidb_layout_svg_params",
DOC(fiction_write_sidb_layout_svg_params))
.def(py::init<>())
Expand Down
10 changes: 10 additions & 0 deletions bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18841,10 +18841,20 @@ static const char *__doc_fiction_write_sidb_layout_svg_params_color_mode_DARK =

static const char *__doc_fiction_write_sidb_layout_svg_params_color_mode_LIGHT = R"doc(Light mode.)doc";

static const char *__doc_fiction_write_sidb_layout_svg_params_lattice_mode = R"doc(The lattice mode of the SiDB layout.)doc";

static const char *__doc_fiction_write_sidb_layout_svg_params_lattice_point_size = R"doc(Size of the H-Si lattice points in SVG units.)doc";

static const char *__doc_fiction_write_sidb_layout_svg_params_sidb_border_width = R"doc(Border width of the SiDB.)doc";

static const char *__doc_fiction_write_sidb_layout_svg_params_sidb_lattice_mode =
R"doc(Enumeration to specify if the H-Si lattice is plotted in addition to
SiDBs.)doc";

static const char *__doc_fiction_write_sidb_layout_svg_params_sidb_lattice_mode_HIDE_LATTICE = R"doc(Lattice is hidden. Only SiDBs are shown.)doc";

static const char *__doc_fiction_write_sidb_layout_svg_params_sidb_lattice_mode_SHOW_LATTICE = R"doc(Lattice is shown.)doc";

static const char *__doc_fiction_write_sidb_layout_svg_params_sidb_size = R"doc(Size of the SiDB in SVG units.)doc";

static const char *__doc_fiction_write_sqd_layout =
Expand Down
57 changes: 39 additions & 18 deletions include/fiction/io/write_svg_layout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ struct write_sidb_layout_svg_params
*/
LIGHT
};
/**
* Enumeration to specify if the H-Si lattice is plotted in addition to SiDBs.
*/
enum class sidb_lattice_mode : uint8_t
{
/**
* Lattice is hidden. Only SiDBs are shown.
*/
HIDE_LATTICE,
/**
* Lattice is shown.
*/
SHOW_LATTICE
};
/**
* Size of the H-Si lattice points in SVG units.
*/
Expand All @@ -78,6 +92,10 @@ struct write_sidb_layout_svg_params
* The color mode of the background for the SVG output.
*/
color_mode color_background = color_mode::DARK;
/**
* The lattice mode of the SiDB layout.
*/
sidb_lattice_mode lattice_mode = sidb_lattice_mode::SHOW_LATTICE;
};

template <typename Coordinate>
Expand Down Expand Up @@ -582,29 +600,32 @@ class write_sidb_layout_svg_impl
const auto min_coord = bb.get_min();
const auto max_coord = bb.get_max();

// Generate all lattice points
const auto all_coords = all_coordinates_in_spanned_area(min_coord, max_coord);

for (const auto& coord : all_coords)
if (ps.lattice_mode == write_sidb_layout_svg_params::sidb_lattice_mode::SHOW_LATTICE)
{
// Shift coordinates for alignment
auto shifted_coord = coord;

shifted_coord.x += 1;
// Generate all lattice points
const auto all_coords = all_coordinates_in_spanned_area(min_coord, max_coord);

if constexpr (has_siqad_coord_v<Lyt>)
{
shifted_coord.y += 1;
}
else
for (const auto& coord : all_coords)
{
shifted_coord.y += 2;
}
// Shift coordinates for alignment
auto shifted_coord = coord;

shifted_coord.x += 1;

const auto nm_pos = sidb_nm_position(lyt, shifted_coord);
if constexpr (has_siqad_coord_v<Lyt>)
{
shifted_coord.y += 1;
}
else
{
shifted_coord.y += 2;
}

const auto nm_pos = sidb_nm_position(lyt, shifted_coord);

svg_content << generate_lattice_point(nm_pos.first * 10, nm_pos.second * 10,
fiction::detail::svg::SI_LATTICE);
svg_content << generate_lattice_point(nm_pos.first * 10, nm_pos.second * 10,
fiction::detail::svg::SI_LATTICE);
}
}

std::vector<cell<Lyt>> all_cells{};
Expand Down
61 changes: 61 additions & 0 deletions test/io/write_svg_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,47 @@ inline const std::string EXPECTED_SVG_DARK_CELL_LEVEL =
</svg>)",
FICTION_VERSION, FICTION_REPO);

inline const std::string EXPECTED_SVG_DARK_CELL_LEVEL_HIDE_LATTICE =
fmt::format(R"(<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Generated by {} ({}) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 19.2 23.04"
version="1.1">
<metadata>
<rdf:RDF>
<cc:Work rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs>
<!-- lattice point -->
<circle id="lattice_point" cx="0" cy="0" r="0.3"/>
<!-- SiDB -->
<circle id="sidb_color" cx="0" cy="0" r="0.9"/>
</defs>
<!-- PATH_DEFINITION placeholder -->
<rect x="0" y="0" width="19.2" height="23.04" style="fill:#25323D;"/> <!-- Background rectangle placeholder -->
<g>
<use xlink:href="#sidb_color" x="3.84" y="7.68" style="fill:#C8C8C8; fill-opacity:1; stroke:#ffffff; stroke-width:0.3;"/>
<use xlink:href="#sidb_color" x="7.68" y="7.68" style="fill:#C8C8C8; fill-opacity:1; stroke:#ffffff; stroke-width:0.3;"/>
<use xlink:href="#sidb_color" x="7.68" y="9.93" style="fill:#C8C8C8; fill-opacity:1; stroke:#ffffff; stroke-width:0.3;"/>
<use xlink:href="#sidb_color" x="15.36" y="17.61" style="fill:#C8C8C8; fill-opacity:1; stroke:#ffffff; stroke-width:0.3;"/>
<!-- SVG content placeholder -->
</g>
</svg>
)",
FICTION_VERSION, FICTION_REPO);

inline const std::string EXPECTED_SVG_DARK_CELL_LEVEL_111 =
fmt::format(R"(<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Generated by fiction v0.6.5 (https://github.com/cda-tum/fiction) -->
Expand Down Expand Up @@ -363,6 +404,26 @@ TEMPLATE_TEST_CASE("Generate SiDB layout in SVG for cell-level layout and charge
// Perform the comparison
REQUIRE(normalized_generated_svg == normalized_expected_svg);
}

SECTION("dark mode and hidden lattice")
{
std::stringstream os_light_cds;

write_sidb_layout_svg_params params{};
params.color_background = write_sidb_layout_svg_params::color_mode::DARK;
params.lattice_mode = write_sidb_layout_svg_params::sidb_lattice_mode::HIDE_LATTICE;
write_sidb_layout_svg(layout, os_light_cds, params);

// Retrieve the SVG content
const auto generated_svg = os_light_cds.str();

// Normalize both SVG strings
const auto normalized_generated_svg = normalize_svg(generated_svg);
const auto normalized_expected_svg = normalize_svg(EXPECTED_SVG_DARK_CELL_LEVEL_HIDE_LATTICE);

// Perform the comparison
REQUIRE(normalized_generated_svg == normalized_expected_svg);
}
}
SECTION("charge distribution")
{
Expand Down

0 comments on commit c8da54f

Please sign in to comment.