Skip to content

Commit c8da54f

Browse files
Drewniokactions-userpre-commit-ci[bot]
authored
✨ Add option to hide lattice points in the SiDB layout SVG writer (#590)
* 📝 Update pyfiction docstrings Signed-off-by: GitHub Actions <[email protected]> * 🎨 Incorporated pre-commit fixes * 🎨 small fix. * 🐍 small fix. * 🎨 small fix. * 🎨 small fix. * 🎨 small fix. * 📝 Update pyfiction docstrings Signed-off-by: GitHub Actions <[email protected]> * 🐍 small fix. --------- Signed-off-by: GitHub Actions <[email protected]> Co-authored-by: GitHub Actions <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 21d9c06 commit c8da54f

File tree

4 files changed

+117
-18
lines changed

4 files changed

+117
-18
lines changed

bindings/pyfiction/include/pyfiction/inout/write_svg_layout.hpp

+7
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ void write_svg_layout(pybind11::module& m)
7373
.value("DARK", fiction::write_sidb_layout_svg_params::color_mode::DARK,
7474
DOC(fiction_write_sidb_layout_svg_params_color_mode_DARK));
7575

76+
py::enum_<fiction::write_sidb_layout_svg_params::sidb_lattice_mode>(
77+
m, "sidb_lattice_mode", DOC(fiction_write_sidb_layout_svg_params_sidb_lattice_mode))
78+
.value("SHOW_LATTICE", fiction::write_sidb_layout_svg_params::sidb_lattice_mode::SHOW_LATTICE,
79+
DOC(fiction_write_sidb_layout_svg_params_sidb_lattice_mode_SHOW_LATTICE))
80+
.value("HIDE_LATTICE", fiction::write_sidb_layout_svg_params::sidb_lattice_mode::HIDE_LATTICE,
81+
DOC(fiction_write_sidb_layout_svg_params_sidb_lattice_mode_HIDE_LATTICE));
82+
7683
py::class_<fiction::write_sidb_layout_svg_params>(m, "write_sidb_layout_svg_params",
7784
DOC(fiction_write_sidb_layout_svg_params))
7885
.def(py::init<>())

bindings/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp

+10
Original file line numberDiff line numberDiff line change
@@ -18841,10 +18841,20 @@ static const char *__doc_fiction_write_sidb_layout_svg_params_color_mode_DARK =
1884118841

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

18844+
static const char *__doc_fiction_write_sidb_layout_svg_params_lattice_mode = R"doc(The lattice mode of the SiDB layout.)doc";
18845+
1884418846
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";
1884518847

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

18850+
static const char *__doc_fiction_write_sidb_layout_svg_params_sidb_lattice_mode =
18851+
R"doc(Enumeration to specify if the H-Si lattice is plotted in addition to
18852+
SiDBs.)doc";
18853+
18854+
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";
18855+
18856+
static const char *__doc_fiction_write_sidb_layout_svg_params_sidb_lattice_mode_SHOW_LATTICE = R"doc(Lattice is shown.)doc";
18857+
1884818858
static const char *__doc_fiction_write_sidb_layout_svg_params_sidb_size = R"doc(Size of the SiDB in SVG units.)doc";
1884918859

1885018860
static const char *__doc_fiction_write_sqd_layout =

include/fiction/io/write_svg_layout.hpp

+39-18
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,20 @@ struct write_sidb_layout_svg_params
6262
*/
6363
LIGHT
6464
};
65+
/**
66+
* Enumeration to specify if the H-Si lattice is plotted in addition to SiDBs.
67+
*/
68+
enum class sidb_lattice_mode : uint8_t
69+
{
70+
/**
71+
* Lattice is hidden. Only SiDBs are shown.
72+
*/
73+
HIDE_LATTICE,
74+
/**
75+
* Lattice is shown.
76+
*/
77+
SHOW_LATTICE
78+
};
6579
/**
6680
* Size of the H-Si lattice points in SVG units.
6781
*/
@@ -78,6 +92,10 @@ struct write_sidb_layout_svg_params
7892
* The color mode of the background for the SVG output.
7993
*/
8094
color_mode color_background = color_mode::DARK;
95+
/**
96+
* The lattice mode of the SiDB layout.
97+
*/
98+
sidb_lattice_mode lattice_mode = sidb_lattice_mode::SHOW_LATTICE;
8199
};
82100

83101
template <typename Coordinate>
@@ -582,29 +600,32 @@ class write_sidb_layout_svg_impl
582600
const auto min_coord = bb.get_min();
583601
const auto max_coord = bb.get_max();
584602

585-
// Generate all lattice points
586-
const auto all_coords = all_coordinates_in_spanned_area(min_coord, max_coord);
587-
588-
for (const auto& coord : all_coords)
603+
if (ps.lattice_mode == write_sidb_layout_svg_params::sidb_lattice_mode::SHOW_LATTICE)
589604
{
590-
// Shift coordinates for alignment
591-
auto shifted_coord = coord;
592-
593-
shifted_coord.x += 1;
605+
// Generate all lattice points
606+
const auto all_coords = all_coordinates_in_spanned_area(min_coord, max_coord);
594607

595-
if constexpr (has_siqad_coord_v<Lyt>)
596-
{
597-
shifted_coord.y += 1;
598-
}
599-
else
608+
for (const auto& coord : all_coords)
600609
{
601-
shifted_coord.y += 2;
602-
}
610+
// Shift coordinates for alignment
611+
auto shifted_coord = coord;
612+
613+
shifted_coord.x += 1;
603614

604-
const auto nm_pos = sidb_nm_position(lyt, shifted_coord);
615+
if constexpr (has_siqad_coord_v<Lyt>)
616+
{
617+
shifted_coord.y += 1;
618+
}
619+
else
620+
{
621+
shifted_coord.y += 2;
622+
}
623+
624+
const auto nm_pos = sidb_nm_position(lyt, shifted_coord);
605625

606-
svg_content << generate_lattice_point(nm_pos.first * 10, nm_pos.second * 10,
607-
fiction::detail::svg::SI_LATTICE);
626+
svg_content << generate_lattice_point(nm_pos.first * 10, nm_pos.second * 10,
627+
fiction::detail::svg::SI_LATTICE);
628+
}
608629
}
609630

610631
std::vector<cell<Lyt>> all_cells{};

test/io/write_svg_layout.cpp

+61
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,47 @@ inline const std::string EXPECTED_SVG_DARK_CELL_LEVEL =
167167
</svg>)",
168168
FICTION_VERSION, FICTION_REPO);
169169

170+
inline const std::string EXPECTED_SVG_DARK_CELL_LEVEL_HIDE_LATTICE =
171+
fmt::format(R"(<?xml version="1.0" encoding="UTF-8" standalone="no"?>
172+
<!-- Generated by {} ({}) -->
173+
<svg
174+
xmlns:dc="http://purl.org/dc/elements/1.1/"
175+
xmlns:cc="http://creativecommons.org/ns#"
176+
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
177+
xmlns:svg="http://www.w3.org/2000/svg"
178+
xmlns:xlink="http://www.w3.org/1999/xlink"
179+
xmlns="http://www.w3.org/2000/svg"
180+
viewBox="0 0 19.2 23.04"
181+
version="1.1">
182+
<metadata>
183+
<rdf:RDF>
184+
<cc:Work rdf:about="">
185+
<dc:format>image/svg+xml</dc:format>
186+
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
187+
<dc:title></dc:title>
188+
</cc:Work>
189+
</rdf:RDF>
190+
</metadata>
191+
192+
<defs>
193+
<!-- lattice point -->
194+
<circle id="lattice_point" cx="0" cy="0" r="0.3"/>
195+
<!-- SiDB -->
196+
<circle id="sidb_color" cx="0" cy="0" r="0.9"/>
197+
</defs>
198+
<!-- PATH_DEFINITION placeholder -->
199+
<rect x="0" y="0" width="19.2" height="23.04" style="fill:#25323D;"/> <!-- Background rectangle placeholder -->
200+
<g>
201+
<use xlink:href="#sidb_color" x="3.84" y="7.68" style="fill:#C8C8C8; fill-opacity:1; stroke:#ffffff; stroke-width:0.3;"/>
202+
<use xlink:href="#sidb_color" x="7.68" y="7.68" style="fill:#C8C8C8; fill-opacity:1; stroke:#ffffff; stroke-width:0.3;"/>
203+
<use xlink:href="#sidb_color" x="7.68" y="9.93" style="fill:#C8C8C8; fill-opacity:1; stroke:#ffffff; stroke-width:0.3;"/>
204+
<use xlink:href="#sidb_color" x="15.36" y="17.61" style="fill:#C8C8C8; fill-opacity:1; stroke:#ffffff; stroke-width:0.3;"/>
205+
<!-- SVG content placeholder -->
206+
</g>
207+
</svg>
208+
)",
209+
FICTION_VERSION, FICTION_REPO);
210+
170211
inline const std::string EXPECTED_SVG_DARK_CELL_LEVEL_111 =
171212
fmt::format(R"(<?xml version="1.0" encoding="UTF-8" standalone="no"?>
172213
<!-- Generated by fiction v0.6.5 (https://github.com/cda-tum/fiction) -->
@@ -363,6 +404,26 @@ TEMPLATE_TEST_CASE("Generate SiDB layout in SVG for cell-level layout and charge
363404
// Perform the comparison
364405
REQUIRE(normalized_generated_svg == normalized_expected_svg);
365406
}
407+
408+
SECTION("dark mode and hidden lattice")
409+
{
410+
std::stringstream os_light_cds;
411+
412+
write_sidb_layout_svg_params params{};
413+
params.color_background = write_sidb_layout_svg_params::color_mode::DARK;
414+
params.lattice_mode = write_sidb_layout_svg_params::sidb_lattice_mode::HIDE_LATTICE;
415+
write_sidb_layout_svg(layout, os_light_cds, params);
416+
417+
// Retrieve the SVG content
418+
const auto generated_svg = os_light_cds.str();
419+
420+
// Normalize both SVG strings
421+
const auto normalized_generated_svg = normalize_svg(generated_svg);
422+
const auto normalized_expected_svg = normalize_svg(EXPECTED_SVG_DARK_CELL_LEVEL_HIDE_LATTICE);
423+
424+
// Perform the comparison
425+
REQUIRE(normalized_generated_svg == normalized_expected_svg);
426+
}
366427
}
367428
SECTION("charge distribution")
368429
{

0 commit comments

Comments
 (0)