diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp deleted file mode 100644 index 5def11f58..000000000 --- a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp +++ /dev/null @@ -1,88 +0,0 @@ -// -// Created by Jan Drewniok 18.10.2024 -// - -#ifndef PYFICTION_DEFECT_INFLUENCE_OPERATIONAL_DOMAIN_HPP -#define PYFICTION_DEFECT_INFLUENCE_OPERATIONAL_DOMAIN_HPP - -#include "pyfiction/documentation.hpp" -#include "pyfiction/types.hpp" - -#include - -#include -#include -#include - -#include - -namespace pyfiction -{ - -namespace detail -{ - -template -void defect_influence_operational_domain_detail(pybind11::module& m) -{ - using namespace pybind11::literals; - - m.def("defect_influence_operational_domain_grid_search", - &fiction::defect_influence_operational_domain_grid_search, "lyt"_a, "spec"_a, "step_size"_a, - "params"_a = fiction::defect_influence_operational_domain_params{}, "stats"_a = nullptr, - DOC(fiction_defect_influence_operational_domain_grid_search)); - - m.def("defect_influence_operational_domain_random_sampling", - &fiction::defect_influence_operational_domain_random_sampling, "lyt"_a, "spec"_a, "samples"_a, - "params"_a = fiction::defect_influence_operational_domain_params{}, "stats"_a = nullptr, - DOC(fiction_defect_influence_operational_domain_random_sampling)); - - m.def("defect_influence_operational_contour_tracing", - &fiction::defect_influence_operational_domain_contour_tracing, "lyt"_a, "spec"_a, "samples"_a, - "params"_a = fiction::defect_influence_operational_domain_params{}, "stats"_a = nullptr, - DOC(fiction_defect_influence_operational_domain_contour_tracing)); -} - -} // namespace detail - -inline void defect_influence_operational_domain(pybind11::module& m) -{ - namespace py = pybind11; - using namespace pybind11::literals; - - py::class_>( - m, "defect_influence_operational_domain_100") - .def(py::init<>()); - - py::class_>( - m, "defect_influence_operational_domain_111") - .def(py::init<>()); - - py::class_(m, "defect_influence_operational_domain_params") - .def(py::init<>()) - .def_readwrite("defect_influence_params", - &fiction::defect_influence_operational_domain_params::defect_influence_params) - .def_readwrite("operational_params", &fiction::defect_influence_operational_domain_params::operational_params); - - py::class_(m, "defect_influence_operational_domain_stats") - .def(py::init<>()) - .def_readonly("time_total", &fiction::defect_influence_operational_domain_stats::time_total) - .def_readonly("num_simulator_invocations", - &fiction::defect_influence_operational_domain_stats::num_simulator_invocations) - .def_readonly("num_evaluated_parameter_combinations", - &fiction::defect_influence_operational_domain_stats::num_evaluated_defect_positions) - .def_readonly("num_operational_defect_positions", - &fiction::defect_influence_operational_domain_stats::num_operational_defect_positions) - .def_readonly("num_operational_defect_positions", - &fiction::defect_influence_operational_domain_stats::num_operational_defect_positions) - .def_readonly("num_non_operational_defect_positions", - &fiction::defect_influence_operational_domain_stats::num_operational_defect_positions); - - // NOTE be careful with the order of the following calls! Python will resolve the first matching overload! - detail::defect_influence_operational_domain_detail(m); - detail::defect_influence_operational_domain_detail(m); -} - -} // namespace pyfiction - -#endif // PYFICTION_DEFECT_INFLUENCE_OPERATIONAL_DOMAIN_HPP diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_operational_domain.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_operational_domain.hpp new file mode 100644 index 000000000..9443a0ccc --- /dev/null +++ b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/defect_operational_domain.hpp @@ -0,0 +1,95 @@ +// +// Created by Jan Drewniok 18.10.2024 +// + +#ifndef PYFICTION_DEFECT_INFLUENCE_OPERATIONAL_DOMAIN_HPP +#define PYFICTION_DEFECT_INFLUENCE_OPERATIONAL_DOMAIN_HPP + +#include "pyfiction/documentation.hpp" +#include "pyfiction/types.hpp" + +#include + +#include +#include +#include + +#include + +namespace pyfiction +{ + +namespace detail +{ + +template +void defect_influence_operational_domain_detail(pybind11::module& m) +{ + using namespace pybind11::literals; + + // todo update docu + + m.def("defect_operational_domain_grid_search", + &fiction::defect_operational_domain_grid_search, "lyt"_a, "spec"_a, "step_size"_a, + "params"_a = fiction::defect_operational_domain_params{}, "stats"_a = nullptr); + + m.def("defect_operational_domain_random_sampling", + &fiction::defect_operational_domain_random_sampling, "lyt"_a, "spec"_a, "samples"_a, + "params"_a = fiction::defect_operational_domain_params{}, "stats"_a = nullptr); + + m.def("defect_operational_domain_quicktrace", + &fiction::defect_operational_domain_quicktrace, "lyt"_a, "spec"_a, "samples"_a, + "params"_a = fiction::defect_operational_domain_params{}, "stats"_a = nullptr); +} + +} // namespace detail + +inline void defect_influence_operational_domain(pybind11::module& m) +{ + namespace py = pybind11; + using namespace pybind11::literals; + + py::class_>( + m, "defect_operational_domain_100") + .def(py::init<>()); + + py::class_>( + m, "defect_operational_domain_111") + .def(py::init<>()); + + py::class_>( + m, "defect_operational_domain_100_cube") + .def(py::init<>()); + + py::class_>( + m, "defect_operational_domain_111_cube") + .def(py::init<>()); + + py::class_(m, "defect_operational_domain_params") + .def(py::init<>()) + .def_readwrite("defect_influence_params", + &fiction::defect_operational_domain_params::defect_influence_params) + .def_readwrite("operational_params", &fiction::defect_operational_domain_params::operational_params); + + py::class_(m, "defect_operational_domain_stats") + .def(py::init<>()) + .def_readonly("time_total", &fiction::defect_operational_domain_stats::time_total) + .def_readonly("num_simulator_invocations", + &fiction::defect_operational_domain_stats::num_simulator_invocations) + .def_readonly("num_evaluated_parameter_combinations", + &fiction::defect_operational_domain_stats::num_evaluated_defect_positions) + .def_readonly("num_operational_defect_positions", + &fiction::defect_operational_domain_stats::num_operational_defect_positions) + .def_readonly("num_operational_defect_positions", + &fiction::defect_operational_domain_stats::num_operational_defect_positions) + .def_readonly("num_non_operational_defect_positions", + &fiction::defect_operational_domain_stats::num_operational_defect_positions); + + // NOTE be careful with the order of the following calls! Python will resolve the first matching overload! + detail::defect_influence_operational_domain_detail(m); + detail::defect_influence_operational_domain_detail(m); +} + +} // namespace pyfiction + +#endif // PYFICTION_DEFECT_INFLUENCE_OPERATIONAL_DOMAIN_HPP diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp index 7419aaedf..c7ec72ae3 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp @@ -46,14 +46,16 @@ inline void determine_physically_valid_parameters(pybind11::module& m) [](const fiction::operational_domain& domain, const fiction::parameter_point& pp) { - try - { - return domain.get_value(pp).value(); - } - catch (const std::out_of_range& e) + auto result = domain.get_value(pp); + + // Check if the result has a value + if (result.has_value()) { - throw py::value_error(e.what()); + return result.value(); } + // If no value is present, raise a Python ValueError + throw py::value_error("Invalid parameter point: no excited state number available for the provided parameter."); + }, "pp"_a); diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp index 18701c247..732297133 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/maximum_defect_influence_position_and_distance.hpp @@ -43,9 +43,7 @@ inline void maximum_defect_influence_distance(pybind11::module& m) .def_readwrite("sim_params", &fiction::maximum_defect_influence_position_and_distance_params::simulation_parameters) .def_readwrite("additional_scanning_area", - &fiction::maximum_defect_influence_position_and_distance_params::additional_scanning_area) - - ; + &fiction::maximum_defect_influence_position_and_distance_params::additional_scanning_area); // NOTE be careful with the order of the following calls! Python will resolve the first matching overload! diff --git a/bindings/pyfiction/include/pyfiction/inout/read_sqd_layout.hpp b/bindings/pyfiction/include/pyfiction/inout/read_sqd_layout.hpp index 6add9b6f6..0dce736a2 100644 --- a/bindings/pyfiction/include/pyfiction/inout/read_sqd_layout.hpp +++ b/bindings/pyfiction/include/pyfiction/inout/read_sqd_layout.hpp @@ -21,7 +21,7 @@ namespace detail { template -void read_sqd_layout(pybind11::module& m) +void read_sqd_layout(pybind11::module& m, std::string lattice_orientation, std::string coordinate_type) { namespace py = pybind11; using namespace py::literals; @@ -32,48 +32,18 @@ void read_sqd_layout(pybind11::module& m) Lyt (*read_sqd_layout_function_pointer)(const std::string_view&, const std::string_view&) = &fiction::read_sqd_layout; - if constexpr (fiction::is_sidb_lattice_100_v && fiction::has_cube_coord_v) - { - m.def("read_sqd_layout_100_cube", read_sqd_layout_function_pointer, "filename"_a, "name"_a = "", - DOC(fiction_read_sqd_layout_3)); - } - else if constexpr (fiction::is_sidb_lattice_100_v && !fiction::has_cube_coord_v) - { - m.def("read_sqd_layout_100", read_sqd_layout_function_pointer, "filename"_a, "name"_a = "", - DOC(fiction_read_sqd_layout_3)); - } - else if constexpr (fiction::is_sidb_lattice_111_v && fiction::has_cube_coord_v) - { - m.def("read_sqd_layout_111_cube", read_sqd_layout_function_pointer, "filename"_a, "name"_a = "", - DOC(fiction_read_sqd_layout_3)); - } - else if constexpr (fiction::is_sidb_lattice_111_v && !fiction::has_cube_coord_v) - { - m.def("read_sqd_layout_111", read_sqd_layout_function_pointer, "filename"_a, "name"_a = "", - DOC(fiction_read_sqd_layout_3)); - } + m.def(fmt::format("read_sqd_layout_{}{}", lattice_orientation, coordinate_type).c_str(), read_sqd_layout_function_pointer, "filename"_a, "name"_a = "", + DOC(fiction_read_sqd_layout_3)); } } // namespace detail -inline void read_sqd_layout_100(pybind11::module& m) +inline void read_sqd_layout(pybind11::module& m) { - detail::read_sqd_layout(m); -} - -inline void read_sqd_layout_111(pybind11::module& m) -{ - detail::read_sqd_layout(m); -} - -inline void read_sqd_layout_100_cube(pybind11::module& m) -{ - detail::read_sqd_layout(m); -} - -inline void read_sqd_layout_111_cube(pybind11::module& m) -{ - detail::read_sqd_layout(m); + detail::read_sqd_layout(m, "100", ""); + detail::read_sqd_layout(m, "111", ""); + detail::read_sqd_layout(m, "100", "_cube"); + detail::read_sqd_layout(m, "111", "_cube"); } } // namespace pyfiction diff --git a/bindings/pyfiction/include/pyfiction/layouts/cartesian_layout.hpp b/bindings/pyfiction/include/pyfiction/layouts/cartesian_layout.hpp index ee2a1e25b..427d50b3d 100644 --- a/bindings/pyfiction/include/pyfiction/layouts/cartesian_layout.hpp +++ b/bindings/pyfiction/include/pyfiction/layouts/cartesian_layout.hpp @@ -20,92 +20,98 @@ namespace pyfiction { -inline void cartesian_layout(pybind11::module& m) +namespace detail +{ + +template +inline void cartesian_layout_impl(pybind11::module& m) { namespace py = pybind11; using namespace pybind11::literals; + std::string coordinate_type; /** * Cartesian layout. */ - py::class_(m, "cartesian_layout", DOC(fiction_cartesian_layout_overridden)) + if constexpr (fiction::has_cube_coord_v) + { + coordinate_type = "cube"; + } + + py::class_(m, fmt::format("cartesian_layout{}", coordinate_type).c_str(), + DOC(fiction_cartesian_layout_overridden)) .def(py::init<>()) - .def(py::init&>(), "dimension"_a, + .def(py::init&>(), "dimension"_a, DOC(fiction_cartesian_layout_cartesian_layout)) .def( - "coord", [](const py_cartesian_layout& layout, const int64_t x, const int64_t y, const int64_t z) + "coord", [](const CartesianLyt& layout, const int64_t x, const int64_t y, const int64_t z) { return layout.coord(x, y, z); }, "x"_a, "y"_a, "z"_a = 0l, DOC(fiction_cartesian_layout_coord)) - .def("x", &py_cartesian_layout::x, DOC(fiction_cartesian_layout_x)) - .def("y", &py_cartesian_layout::y, DOC(fiction_cartesian_layout_y)) - .def("z", &py_cartesian_layout::z, DOC(fiction_cartesian_layout_z)) - .def("area", &py_cartesian_layout::area, DOC(fiction_cartesian_layout_area)) - .def("resize", &py_cartesian_layout::resize, "dimension"_a, DOC(fiction_cartesian_layout_resize)) - - .def("north", &py_cartesian_layout::north, "c"_a, DOC(fiction_cartesian_layout_north)) - .def("north_east", &py_cartesian_layout::north_east, "c"_a, DOC(fiction_cartesian_layout_north_east)) - .def("east", &py_cartesian_layout::east, "c"_a, DOC(fiction_cartesian_layout_east)) - .def("south_east", &py_cartesian_layout::south_east, "c"_a, DOC(fiction_cartesian_layout_south_east)) - .def("south", &py_cartesian_layout::south, "c"_a, DOC(fiction_cartesian_layout_south)) - .def("south_west", &py_cartesian_layout::south_west, "c"_a, DOC(fiction_cartesian_layout_south_west)) - .def("west", &py_cartesian_layout::west, "c"_a, DOC(fiction_cartesian_layout_west)) - .def("north_west", &py_cartesian_layout::north_west, "c"_a, DOC(fiction_cartesian_layout_north_west)) - .def("above", &py_cartesian_layout::above, "c"_a, DOC(fiction_cartesian_layout_above)) - .def("below", &py_cartesian_layout::below, "c"_a, DOC(fiction_cartesian_layout_below)) - - .def("is_north_of", &py_cartesian_layout::is_north_of, "c1"_a, "c2"_a, - DOC(fiction_cartesian_layout_is_north_of)) - .def("is_east_of", &py_cartesian_layout::is_east_of, "c1"_a, "c2"_a, DOC(fiction_cartesian_layout_is_east_of)) - .def("is_south_of", &py_cartesian_layout::is_south_of, "c1"_a, "c2"_a, - DOC(fiction_cartesian_layout_is_south_of)) - .def("is_west_of", &py_cartesian_layout::is_west_of, "c1"_a, "c2"_a, DOC(fiction_cartesian_layout_is_west_of)) - .def("is_adjacent_of", &py_cartesian_layout::is_adjacent_of, "c1"_a, "c2"_a, + .def("x", &CartesianLyt::x, DOC(fiction_cartesian_layout_x)) + .def("y", &CartesianLyt::y, DOC(fiction_cartesian_layout_y)) + .def("z", &CartesianLyt::z, DOC(fiction_cartesian_layout_z)) + .def("area", &CartesianLyt::area, DOC(fiction_cartesian_layout_area)) + .def("resize", &CartesianLyt::resize, "dimension"_a, DOC(fiction_cartesian_layout_resize)) + + .def("north", &CartesianLyt::north, "c"_a, DOC(fiction_cartesian_layout_north)) + .def("north_east", &CartesianLyt::north_east, "c"_a, DOC(fiction_cartesian_layout_north_east)) + .def("east", &CartesianLyt::east, "c"_a, DOC(fiction_cartesian_layout_east)) + .def("south_east", &CartesianLyt::south_east, "c"_a, DOC(fiction_cartesian_layout_south_east)) + .def("south", &CartesianLyt::south, "c"_a, DOC(fiction_cartesian_layout_south)) + .def("south_west", &CartesianLyt::south_west, "c"_a, DOC(fiction_cartesian_layout_south_west)) + .def("west", &CartesianLyt::west, "c"_a, DOC(fiction_cartesian_layout_west)) + .def("north_west", &CartesianLyt::north_west, "c"_a, DOC(fiction_cartesian_layout_north_west)) + .def("above", &CartesianLyt::above, "c"_a, DOC(fiction_cartesian_layout_above)) + .def("below", &CartesianLyt::below, "c"_a, DOC(fiction_cartesian_layout_below)) + + .def("is_north_of", &CartesianLyt::is_north_of, "c1"_a, "c2"_a, DOC(fiction_cartesian_layout_is_north_of)) + .def("is_east_of", &CartesianLyt::is_east_of, "c1"_a, "c2"_a, DOC(fiction_cartesian_layout_is_east_of)) + .def("is_south_of", &CartesianLyt::is_south_of, "c1"_a, "c2"_a, DOC(fiction_cartesian_layout_is_south_of)) + .def("is_west_of", &CartesianLyt::is_west_of, "c1"_a, "c2"_a, DOC(fiction_cartesian_layout_is_west_of)) + .def("is_adjacent_of", &CartesianLyt::is_adjacent_of, "c1"_a, "c2"_a, DOC(fiction_cartesian_layout_is_adjacent_of)) - .def("is_adjacent_elevation_of", &py_cartesian_layout::is_adjacent_elevation_of, "c1"_a, "c2"_a, + .def("is_adjacent_elevation_of", &CartesianLyt::is_adjacent_elevation_of, "c1"_a, "c2"_a, DOC(fiction_cartesian_layout_is_adjacent_elevation_of)) - .def("is_above", &py_cartesian_layout::is_above, "c1"_a, "c2"_a, DOC(fiction_cartesian_layout_is_above)) - .def("is_below", &py_cartesian_layout::is_below, "c1"_a, "c2"_a, DOC(fiction_cartesian_layout_is_below)) - .def("is_northwards_of", &py_cartesian_layout::is_northwards_of, "c1"_a, "c2"_a, + .def("is_above", &CartesianLyt::is_above, "c1"_a, "c2"_a, DOC(fiction_cartesian_layout_is_above)) + .def("is_below", &CartesianLyt::is_below, "c1"_a, "c2"_a, DOC(fiction_cartesian_layout_is_below)) + .def("is_northwards_of", &CartesianLyt::is_northwards_of, "c1"_a, "c2"_a, DOC(fiction_cartesian_layout_is_northwards_of)) - .def("is_eastwards_of", &py_cartesian_layout::is_eastwards_of, "c1"_a, "c2"_a, + .def("is_eastwards_of", &CartesianLyt::is_eastwards_of, "c1"_a, "c2"_a, DOC(fiction_cartesian_layout_is_eastwards_of)) - .def("is_southwards_of", &py_cartesian_layout::is_southwards_of, "c1"_a, "c2"_a, + .def("is_southwards_of", &CartesianLyt::is_southwards_of, "c1"_a, "c2"_a, DOC(fiction_cartesian_layout_is_southwards_of)) - .def("is_westwards_of", &py_cartesian_layout::is_westwards_of, "c1"_a, "c2"_a, + .def("is_westwards_of", &CartesianLyt::is_westwards_of, "c1"_a, "c2"_a, DOC(fiction_cartesian_layout_is_westwards_of)) - .def("is_at_northern_border", &py_cartesian_layout::is_at_northern_border, "c"_a, + .def("is_at_northern_border", &CartesianLyt::is_at_northern_border, "c"_a, DOC(fiction_cartesian_layout_is_at_northern_border)) - .def("is_at_eastern_border", &py_cartesian_layout::is_at_eastern_border, "c"_a, + .def("is_at_eastern_border", &CartesianLyt::is_at_eastern_border, "c"_a, DOC(fiction_cartesian_layout_is_at_eastern_border)) - .def("is_at_southern_border", &py_cartesian_layout::is_at_southern_border, "c"_a, + .def("is_at_southern_border", &CartesianLyt::is_at_southern_border, "c"_a, DOC(fiction_cartesian_layout_is_at_southern_border)) - .def("is_at_western_border", &py_cartesian_layout::is_at_western_border, "c"_a, + .def("is_at_western_border", &CartesianLyt::is_at_western_border, "c"_a, DOC(fiction_cartesian_layout_is_at_western_border)) - .def("is_at_any_border", &py_cartesian_layout::is_at_any_border, "c"_a, - DOC(fiction_cartesian_layout_is_at_any_border)) + .def("is_at_any_border", &CartesianLyt::is_at_any_border, "c"_a, DOC(fiction_cartesian_layout_is_at_any_border)) - .def("northern_border_of", &py_cartesian_layout::northern_border_of, "c"_a, + .def("northern_border_of", &CartesianLyt::northern_border_of, "c"_a, DOC(fiction_cartesian_layout_northern_border_of)) - .def("eastern_border_of", &py_cartesian_layout::eastern_border_of, "c"_a, + .def("eastern_border_of", &CartesianLyt::eastern_border_of, "c"_a, DOC(fiction_cartesian_layout_eastern_border_of)) - .def("southern_border_of", &py_cartesian_layout::southern_border_of, "c"_a, + .def("southern_border_of", &CartesianLyt::southern_border_of, "c"_a, DOC(fiction_cartesian_layout_southern_border_of)) - .def("western_border_of", &py_cartesian_layout::western_border_of, "c"_a, + .def("western_border_of", &CartesianLyt::western_border_of, "c"_a, DOC(fiction_cartesian_layout_western_border_of)) - .def("is_ground_layer", &py_cartesian_layout::is_ground_layer, "c"_a, - DOC(fiction_cartesian_layout_is_ground_layer)) - .def("is_crossing_layer", &py_cartesian_layout::is_crossing_layer, "c"_a, + .def("is_ground_layer", &CartesianLyt::is_ground_layer, "c"_a, DOC(fiction_cartesian_layout_is_ground_layer)) + .def("is_crossing_layer", &CartesianLyt::is_crossing_layer, "c"_a, DOC(fiction_cartesian_layout_is_crossing_layer)) - .def("is_within_bounds", &py_cartesian_layout::is_within_bounds, "c"_a, - DOC(fiction_cartesian_layout_is_within_bounds)) + .def("is_within_bounds", &CartesianLyt::is_within_bounds, "c"_a, DOC(fiction_cartesian_layout_is_within_bounds)) .def( "coordinates", - [](const py_cartesian_layout& lyt) + [](const CartesianLyt& lyt) { - std::vector> coords{}; + std::vector> coords{}; coords.reserve(lyt.area() * (lyt.z() + 1)); lyt.foreach_coordinate([&coords](const auto& c) { coords.push_back(c); }); return coords; @@ -113,21 +119,21 @@ inline void cartesian_layout(pybind11::module& m) DOC(fiction_cartesian_layout_coordinates)) .def( "ground_coordinates", - [](const py_cartesian_layout& lyt) + [](const CartesianLyt& lyt) { - std::vector> coords{}; + std::vector> coords{}; coords.reserve(lyt.area()); lyt.foreach_ground_coordinate([&coords](const auto& c) { coords.push_back(c); }); return coords; }, DOC(fiction_cartesian_layout_ground_coordinates)) - .def("adjacent_coordinates", &py_cartesian_layout::adjacent_coordinates, "c"_a, + .def("adjacent_coordinates", &CartesianLyt::adjacent_coordinates, "c"_a, DOC(fiction_cartesian_layout_adjacent_coordinates)) - .def("adjacent_opposite_coordinates", &py_cartesian_layout::adjacent_opposite_coordinates, "c"_a, + .def("adjacent_opposite_coordinates", &CartesianLyt::adjacent_opposite_coordinates, "c"_a, DOC(fiction_cartesian_layout_adjacent_opposite_coordinates)) .def("__repr__", - [](const py_cartesian_layout& lyt) -> std::string + [](const CartesianLyt& lyt) -> std::string { std::stringstream stream{}; print_layout(lyt, stream); @@ -137,6 +143,16 @@ inline void cartesian_layout(pybind11::module& m) ; } -} // namespace pyfiction +}; + +inline void cartesian_layout(pybind11::module& m) +{ + detail::cartesian_layout_impl(m); + detail::cartesian_layout_impl(m); +} + + + +}// namespace pyfiction #endif // PYFICTION_CARTESIAN_LAYOUT_HPP diff --git a/bindings/pyfiction/include/pyfiction/layouts/cell_level_layout.hpp b/bindings/pyfiction/include/pyfiction/layouts/cell_level_layout.hpp index a70566ce3..1a8fbfe53 100644 --- a/bindings/pyfiction/include/pyfiction/layouts/cell_level_layout.hpp +++ b/bindings/pyfiction/include/pyfiction/layouts/cell_level_layout.hpp @@ -29,7 +29,7 @@ namespace detail { template -void fcn_technology_cell_level_layout(pybind11::module& m) +void fcn_technology_cells(pybind11::module& m) { namespace py = pybind11; using namespace pybind11::literals; @@ -72,28 +72,37 @@ void fcn_technology_cell_level_layout(pybind11::module& m) { cell_type.value("LOGIC", Technology::cell_type::LOGIC); } - // NOTE: more technologies go here +} + +template +void fcn_technology_cell_layout(pybind11::module& m, std::string coordinate_name = "") +{ + namespace py = pybind11; + using namespace pybind11::literals; - using py_cartesian_technology_cell_layout = py_cartesian_cell_layout; + // fetch technology name + auto tech_name = std::string{fiction::tech_impl_name}; + std::transform(tech_name.begin(), tech_name.end(), tech_name.begin(), ::tolower); /** * Cell-level clocked Cartesian layout. */ - py::class_( - m, fmt::format("{}_layout", tech_name).c_str(), DOC(fiction_cell_level_layout)) + + py::class_( + m, fmt::format("{}_layout{}", tech_name, coordinate_name).c_str(), DOC(fiction_cell_level_layout)) .def(py::init<>()) - .def(py::init&>(), "dimension"_a, + .def(py::init&>(), "dimension"_a, DOC(fiction_cell_level_layout_cell_level_layout)) .def(py::init( - [](const fiction::aspect_ratio& dimension, + [](const fiction::aspect_ratio& dimension, const std::string& scheme_name, - const std::string& layout_name) -> py_cartesian_technology_cell_layout + const std::string& layout_name) -> CellLyt { if (const auto scheme = - fiction::get_clocking_scheme(scheme_name); + fiction::get_clocking_scheme(scheme_name); scheme.has_value()) { - return py_cartesian_technology_cell_layout{dimension, *scheme, layout_name}; + return CellLyt{dimension, *scheme, layout_name}; } throw std::runtime_error("Given name does not refer to a supported clocking scheme"); @@ -101,62 +110,62 @@ void fcn_technology_cell_level_layout(pybind11::module& m) "dimension"_a, "clocking_scheme"_a = "2DDWave", "layout_name"_a = "", DOC(fiction_cell_level_layout_cell_level_layout_2)) - .def("assign_cell_type", &py_cartesian_technology_cell_layout::assign_cell_type, "c"_a, "ct"_a, + .def("assign_cell_type", &CellLyt::assign_cell_type, "c"_a, "ct"_a, DOC(fiction_cell_level_layout_assign_cell_type)) - .def("get_cell_type", &py_cartesian_technology_cell_layout::get_cell_type, "c"_a, + .def("get_cell_type", &CellLyt::get_cell_type, "c"_a, DOC(fiction_cell_level_layout_get_cell_type)) - .def("is_empty_cell", &py_cartesian_technology_cell_layout::is_empty_cell, "c"_a, + .def("is_empty_cell", &CellLyt::is_empty_cell, "c"_a, DOC(fiction_cell_level_layout_is_empty_cell)) - .def("assign_cell_name", &py_cartesian_technology_cell_layout::assign_cell_name, "c"_a, "n"_a, + .def("assign_cell_name", &CellLyt::assign_cell_name, "c"_a, "n"_a, DOC(fiction_cell_level_layout_assign_cell_name)) - .def("get_cell_name", &py_cartesian_technology_cell_layout::get_cell_name, "c"_a, + .def("get_cell_name", &CellLyt::get_cell_name, "c"_a, DOC(fiction_cell_level_layout_get_cell_name)) - .def("set_layout_name", &py_cartesian_technology_cell_layout::set_layout_name, "name"_a, + .def("set_layout_name", &CellLyt::set_layout_name, "name"_a, DOC(fiction_cell_level_layout_set_layout_name)) - .def("get_layout_name", &py_cartesian_technology_cell_layout::get_layout_name, + .def("get_layout_name", &CellLyt::get_layout_name, DOC(fiction_cell_level_layout_get_layout_name)) - .def("num_cells", &py_cartesian_technology_cell_layout::num_cells, DOC(fiction_cell_level_layout_num_cells)) - .def("is_empty", &py_cartesian_technology_cell_layout::is_empty, DOC(fiction_cell_level_layout_is_empty)) - .def("num_pis", &py_cartesian_technology_cell_layout::num_pis, DOC(fiction_cell_level_layout_num_pis)) - .def("num_pos", &py_cartesian_technology_cell_layout::num_pos, DOC(fiction_cell_level_layout_num_pos)) - .def("is_pi", &py_cartesian_technology_cell_layout::is_pi, "c"_a, DOC(fiction_cell_level_layout_is_pi)) - .def("is_po", &py_cartesian_technology_cell_layout::is_po, "c"_a, DOC(fiction_cell_level_layout_is_po)) + .def("num_cells", &CellLyt::num_cells, DOC(fiction_cell_level_layout_num_cells)) + .def("is_empty", &CellLyt::is_empty, DOC(fiction_cell_level_layout_is_empty)) + .def("num_pis", &CellLyt::num_pis, DOC(fiction_cell_level_layout_num_pis)) + .def("num_pos", &CellLyt::num_pos, DOC(fiction_cell_level_layout_num_pos)) + .def("is_pi", &CellLyt::is_pi, "c"_a, DOC(fiction_cell_level_layout_is_pi)) + .def("is_po", &CellLyt::is_po, "c"_a, DOC(fiction_cell_level_layout_is_po)) .def("cells", - [](const py_cartesian_technology_cell_layout& lyt) + [](const CellLyt& lyt) { - std::vector> cells{}; + std::vector> cells{}; cells.reserve(lyt.num_cells()); lyt.foreach_cell([&cells](const auto& c) { cells.push_back(c); }); return cells; }) .def("pis", - [](const py_cartesian_technology_cell_layout& lyt) + [](const CellLyt& lyt) { - std::vector> pis{}; + std::vector> pis{}; pis.reserve(lyt.num_pis()); lyt.foreach_pi([&pis](const auto& c) { pis.push_back(c); }); return pis; }) .def("pos", - [](const py_cartesian_technology_cell_layout& lyt) + [](const CellLyt& lyt) { - std::vector> pos{}; + std::vector> pos{}; pos.reserve(lyt.num_pos()); lyt.foreach_po([&pos](const auto& c) { pos.push_back(c); }); return pos; }) .def( "bounding_box_2d", - [](const py_cartesian_technology_cell_layout& lyt) + [](const CellLyt& lyt) { - const auto bb = fiction::bounding_box_2d(lyt); + const auto bb = fiction::bounding_box_2d(lyt); return std::make_pair(bb.get_min(), bb.get_max()); }, DOC(fiction_bounding_box_2d_overridden)) .def("__repr__", - [](const py_cartesian_technology_cell_layout& lyt) -> std::string + [](const CellLyt& lyt) -> std::string { std::stringstream stream{}; @@ -171,7 +180,6 @@ void fcn_technology_cell_level_layout(pybind11::module& m) return stream.str(); }) - ; } @@ -179,9 +187,14 @@ void fcn_technology_cell_level_layout(pybind11::module& m) inline void cell_level_layouts(pybind11::module& m) { - detail::fcn_technology_cell_level_layout(m); - detail::fcn_technology_cell_level_layout(m); - detail::fcn_technology_cell_level_layout(m); + detail::fcn_technology_cells(m); + detail::fcn_technology_cells(m); + detail::fcn_technology_cells(m); + + detail::fcn_technology_cell_layout(m); + detail::fcn_technology_cell_layout(m); + detail::fcn_technology_cell_layout(m); + detail::fcn_technology_cell_layout(m, "cube"); } } // namespace pyfiction diff --git a/bindings/pyfiction/include/pyfiction/layouts/clocked_layout.hpp b/bindings/pyfiction/include/pyfiction/layouts/clocked_layout.hpp index 756be81e3..888f3cd81 100644 --- a/bindings/pyfiction/include/pyfiction/layouts/clocked_layout.hpp +++ b/bindings/pyfiction/include/pyfiction/layouts/clocked_layout.hpp @@ -25,7 +25,7 @@ namespace detail { template -void clocked_layout(pybind11::module& m, const std::string& topology) +void clocked_layout(pybind11::module& m, const std::string& topology, const std::string& coordinate_type = "") { namespace py = pybind11; using namespace pybind11::literals; @@ -33,7 +33,7 @@ void clocked_layout(pybind11::module& m, const std::string& topology) /** * Clocked Cartesian layout. */ - py::class_(m, fmt::format("clocked_{}_layout", topology).c_str(), DOC(fiction_clocked_layout)) + py::class_(m, fmt::format("clocked_{}_layout{}", topology, coordinate_type).c_str(), DOC(fiction_clocked_layout)) .def(py::init<>()) .def(py::init&>(), "dimension"_a, DOC(fiction_clocked_layout_clocked_layout)) @@ -89,6 +89,7 @@ void clocked_layout(pybind11::module& m, const std::string& topology) void clocked_layouts(pybind11::module& m) { detail::clocked_layout(m, "cartesian"); + detail::clocked_layout(m, "cartesian", "cube"); detail::clocked_layout(m, "shifted_cartesian"); detail::clocked_layout(m, "hexagonal"); } diff --git a/bindings/pyfiction/include/pyfiction/technology/sidb_lattice.hpp b/bindings/pyfiction/include/pyfiction/technology/sidb_lattice.hpp index 8d6ad88e0..719c185a8 100644 --- a/bindings/pyfiction/include/pyfiction/technology/sidb_lattice.hpp +++ b/bindings/pyfiction/include/pyfiction/technology/sidb_lattice.hpp @@ -30,7 +30,7 @@ namespace detail * @tparam LayoutType The layout type (e.g., py_sidb_layout for regular layouts, py_sidb_layout_cube for cube layouts). */ template -void sidb_lattice_cell_level_layout(pybind11::module& m) +void sidb_lattice_cell_level_layout(pybind11::module& m, std::string lattice_name = "", std::string coordinate_tye = "") { namespace py = pybind11; using namespace py::literals; @@ -39,71 +39,25 @@ void sidb_lattice_cell_level_layout(pybind11::module& m) auto orientation = std::string{fiction::sidb_lattice_name}; std::transform(orientation.begin(), orientation.end(), orientation.begin(), ::tolower); - // Define the type alias for the specific SiDB lattice layout being bound - using py_sidb_lattice = fiction::sidb_lattice; - - /** - * SiDB lattice. - */ - if constexpr (fiction::has_cube_coord_v && fiction::is_sidb_lattice_100_v) - { - py::class_(m, "sidb_100_lattice_cube", DOC(fiction_cell_level_layout), - py::module_local()) - .def(py::init<>()) // Default constructor - .def(py::init&, const std::string&>(), "dimension"_a, "name"_a = "", - DOC(fiction_sidb_lattice)); - } - else if constexpr (fiction::has_cube_coord_v && fiction::is_sidb_lattice_111_v) - { - py::class_(m, "sidb_111_lattice_cube", DOC(fiction_cell_level_layout), - py::module_local()) - .def(py::init<>()) // Default constructor - .def(py::init&, const std::string&>(), "dimension"_a, "name"_a = "", - DOC(fiction_sidb_lattice)); - } - else if constexpr (!fiction::has_cube_coord_v && fiction::is_sidb_lattice_100_v) - { - py::class_(m, "sidb_100_lattice", DOC(fiction_cell_level_layout), - py::module_local()) - .def(py::init<>()) // Default constructor - .def(py::init&, const std::string&>(), "dimension"_a, "name"_a = "", - DOC(fiction_sidb_lattice)); - } - else if constexpr (!fiction::has_cube_coord_v && fiction::is_sidb_lattice_111_v) - { - py::class_(m, "sidb_111_lattice", DOC(fiction_cell_level_layout), + py::class_(m, fmt::format("sidb_{}_lattice{}", lattice_name, coordinate_tye).c_str(), DOC(fiction_cell_level_layout), py::module_local()) .def(py::init<>()) // Default constructor .def(py::init&, const std::string&>(), "dimension"_a, "name"_a = "", DOC(fiction_sidb_lattice)); - } } } // namespace detail -inline void sidb_lattices_100_cube(pybind11::module& m) -{ - // Bind the cube-coordinate 100 and 111 SiDB lattices - detail::sidb_lattice_cell_level_layout(m); -} -inline void sidb_lattices_111(pybind11::module& m) -{ - - detail::sidb_lattice_cell_level_layout(m); -} - -inline void sidb_lattices_100(pybind11::module& m) +inline void sidb_lattice(pybind11::module& m) { // Bind the regular 100 and 111 SiDB lattices - detail::sidb_lattice_cell_level_layout(m); + detail::sidb_lattice_cell_level_layout(m, "100"); + detail::sidb_lattice_cell_level_layout(m, "100", "_cube"); + detail::sidb_lattice_cell_level_layout(m, "111"); + detail::sidb_lattice_cell_level_layout(m, "111", "_cube"); } -inline void sidb_lattices_111_cube(pybind11::module& m) -{ - // Bind the regular 100 and 111 SiDB lattices - detail::sidb_lattice_cell_level_layout(m); -} } // namespace pyfiction diff --git a/bindings/pyfiction/pyfiction.cpp b/bindings/pyfiction/pyfiction.cpp index 350054806..0b9b7653a 100644 --- a/bindings/pyfiction/pyfiction.cpp +++ b/bindings/pyfiction/pyfiction.cpp @@ -34,6 +34,7 @@ #include "pyfiction/algorithms/simulation/sidb/convert_potential_to_distance.hpp" #include "pyfiction/algorithms/simulation/sidb/critical_temperature.hpp" #include "pyfiction/algorithms/simulation/sidb/detect_bdl_pairs.hpp" +#include "pyfiction/algorithms/simulation/sidb/defect_operational_domain.hpp" #include "pyfiction/algorithms/simulation/sidb/detect_bdl_wires.hpp" #include "pyfiction/algorithms/simulation/sidb/determine_groundstate_from_simulation_results.hpp" #include "pyfiction/algorithms/simulation/sidb/determine_physically_valid_parameters.hpp" @@ -136,8 +137,8 @@ PYBIND11_MODULE(pyfiction, m) pyfiction::detect_bdl_wires(m); pyfiction::is_operational(m); pyfiction::operational_domain(m); - // pyfiction::defect_influence_operational_domain(m); - // pyfiction::maximum_defect_influence_distance(m); + pyfiction::defect_influence_operational_domain(m); + pyfiction::maximum_defect_influence_distance(m); pyfiction::exhaustive_ground_state_simulation(m); pyfiction::quicksim(m); pyfiction::quickexact(m); @@ -200,14 +201,11 @@ PYBIND11_MODULE(pyfiction, m) pyfiction::sidb_charge_state(m); pyfiction::sidb_nm_position(m); pyfiction::sidb_nm_distance(m); - pyfiction::sidb_lattices_100(m); - // pyfiction::sidb_lattices_100_cube(m); - pyfiction::sidb_lattices_111(m); - // pyfiction::sidb_lattices_111_cube(m); + pyfiction::sidb_lattice(m); pyfiction::charge_distribution_surfaces(m); - /** - * Input/Output - */ + // /** + // * Input/Output + // */ pyfiction::write_dot_layout(m); pyfiction::write_fgl_layout(m); pyfiction::write_qca_layout(m); @@ -221,10 +219,7 @@ PYBIND11_MODULE(pyfiction, m) pyfiction::write_operational_domain(m); pyfiction::read_fgl_layout(m); pyfiction::read_fqca_layout(m); - pyfiction::read_sqd_layout_100(m); - pyfiction::read_sqd_layout_111(m); - pyfiction::read_sqd_layout_100_cube(m); - pyfiction::read_sqd_layout_111_cube(m); + pyfiction::read_sqd_layout(m); /** * Utils diff --git a/bindings/pyfiction/test/algorithms/simulation/sidb/test_defect_operational_domain.py b/bindings/pyfiction/test/algorithms/simulation/sidb/test_defect_operational_domain.py index c579de6e4..d4ff769c3 100644 --- a/bindings/pyfiction/test/algorithms/simulation/sidb/test_defect_operational_domain.py +++ b/bindings/pyfiction/test/algorithms/simulation/sidb/test_defect_operational_domain.py @@ -6,25 +6,29 @@ dir_path = os.path.dirname(os.path.realpath(__file__)) -class TestOperationalDomain(unittest.TestCase): +class TestDefectOperationalDomain(unittest.TestCase): def test_xor_gate_100_lattice(self): lyt = read_sqd_layout_100_cube(dir_path + "/../../../resources/hex_21_inputsdbp_xor_v1.sqd") - params = defect_influence_operational_domain_params() - params.defect_influence_params.additional_scanning_area = (20, 20) + params = defect_operational_domain_params() + params.operational_params.simulation_parameters.base = 2 + params.operational_params.simulation_parameters.mu_minus = -0.32 + params.defect_influence_params.additional_scanning_area = (50, 50) - stats_grid = defect_influence_operational_domain_stats() - _ = defect_influence_operational_domain_grid_search(lyt, [create_xor_tt()], params, 3, stats_grid) - self.assertGreater(stats_grid.num_operational_parameter_combinations, 0) + params.defect_influence_params.defect = sidb_defect(sidb_defect_type.SI_VACANCY, -1, 10.6, 5.9) - stats_random = defect_influence_operational_domain_stats() - _ = defect_influence_operational_domain_grid_search(lyt, [create_xor_tt()], params, 100, stats_random) - self.assertGreater(stats_random.num_operational_parameter_combinations, 0) + stats_grid = defect_operational_domain_stats() + _ = defect_operational_domain_grid_search(lyt, [create_xor_tt()], 6, params, stats_grid) + self.assertGreater(stats_grid.num_operational_defect_positions, 0) - stats_contour_tracing = defect_influence_operational_domain_stats() - _ = defect_influence_operational_domain_contour_tracing(lyt, [create_xor_tt()], params, 20, stats_contour_tracing) - self.assertGreater(stats_contour_tracing.num_operational_parameter_combinations, 0) + stats_random = defect_operational_domain_stats() + _ = defect_operational_domain_random_sampling(lyt, [create_xor_tt()], 100, params, stats_random) + self.assertGreater(stats_random.num_operational_defect_positions, 0) + + stats_quicktrace = defect_operational_domain_stats() + _ = defect_operational_domain_quicktrace(lyt, [create_xor_tt()], 3, params, stats_quicktrace) + self.assertGreater(stats_quicktrace.num_operational_defect_positions, 0) if __name__ == '__main__': unittest.main() diff --git a/cli/cmd/simulation/opdom.hpp b/cli/cmd/simulation/opdom.hpp index e0430bc63..466d89097 100644 --- a/cli/cmd/simulation/opdom.hpp +++ b/cli/cmd/simulation/opdom.hpp @@ -73,7 +73,7 @@ class opdom_command : public command "Use random sampling instead of grid search with this many random samples"); add_option("--flood_fill,-f", num_random_samples, "Use flood fill instead of grid search with this many initial random samples"); - add_option("--contour_tracing,-c", num_random_samples, + add_option("--quicktrace,-c", num_random_samples, "Use contour tracing instead of grid search with this many random samples"); add_option("filename", filename, "CSV filename to write the operational domain to")->required(); @@ -151,7 +151,7 @@ class opdom_command : public command // make sure that at most one algorithm is selected const std::array algorithm_selections = {is_set("random_sampling"), is_set("flood_fill"), - is_set("contour_tracing")}; + is_set("quicktrace")}; if (std::count(algorithm_selections.cbegin(), algorithm_selections.cend(), true) > 1) { env->out() << "[e] only one algorithm can be selected at a time" << std::endl; @@ -303,7 +303,7 @@ class opdom_command : public command op_domain = fiction::operational_domain_flood_fill(*lyt_ptr, std::vector{*tt_ptr}, num_random_samples, params, &stats); } - else if (is_set("contour_tracing")) + else if (is_set("quicktrace")) { op_domain = fiction::operational_domain_contour_tracing( *lyt_ptr, std::vector{*tt_ptr}, num_random_samples, params, &stats); diff --git a/docs/cli.rst b/docs/cli.rst index 54122c73a..c8d0b2110 100644 --- a/docs/cli.rst +++ b/docs/cli.rst @@ -402,7 +402,7 @@ By default, grid search is applied to explore the operational domain. The algori the following options: - ``--random_sampling``/``-r`` - ``--flood_fill``/``-f`` -- ``--contour_tracing``/``-c`` +- ``--quicktrace``/``-c`` each of which start from a set of random samples, whose number has to be passed as an argument to the flag. See ``opdom -h`` for a full list of arguments. diff --git a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp index d5a17dd04..6a8c1e35b 100644 --- a/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp @@ -222,7 +222,7 @@ class defect_operational_domain_impl return defect_operational_domain; } - [[nodiscard]] defect_operational_domain contour_tracing(const std::size_t samples) noexcept + [[nodiscard]] defect_operational_domain quicktrace(const std::size_t samples) noexcept { mockturtle::stopwatch stop{stats.time_total}; @@ -286,8 +286,11 @@ class defect_operational_domain_impl current_neighborhood.front() : next_clockwise_point(current_neighborhood, backtrack_point); - while (next_point != contour_starting_point) + std::size_t counter = 0; + while (next_point != contour_starting_point && counter < 1000) { + counter ++; // avoid infinite loops + const auto operational_status = is_defect_position_operational(next_point); assert(layout.num_defects() == 0 && "more than one defect"); @@ -757,7 +760,7 @@ defect_operational_domain defect_operational_domain_quicktrace(const Lyt& l defect_operational_domain_stats st{}; detail::defect_operational_domain_impl p{lyt, spec, params, st}; - const auto result = p.contour_tracing(samples); + const auto result = p.quicktrace(samples); if (stats) { diff --git a/include/fiction/algorithms/simulation/sidb/operational_domain.hpp b/include/fiction/algorithms/simulation/sidb/operational_domain.hpp index d20c75860..1a8d63413 100644 --- a/include/fiction/algorithms/simulation/sidb/operational_domain.hpp +++ b/include/fiction/algorithms/simulation/sidb/operational_domain.hpp @@ -303,8 +303,9 @@ void validate_sweep_parameters(const operational_domain_params& params) template std::optional contains_key(const MapType& map, const typename MapType::key_type& key) { - auto it = map.find(key); - if (it != map.end()) + const auto it = map.find(key); + + if (it != map.cend()) { return it->second; } diff --git a/test/algorithms/simulation/sidb/assess_physical_population_stability.cpp b/test/algorithms/simulation/sidb/assess_physical_population_stability.cpp index de6b3bfce..8dfaab87a 100644 --- a/test/algorithms/simulation/sidb/assess_physical_population_stability.cpp +++ b/test/algorithms/simulation/sidb/assess_physical_population_stability.cpp @@ -6,8 +6,6 @@ #include #include -#include "utils/blueprints/layout_blueprints.hpp" - #include #include #include diff --git a/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp b/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp index 5bbb9bf9d..5d9aacb60 100644 --- a/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp +++ b/test/algorithms/simulation/sidb/defect_influence_operational_domain.cpp @@ -5,15 +5,13 @@ #include #include +#include "utils/blueprints/layout_blueprints.hpp" + #include #include #include #include #include -#include -#include -#include -#include #include #include #include @@ -27,43 +25,7 @@ using namespace fiction; TEST_CASE("novel designed AND Gate influence distance function which fails again", "[defect-influence-operational-domain]") { - sidb_cell_clk_lyt_siqad lyt{}; - - lyt.assign_cell_type({38, 0, 0}, sidb_technology::cell_type::INPUT); - lyt.assign_cell_type({0, 0, 0}, sidb_technology::cell_type::INPUT); - - lyt.assign_cell_type({36, 1, 0}, sidb_technology::cell_type::INPUT); - lyt.assign_cell_type({2, 1, 0}, sidb_technology::cell_type::INPUT); - - lyt.assign_cell_type({6, 2, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({8, 3, 0}, sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type({32, 2, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({30, 3, 0}, sidb_technology::cell_type::NORMAL); - - lyt.assign_cell_type({26, 4, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({24, 5, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({12, 4, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({14, 5, 0}, sidb_technology::cell_type::NORMAL); - - // canvas SiDBs - // ------------- - lyt.assign_cell_type({17, 8, 1}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({21, 8, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({18, 11, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({20, 11, 0}, sidb_technology::cell_type::NORMAL); - // ------------- - - lyt.assign_cell_type({19, 13, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({20, 14, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({24, 15, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({26, 16, 0}, sidb_technology::cell_type::NORMAL); - lyt.assign_cell_type({32, 18, 0}, sidb_technology::cell_type::OUTPUT); - lyt.assign_cell_type({30, 17, 0}, sidb_technology::cell_type::OUTPUT); - - lyt.assign_cell_type({36, 19, 0}, sidb_technology::cell_type::NORMAL); - - write_sqd_layout(lyt, "/Users/jandrewniok/CLionProjects/fiction_fork/experiments/quicktrace/plots/and/and.sqd"); + const auto lyt = blueprints::bestagon_xor(); const auto cube_lyt = convert_layout_to_fiction_coordinates(lyt); @@ -77,9 +39,9 @@ TEST_CASE("novel designed AND Gate influence distance function which fails again params.defect_influence_params.additional_scanning_area = {20, 20}; defect_operational_domain_stats stats{}; const auto defect_influence_domain = - defect_operational_domain_grid_search(cube_lyt, std::vector{create_or_tt()}, 1, params, &stats); + defect_operational_domain_grid_search(cube_lyt, std::vector{create_xor_tt()}, 3, params, &stats); CHECK_THAT(defect_avoidance_distance(cube_lyt, defect_influence_domain).minimum_defect_clearance, - Catch::Matchers::WithinAbs(12.579477930, physical_constants::POP_STABILITY_ERR)); + Catch::Matchers::WithinAbs(8.42177748459314479, physical_constants::POP_STABILITY_ERR)); } SECTION("Random Sampling") @@ -87,18 +49,18 @@ TEST_CASE("novel designed AND Gate influence distance function which fails again params.defect_influence_params.additional_scanning_area = {20, 20}; defect_operational_domain_stats stats{}; const auto defect_influence_domain = - defect_operational_domain_random_sampling(cube_lyt, std::vector{create_or_tt()}, 100, params, &stats); + defect_operational_domain_random_sampling(cube_lyt, std::vector{create_xor_tt()}, 100, params, &stats); CHECK(defect_influence_domain.operational_values.size() == 100); CHECK(defect_avoidance_distance(cube_lyt, defect_influence_domain).minimum_defect_clearance <= 12.579477930); } - SECTION("Contour Tracing") + SECTION("QuickTrace") { - params.defect_influence_params.additional_scanning_area = {20, 20}; + params.defect_influence_params.additional_scanning_area = {30, 30}; defect_operational_domain_stats stats{}; const auto defect_influence_domain = - defect_operational_domain_quicktrace(cube_lyt, std::vector{create_or_tt()}, 5, params, &stats); + defect_operational_domain_quicktrace(cube_lyt, std::vector{create_xor_tt()}, 5, params, &stats); CHECK_THAT(defect_avoidance_distance(cube_lyt, defect_influence_domain).minimum_defect_clearance, - Catch::Matchers::WithinAbs(12.579477930, physical_constants::POP_STABILITY_ERR)); + Catch::Matchers::WithinAbs(9.62301241815680086, physical_constants::POP_STABILITY_ERR)); } } diff --git a/test/algorithms/simulation/sidb/operational_domain.cpp b/test/algorithms/simulation/sidb/operational_domain.cpp index d9fa8675b..575a7f4f4 100644 --- a/test/algorithms/simulation/sidb/operational_domain.cpp +++ b/test/algorithms/simulation/sidb/operational_domain.cpp @@ -137,7 +137,7 @@ TEST_CASE("Error handling of operational domain algorithms", "[operational-domai std::invalid_argument); } } - SECTION("contour_tracing") + SECTION("quicktrace") { // contour tracing operates only on 2-dimensional parameter spaces for (const auto& params : @@ -195,7 +195,7 @@ TEST_CASE("Error handling of operational domain algorithms", "[operational-domai CHECK_THROWS_AS(operational_domain_flood_fill(lat, std::vector{create_id_tt()}, 1, params), std::invalid_argument); } - SECTION("contour_tracing") + SECTION("quicktrace") { CHECK_THROWS_AS(operational_domain_contour_tracing(lat, std::vector{create_id_tt()}, 1, params), std::invalid_argument); @@ -243,7 +243,7 @@ TEST_CASE("Error handling of operational domain algorithms", "[operational-domai CHECK_THROWS_AS(operational_domain_flood_fill(lat, std::vector{create_id_tt()}, 1, params), std::invalid_argument); } - SECTION("contour_tracing") + SECTION("quicktrace") { CHECK_THROWS_AS(operational_domain_contour_tracing(lat, std::vector{create_id_tt()}, 1, params), std::invalid_argument); @@ -422,7 +422,7 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") } } } - SECTION("contour_tracing") + SECTION("quicktrace") { const auto op_domain = operational_domain_contour_tracing(lat, std::vector{create_id_tt()}, 1, op_domain_params, &op_domain_stats); @@ -505,7 +505,7 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") CHECK(op_domain_stats.num_operational_parameter_combinations == 100); CHECK(op_domain_stats.num_non_operational_parameter_combinations == 0); } - SECTION("contour_tracing") + SECTION("quicktrace") { const auto op_domain = operational_domain_contour_tracing(lat, std::vector{create_id_tt()}, 1, op_domain_params, &op_domain_stats); @@ -661,7 +661,7 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") } } } - SECTION("contour_tracing") + SECTION("quicktrace") { const auto op_domain = operational_domain_contour_tracing(lat, std::vector{create_id_tt()}, 1, op_domain_params, &op_domain_stats); @@ -815,7 +815,7 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") CHECK(op_domain_stats.num_non_operational_parameter_combinations <= 500); } } - SECTION("contour_tracing") + SECTION("quicktrace") { const auto op_domain = operational_domain_contour_tracing(lat, std::vector{create_id_tt()}, 25, op_domain_params, &op_domain_stats); @@ -924,7 +924,7 @@ TEST_CASE("BDL wire operational domain computation", "[operational-domain]") CHECK(op_domain_stats.num_non_operational_parameter_combinations <= 176); } } - SECTION("contour_tracing") + SECTION("quicktrace") { const auto op_domain = operational_domain_contour_tracing(lat, std::vector{create_id_tt()}, 50, op_domain_params, &op_domain_stats); @@ -1031,7 +1031,7 @@ TEST_CASE("SiQAD's AND gate operational domain computation", "[operational-domai CHECK(op_domain_stats.num_operational_parameter_combinations == 100); CHECK(op_domain_stats.num_non_operational_parameter_combinations == 0); } - SECTION("contour_tracing") + SECTION("quicktrace") { const auto op_domain = operational_domain_contour_tracing(lat, std::vector{create_and_tt()}, 1, op_domain_params, &op_domain_stats); @@ -1148,7 +1148,7 @@ TEST_CASE("SiQAD's AND gate operational domain computation, using cube coordinat CHECK(op_domain_stats.num_operational_parameter_combinations == 100); CHECK(op_domain_stats.num_non_operational_parameter_combinations == 0); } - SECTION("contour_tracing") + SECTION("quicktrace") { const auto op_domain = operational_domain_contour_tracing(lat, std::vector{create_and_tt()}, 1, op_domain_params, &op_domain_stats); @@ -1237,7 +1237,7 @@ TEMPLATE_TEST_CASE("AND gate on the H-Si(111)-1x1 surface", "[operational-domain CHECK(op_domain_stats.num_non_operational_parameter_combinations == 0); } } - SECTION("contour_tracing") + SECTION("quicktrace") { const auto op_domain = operational_domain_contour_tracing(layout, std::vector{create_and_tt()}, 1, op_domain_params, &op_domain_stats); diff --git a/test/utils/blueprints/layout_blueprints.hpp b/test/utils/blueprints/layout_blueprints.hpp index dba271966..241b42e74 100644 --- a/test/utils/blueprints/layout_blueprints.hpp +++ b/test/utils/blueprints/layout_blueprints.hpp @@ -924,6 +924,7 @@ Lyt and_gate_111_mirrored_on_the_x_axis() noexcept static_assert(fiction::is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(fiction::has_sidb_technology_v, "Lyt is not an SiDB layout"); static_assert(fiction::is_sidb_lattice_111_v, "Lyt should have 111 as lattice orientation"); + static_assert(fiction::has_siqad_coord_v, "Lyt is not an SiDB layout"); Lyt lyt{}; @@ -972,6 +973,7 @@ Lyt bestagon_crossing() noexcept { static_assert(fiction::is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(fiction::has_sidb_technology_v, "Lyt is not an SiDB layout"); + static_assert(fiction::has_siqad_coord_v, "Lyt is not an SiDB layout"); Lyt lyt{}; @@ -1025,6 +1027,7 @@ Lyt crossing_bestagon_shape_input_down_output_up() noexcept { static_assert(fiction::is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(fiction::has_sidb_technology_v, "Lyt is not an SiDB layout"); + static_assert(fiction::has_siqad_coord_v, "Lyt is not an SiDB layout"); Lyt lyt{}; @@ -1083,6 +1086,7 @@ Lyt bestagon_and() noexcept { static_assert(fiction::is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(fiction::has_sidb_technology_v, "Lyt is not an SiDB layout"); + static_assert(fiction::has_siqad_coord_v, "Lyt is not an SiDB layout"); Lyt lyt{}; @@ -1133,6 +1137,7 @@ Lyt bestagon_fo2() noexcept { static_assert(fiction::is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(fiction::has_sidb_technology_v, "Lyt is not an SiDB layout"); + static_assert(fiction::has_siqad_coord_v, "Lyt is not an SiDB layout"); Lyt lyt{}; @@ -1180,6 +1185,7 @@ Lyt two_input_two_output_bestagon_skeleton() noexcept { static_assert(fiction::is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(fiction::has_sidb_technology_v, "Lyt is not an SiDB layout"); + static_assert(fiction::has_siqad_coord_v, "Lyt is not an SiDB layout"); Lyt lyt{}; @@ -1231,6 +1237,7 @@ Lyt two_input_two_output_bestagon_skeleton_input_down_output_up() noexcept { static_assert(fiction::is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(fiction::has_sidb_technology_v, "Lyt is not an SiDB layout"); + static_assert(fiction::has_siqad_coord_v, "Lyt is not an SiDB layout"); Lyt lyt{}; @@ -1284,6 +1291,7 @@ Lyt two_input_one_output_bestagon_skeleton() noexcept { static_assert(fiction::is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(fiction::has_sidb_technology_v, "Lyt is not an SiDB layout"); + static_assert(fiction::has_siqad_coord_v, "Lyt is not an SiDB layout"); Lyt lyt{}; @@ -1318,6 +1326,53 @@ Lyt two_input_one_output_bestagon_skeleton() noexcept return lyt; }; + +template +Lyt bestagon_xor() noexcept +{ + static_assert(fiction::is_cell_level_layout_v, "Lyt is not a cell-level layout"); + static_assert(fiction::has_sidb_technology_v, "Lyt is not an SiDB layout"); + static_assert(fiction::has_siqad_coord_v, "Lyt is not an SiDB layout"); + + Lyt lyt{}; + + // input wires + lyt.assign_cell_type({0, 0, 0}, Lyt::cell_type::INPUT); + lyt.assign_cell_type({38, 0, 0}, Lyt::cell_type::INPUT); + + lyt.assign_cell_type({2, 1, 0}, Lyt::cell_type::INPUT); + lyt.assign_cell_type({36, 1, 0}, Lyt::cell_type::INPUT); + + lyt.assign_cell_type({32, 2, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({6, 2, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({30, 3, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({8, 3, 0}, Lyt::cell_type::NORMAL); + + lyt.assign_cell_type({26, 4, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({12, 4, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({24, 5, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({14, 5, 0}, Lyt::cell_type::NORMAL); + + // canvas + lyt.assign_cell_type({15, 7, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({19, 8, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({17, 9, 1}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({20, 11, 0}, Lyt::cell_type::NORMAL); + + // output wire + lyt.assign_cell_type({19, 13, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({20, 14, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({24, 15, 0}, Lyt::cell_type::NORMAL); + lyt.assign_cell_type({26, 16, 0}, Lyt::cell_type::NORMAL); + + lyt.assign_cell_type({30, 17, 0}, Lyt::cell_type::OUTPUT); + lyt.assign_cell_type({32, 18, 0}, Lyt::cell_type::OUTPUT); + + lyt.assign_cell_type({36, 19, 0}, Lyt::cell_type::NORMAL); + + return lyt; +}; + /** * This layout represents an AND gate with the typical Bestagon skeleton. However, it shows kinks in the I/O pins for * certain input pattern. @@ -1327,6 +1382,7 @@ Lyt and_gate_with_kink_states() noexcept { static_assert(fiction::is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(fiction::has_sidb_technology_v, "Lyt is not an SiDB layout"); + static_assert(fiction::has_siqad_coord_v, "Lyt is not an SiDB layout"); Lyt lyt{}; @@ -1375,6 +1431,7 @@ Lyt two_input_left_one_output_right_top_skeleton() noexcept { static_assert(fiction::is_cell_level_layout_v, "Lyt is not a cell-level layout"); static_assert(fiction::has_sidb_technology_v, "Lyt is not an SiDB layout"); + static_assert(fiction::has_siqad_coord_v, "Lyt is not an SiDB layout"); Lyt lyt{};