Skip to content

Commit e356987

Browse files
🎨 Refactored random layout design functions (cda-tum#678)
* 🎨 restructure random layout design. * 📝 Update pyfiction docstrings Signed-off-by: GitHub Actions <[email protected]> * 📝 update docu. * ✅ small fix. * ⚗️ update experiment script after changes. * ⚗️ update experiment script after changes. * ⚗️ update experiment script after changes. * 🎨 small fix. * 🎨 remove missing todo. * 🎨 implement Marcel's feedback. * 📝 Update pyfiction docstrings Signed-off-by: GitHub Actions <[email protected]> * 🎨 small fix. * 🎨 implement Marcel's feedback. * 🎨 implement Marcel's feedback. * 📝 Update pyfiction docstrings Signed-off-by: GitHub Actions <[email protected]> --------- Signed-off-by: GitHub Actions <[email protected]> Co-authored-by: GitHub Actions <[email protected]>
1 parent ac42d89 commit e356987

File tree

9 files changed

+330
-190
lines changed

9 files changed

+330
-190
lines changed

bindings/mnt/pyfiction/include/pyfiction/algorithms/simulation/sidb/random_sidb_layout_generator.hpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,20 @@ void random_layout_generator(pybind11::module& m)
2626
{
2727
namespace py = pybind11;
2828

29-
m.def("generate_random_sidb_layout", &fiction::generate_random_sidb_layout<Lyt>, py::arg("lyt_skeleton"),
29+
m.def("generate_random_sidb_layout", &fiction::generate_random_sidb_layout<Lyt>,
3030
py::arg("params") = fiction::generate_random_sidb_layout_params<fiction::cell<Lyt>>{},
31-
DOC(fiction_generate_random_sidb_layout));
31+
py::arg("lyt_skeleton"), DOC(fiction_generate_random_sidb_layout));
3232

3333
m.def("generate_multiple_random_sidb_layouts", &fiction::generate_multiple_random_sidb_layouts<Lyt>,
34-
py::arg("lyt_skeleton"),
3534
py::arg("params") = fiction::generate_random_sidb_layout_params<fiction::cell<Lyt>>{},
36-
DOC(fiction_generate_multiple_random_sidb_layouts));
35+
py::arg("lyt_skeleton"), DOC(fiction_generate_multiple_random_sidb_layouts));
3736
}
3837

3938
} // namespace detail
4039

4140
inline void random_sidb_layout_generator(pybind11::module& m)
4241
{
4342
namespace py = pybind11;
44-
namespace py = pybind11;
4543

4644
py::enum_<typename fiction::generate_random_sidb_layout_params<fiction::offset::ucoord_t>::positive_charges>(
4745
m, "positive_charges", DOC(fiction_generate_random_sidb_layout_params_positive_charges))
@@ -70,6 +68,9 @@ inline void random_sidb_layout_generator(pybind11::module& m)
7068
.def_readwrite("positive_sidbs",
7169
&fiction::generate_random_sidb_layout_params<fiction::offset::ucoord_t>::positive_sidbs,
7270
DOC(fiction_generate_random_sidb_layout_params_positive_sidbs))
71+
.def_readwrite("simulation_parameters",
72+
&fiction::generate_random_sidb_layout_params<fiction::offset::ucoord_t>::simulation_parameters,
73+
DOC(fiction_generate_random_sidb_layout_params_simulation_parameters))
7374
.def_readwrite("maximal_attempts",
7475
&fiction::generate_random_sidb_layout_params<fiction::offset::ucoord_t>::maximal_attempts,
7576
DOC(fiction_generate_random_sidb_layout_params_maximal_attempts))
@@ -85,6 +86,7 @@ inline void random_sidb_layout_generator(pybind11::module& m)
8586
// NOTE be careful with the order of the following calls! Python will resolve the first matching overload!
8687
detail::random_layout_generator<py_sidb_100_lattice>(m);
8788
detail::random_layout_generator<py_sidb_111_lattice>(m);
89+
detail::random_layout_generator<py_sidb_layout>(m);
8890
}
8991

9092
} // namespace pyfiction

bindings/mnt/pyfiction/include/pyfiction/pybind11_mkdoc_docstrings.hpp

+17-16
Original file line numberDiff line numberDiff line change
@@ -13469,39 +13469,40 @@ R"doc(For each routing objective that cannot be fulfilled in the given
1346913469
layout, this counter is incremented.)doc";
1347013470

1347113471
static const char *__doc_fiction_generate_multiple_random_sidb_layouts =
13472-
R"doc(Generates multiple unique random SiDB layouts by adding them to the
13473-
provided layout skeleton. The layout skeleton serves as the starting
13474-
layout to which SiDBs are added to create unique SiDB layouts.
13472+
R"doc(Generates multiple random layouts featuring a random arrangement of
13473+
SiDBs. These randomly placed dots can be incorporated into an existing
13474+
layout skeleton that may be optionally provided.
1347513475

1347613476
Template parameter ``Lyt``:
1347713477
SiDB cell-level SiDB layout type.
1347813478

13479-
Parameter ``lyt_skeleton``:
13480-
A layout to which random SiDBs are added to create unique layouts.
13481-
1348213479
Parameter ``params``:
1348313480
The parameters for generating the random SiDB layouts.
1348413481

13482+
Parameter ``skeleton``:
13483+
Optional layout to which random dots are added.
13484+
1348513485
Returns:
13486-
A vector containing the unique randomly generated SiDB layouts.)doc";
13486+
A vector containing the unique randomly generated SiDB layouts. If
13487+
the design is impossible, `std::nullopt`)doc";
1348713488

1348813489
static const char *__doc_fiction_generate_random_sidb_layout =
13489-
R"doc(Generates a random layout of SiDBs by adding them to the provided
13490-
layout skeleton. The layout skeleton serves as the starting layout to
13491-
which SiDBs are added to create the final layout.
13490+
R"doc(Generates a layout featuring a random arrangement of SiDBs. These
13491+
randomly placed dots can be incorporated into an existing layout
13492+
skeleton that may be optionally provided.
1349213493

1349313494
Template parameter ``Lyt``:
1349413495
SiDB cell-level SiDB layout type.
1349513496

13496-
Parameter ``lyt_skeleton``:
13497-
A layout to which random cells are added to create the final
13498-
layout.
13499-
1350013497
Parameter ``params``:
1350113498
The parameters for generating the random layout.
1350213499

13500+
Parameter ``skeleton``:
13501+
Optional layout to which random dots are added.
13502+
1350313503
Returns:
13504-
A randomly-generated layout of SiDBs.)doc";
13504+
A randomly generated SiDB layout, or `std::nullopt` if the process
13505+
failed due to conflicting parameters.)doc";
1350513506

1350613507
static const char *__doc_fiction_generate_random_sidb_layout_params =
1350713508
R"doc(This struct stores the parameters for the
@@ -13550,7 +13551,7 @@ static const char *__doc_fiction_generate_random_sidb_layout_params_positive_sid
1355013551
R"doc(If positively charged SiDBs should be prevented, SiDBs are not placed
1355113552
closer than the minimal_spacing.)doc";
1355213553

13553-
static const char *__doc_fiction_generate_random_sidb_layout_params_sim_params = R"doc(Simulation parameters.)doc";
13554+
static const char *__doc_fiction_generate_random_sidb_layout_params_simulation_parameters = R"doc(Simulation parameters.)doc";
1355413555

1355513556
static const char *__doc_fiction_geometric_temperature_schedule =
1355613557
R"doc(A logarithmically decreasing temperature schedule. The temperature is

bindings/mnt/pyfiction/include/pyfiction/technology/charge_distribution_surface.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ template <typename Lyt>
3232
void charge_distribution_surface_layout(pybind11::module& m, const std::string& lattice = "")
3333
{
3434
namespace py = pybind11;
35-
namespace py = pybind11;
3635

3736
using py_cds = py_charge_distribution_surface_layout<Lyt>;
3837

Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import unittest
22

33
from mnt.pyfiction import (
4+
charge_distribution_surface_100,
5+
charge_distribution_surface_111,
6+
generate_multiple_random_sidb_layouts,
47
generate_random_sidb_layout,
58
generate_random_sidb_layout_params,
69
sidb_100_lattice,
710
sidb_111_lattice,
11+
sidb_layout,
812
)
913

1014

@@ -13,30 +17,67 @@ def test_area_with_one_sidb_100_lattice(self):
1317
params = generate_random_sidb_layout_params()
1418
params.number_of_sidbs = 1
1519
params.coordinate_pair = ((10, 10), (10, 10))
16-
result_lyt = generate_random_sidb_layout(sidb_100_lattice(), params)
20+
result_lyt = generate_random_sidb_layout(params, sidb_100_lattice())
1721
self.assertEqual(result_lyt.num_cells(), 1)
1822
cell = (result_lyt.cells())[0]
1923
self.assertEqual(cell.x, 10)
2024
self.assertEqual(cell.y, 10)
2125

26+
def test_area_with_five_sidb_layout(self):
27+
params = generate_random_sidb_layout_params()
28+
params.number_of_sidbs = 5
29+
print(params.number_of_sidbs)
30+
params.coordinate_pair = ((0, 0), (10, 10))
31+
result_lyt = generate_random_sidb_layout(params, sidb_layout())
32+
self.assertEqual(result_lyt.num_cells(), 5)
33+
2234
def test_area_with_five_sidb_100_lattice(self):
2335
params = generate_random_sidb_layout_params()
2436
params.number_of_sidbs = 5
2537
print(params.number_of_sidbs)
2638
params.coordinate_pair = ((0, 0), (10, 10))
27-
result_lyt = generate_random_sidb_layout(sidb_100_lattice(), params)
39+
result_lyt = generate_random_sidb_layout(params, sidb_100_lattice())
40+
self.assertEqual(result_lyt.num_cells(), 5)
41+
42+
def test_area_with_five_sidbs_cds_100(self):
43+
params = generate_random_sidb_layout_params()
44+
params.number_of_sidbs = 5
45+
print(params.number_of_sidbs)
46+
params.coordinate_pair = ((0, 0), (10, 10))
47+
result_lyt = generate_random_sidb_layout(params, charge_distribution_surface_100())
48+
self.assertEqual(result_lyt.num_cells(), 5)
49+
50+
def test_area_with_five_sidbs_cds_111(self):
51+
params = generate_random_sidb_layout_params()
52+
params.number_of_sidbs = 5
53+
print(params.number_of_sidbs)
54+
params.coordinate_pair = ((0, 0), (10, 10))
55+
result_lyt = generate_random_sidb_layout(params, charge_distribution_surface_111())
2856
self.assertEqual(result_lyt.num_cells(), 5)
2957

3058
def test_area_with_one_coordinate_111_lattice(self):
3159
params = generate_random_sidb_layout_params()
3260
params.number_of_sidbs = 1
3361
params.coordinate_pair = ((10, 10), (10, 10))
34-
result_lyt = generate_random_sidb_layout(sidb_111_lattice(), params)
62+
result_lyt = generate_random_sidb_layout(params, sidb_111_lattice())
3563
self.assertEqual(result_lyt.num_cells(), 1)
3664
cell = (result_lyt.cells())[0]
3765
self.assertEqual(cell.x, 10)
3866
self.assertEqual(cell.y, 10)
3967

68+
def test_impossible_design_of_single_layout(self):
69+
params = generate_random_sidb_layout_params()
70+
params.number_of_sidbs = 2
71+
result_lyt = generate_random_sidb_layout(params, sidb_layout())
72+
self.assertIsNone(result_lyt)
73+
74+
def test_impossible_design_of_mutiple_layouts(self):
75+
params = generate_random_sidb_layout_params()
76+
params.maximal_attempts_for_multiple_layouts = 5
77+
params.number_of_sidbs = 2
78+
result_lyt = generate_multiple_random_sidb_layouts(params, sidb_layout())
79+
self.assertIsNone(result_lyt)
80+
4081

4182
if __name__ == "__main__":
4283
unittest.main()

experiments/random_sidb_layout_generation/random_sidb_layout_generation.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,15 @@ int main(int argc, const char* argv[]) // NOLINT
181181
const generate_random_sidb_layout_params<offset::ucoord_t> params{
182182
{{nw_x, nw_y}, {se_x, se_y}}, number_of_placed_sidbs, charges,
183183
sidb_simulation_parameters{3, -0.32}, static_cast<uint64_t>(10E6), number_of_layouts};
184-
const auto unique_lyts = generate_multiple_random_sidb_layouts(sidb_100_cell_clk_lyt{}, params);
185-
for (auto i = 0u; i < unique_lyts.size(); i++)
184+
const auto unique_lyts = generate_multiple_random_sidb_layouts<sidb_100_cell_clk_lyt>(params);
185+
186+
if (unique_lyts.has_value())
186187
{
187-
write_sqd_layout(unique_lyts[i], fmt::format("{}/layout_{}.sqd", dir_path_sqd.string(), i));
188+
for (auto i = 0u; i < unique_lyts.value().size(); i++)
189+
{
190+
write_sqd_layout(unique_lyts.value()[i],
191+
fmt::format("{}/layout_{}.sqd", dir_path_sqd.string(), i));
192+
}
188193
}
189194
}
190195
catch (const std::filesystem::filesystem_error& ex)

experiments/sidb_simulation/electrostatic_ground_state/runtime_analysis_layouts_with_possible_positive_sidbs.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <fiction/algorithms/simulation/sidb/quickexact.hpp>
1010
#include <fiction/algorithms/simulation/sidb/random_sidb_layout_generator.hpp>
1111
#include <fiction/algorithms/simulation/sidb/sidb_simulation_parameters.hpp>
12+
#include <fiction/types.hpp>
1213

1314
#include <mockturtle/utils/stopwatch.hpp>
1415

@@ -52,15 +53,20 @@ int main() // NOLINT
5253
{
5354
random_layouts_params.number_of_sidbs = num_sidbs;
5455

55-
const auto random_layouts = generate_multiple_random_sidb_layouts(Lyt{}, random_layouts_params);
56+
const auto random_layouts = generate_multiple_random_sidb_layouts<Lyt>(random_layouts_params);
5657

5758
double runtime_exhaustive = 0;
5859
double runtime_quickexact = 0;
5960

6061
std::vector<std::size_t> number_of_positive_sidbs_of_gs_per_layout{};
6162
number_of_positive_sidbs_of_gs_per_layout.reserve(random_layouts_params.number_of_unique_generated_layouts);
6263

63-
for (const auto& layout : random_layouts)
64+
if (!random_layouts.has_value())
65+
{
66+
continue;
67+
}
68+
69+
for (const auto& layout : random_layouts.value())
6470
{
6571
const auto exhaustive_results_layout = exhaustive_ground_state_simulation(layout, sim_params);
6672

@@ -80,7 +86,7 @@ int main() // NOLINT
8086
number_of_positive_sidbs_of_gs_per_layout.cend(), 0u)) /
8187
static_cast<double>(number_of_positive_sidbs_of_gs_per_layout.size());
8288

83-
simulation_exp(random_layouts_params.number_of_sidbs, random_layouts.size(), runtime_exhaustive,
89+
simulation_exp(random_layouts_params.number_of_sidbs, random_layouts.value().size(), runtime_exhaustive,
8490
runtime_quickexact, average_pos_sibs_of_gs);
8591

8692
simulation_exp.save();

include/fiction/algorithms/physical_design/design_sidb_gates.hpp

+17-7
Original file line numberDiff line numberDiff line change
@@ -328,36 +328,46 @@ class design_sidb_gates_impl
328328
{
329329
while (!gate_layout_is_found)
330330
{
331-
auto result_lyt = generate_random_sidb_layout<Lyt>(skeleton_layout, parameter);
331+
auto result_lyt = generate_random_sidb_layout<Lyt>(parameter, skeleton_layout);
332+
333+
if (!result_lyt.has_value())
334+
{
335+
continue;
336+
}
337+
332338
if constexpr (has_get_sidb_defect_v<Lyt>)
333339
{
334-
result_lyt.foreach_sidb_defect(
340+
result_lyt.value().foreach_sidb_defect(
335341
[&result_lyt](const auto& cd)
336342
{
337343
if (is_neutrally_charged_defect(cd.second))
338344
{
339-
result_lyt.assign_sidb_defect(cd.first, sidb_defect{sidb_defect_type::NONE});
345+
result_lyt.value().assign_sidb_defect(cd.first,
346+
sidb_defect{sidb_defect_type::NONE});
340347
}
341348
});
342349
}
343-
if (const auto [status, sim_calls] = is_operational(
344-
result_lyt, truth_table, params.operational_params, input_bdl_wires, output_bdl_wires);
350+
351+
if (const auto [status, sim_calls] =
352+
is_operational(result_lyt.value(), truth_table, params.operational_params,
353+
input_bdl_wires, output_bdl_wires);
345354
status == operational_status::OPERATIONAL)
346355
{
347356
const std::lock_guard lock{mutex_to_protect_designed_gate_layouts};
357+
348358
if constexpr (has_get_sidb_defect_v<Lyt>)
349359
{
350360
skeleton_layout.foreach_sidb_defect(
351361
[&result_lyt](const auto& cd)
352362
{
353363
if (is_neutrally_charged_defect(cd.second))
354364
{
355-
result_lyt.assign_sidb_defect(cd.first, cd.second);
365+
result_lyt.value().assign_sidb_defect(cd.first, cd.second);
356366
}
357367
});
358368
}
359369

360-
randomly_designed_gate_layouts.push_back(result_lyt);
370+
randomly_designed_gate_layouts.push_back(result_lyt.value());
361371
gate_layout_is_found = true;
362372
break;
363373
}

0 commit comments

Comments
 (0)