Skip to content

Commit

Permalink
🎨 Enable the usage of py_sidb_layout instead of py_charge_distributio…
Browse files Browse the repository at this point in the history
…n_surface in simulation algorithms
  • Loading branch information
marcelwa committed Dec 1, 2023
1 parent be72d9e commit 27e6513
Show file tree
Hide file tree
Showing 16 changed files with 114 additions and 220 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,50 +23,50 @@ namespace detail

template <typename Lyt>
void design_sidb_gates(pybind11::module& m)
{
using namespace pybind11::literals;

m.def("design_sidb_gates", &fiction::design_sidb_gates<Lyt, py_tt>, "skeleton"_a, "spec"_a,
"params"_a = fiction::design_sidb_gates_params{}, DOC(fiction_design_sidb_gates));
}

} // namespace detail

inline void design_sidb_gates(pybind11::module& m)
{
namespace py = pybind11;
using namespace py::literals;

/**
* Design approach selector type.
*/
pybind11::enum_<fiction::design_sidb_gates_params::design_sidb_gates_mode>(
pybind11::enum_<typename fiction::design_sidb_gates_params<Lyt>::design_sidb_gates_mode>(
m, "design_sidb_gates_mode", DOC(fiction_design_sidb_gates_params_design_sidb_gates_mode))
.value("EXHAUSTIVE", fiction::design_sidb_gates_params::design_sidb_gates_mode::EXHAUSTIVE,
.value("EXHAUSTIVE", fiction::design_sidb_gates_params<Lyt>::design_sidb_gates_mode::EXHAUSTIVE,
DOC(fiction_design_sidb_gates_params_design_sidb_gates_mode_EXHAUSTIVE))
.value("RANDOM", fiction::design_sidb_gates_params::design_sidb_gates_mode::RANDOM,
.value("RANDOM", fiction::design_sidb_gates_params<Lyt>::design_sidb_gates_mode::RANDOM,
DOC(fiction_design_sidb_gates_params_design_sidb_gates_mode_RANDOM))

;

/**
* Parameters.
*/
py::class_<fiction::design_sidb_gates_params>(m, "design_sidb_gates_params", DOC(fiction_design_sidb_gates_params))
py::class_<fiction::design_sidb_gates_params<Lyt>>(m, "design_sidb_gates_params",
DOC(fiction_design_sidb_gates_params))
.def(py::init<>())
.def_readwrite("phys_params", &fiction::design_sidb_gates_params::phys_params,
.def_readwrite("phys_params", &fiction::design_sidb_gates_params<Lyt>::phys_params,
DOC(fiction_design_sidb_gates_params_phys_params))
.def_readwrite("design_mode", &fiction::design_sidb_gates_params::design_mode,
.def_readwrite("design_mode", &fiction::design_sidb_gates_params<Lyt>::design_mode,
DOC(fiction_design_sidb_gates_params_design_mode))
.def_readwrite("canvas", &fiction::design_sidb_gates_params::canvas,
.def_readwrite("canvas", &fiction::design_sidb_gates_params<Lyt>::canvas,
DOC(fiction_design_sidb_gates_params_canvas))
.def_readwrite("number_of_sidbs", &fiction::design_sidb_gates_params::number_of_sidbs,
.def_readwrite("number_of_sidbs", &fiction::design_sidb_gates_params<Lyt>::number_of_sidbs,
DOC(fiction_design_sidb_gates_params_number_of_sidbs))
.def_readwrite("sim_engine", &fiction::design_sidb_gates_params::sim_engine,
.def_readwrite("sim_engine", &fiction::design_sidb_gates_params<Lyt>::sim_engine,
DOC(fiction_design_sidb_gates_params_sim_engine))

;

detail::design_sidb_gates<py_charge_distribution_surface>(m);
m.def("design_sidb_gates", &fiction::design_sidb_gates<Lyt, py_tt>, "skeleton"_a, "spec"_a,
"params"_a = fiction::design_sidb_gates_params<Lyt>{}, DOC(fiction_design_sidb_gates));
}

} // namespace detail

inline void design_sidb_gates(pybind11::module& m)
{
detail::design_sidb_gates<py_sidb_layout>(m);
}

} // namespace pyfiction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ inline void assess_physical_population_stability(pybind11::module& m)

// NOTE be careful with the order of the following calls! Python will resolve the first matching overload!

detail::assess_physical_population_stability<py_charge_distribution_surface>(m);
detail::assess_physical_population_stability<py_sidb_layout>(m);
}

} // namespace pyfiction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,8 @@ void exhaustive_ground_state_simulation(pybind11::module& m)
{
using namespace pybind11::literals;

m.def(
"exhaustive_ground_state_simulation",
[](const Lyt& lyt,
const fiction::sidb_simulation_parameters& params) -> fiction::sidb_simulation_result<py_cds_base>
{ return fiction::exhaustive_ground_state_simulation<py_cds_base>(lyt, params); },
"lyt"_a, "params"_a = fiction::sidb_simulation_parameters{}, DOC(fiction_exhaustive_ground_state_simulation));
m.def("exhaustive_ground_state_simulation", &fiction::exhaustive_ground_state_simulation<py_sidb_layout>, "lyt"_a,
"params"_a = fiction::sidb_simulation_parameters{}, DOC(fiction_exhaustive_ground_state_simulation));
}

} // namespace detail
Expand All @@ -38,7 +34,7 @@ inline void exhaustive_ground_state_simulation(pybind11::module& m)
{
// NOTE be careful with the order of the following calls! Python will resolve the first matching overload!

detail::exhaustive_ground_state_simulation<py_charge_distribution_surface>(m);
detail::exhaustive_ground_state_simulation<py_sidb_layout>(m);
}

} // namespace pyfiction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,8 @@ void quickexact(pybind11::module& m)

;

m.def(
"quickexact",
[](const Lyt& lyt,
const typename fiction::quickexact_params<Lyt>& params) -> fiction::sidb_simulation_result<py_cds_base>
{
fiction::quickexact_params<py_cds_base> converted_params{
params.physical_parameters,
params.base_number_detection == fiction::quickexact_params<Lyt>::automatic_base_number_detection::ON ?
fiction::quickexact_params<py_cds_base>::automatic_base_number_detection::ON :
fiction::quickexact_params<py_cds_base>::automatic_base_number_detection::OFF,
params.local_external_potential, params.global_potential};

return fiction::quickexact<py_cds_base>(lyt, converted_params);
},
"lyt"_a, "params"_a = fiction::quickexact_params<Lyt>{}, DOC(fiction_quickexact));
m.def("quickexact", &fiction::quickexact<Lyt>, "lyt"_a, "params"_a = fiction::quickexact_params<Lyt>{},
DOC(fiction_quickexact));
}

} // namespace detail
Expand All @@ -73,7 +60,7 @@ inline void quickexact(pybind11::module& m)
{
// NOTE be careful with the order of the following calls! Python will resolve the first matching overload!

detail::quickexact<py_charge_distribution_surface>(m);
detail::quickexact<py_sidb_layout>(m);
}

} // namespace pyfiction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ void quicksim(pybind11::module& m)
{
using namespace pybind11::literals;

m.def(
"quicksim",
[](const Lyt& lyt, const fiction::quicksim_params& params) -> fiction::sidb_simulation_result<py_cds_base>
{ return fiction::quicksim<py_cds_base>(lyt, params); },
"lyt"_a, "params"_a = fiction::quicksim_params{}, DOC(fiction_quicksim));
m.def("quicksim", &fiction::quicksim<Lyt>, "lyt"_a, "params"_a = fiction::quicksim_params{}, DOC(fiction_quicksim));
}

} // namespace detail
Expand All @@ -53,7 +49,7 @@ inline void quicksim(pybind11::module& m)

// NOTE be careful with the order of the following calls! Python will resolve the first matching overload!

detail::quicksim<py_charge_distribution_surface>(m);
detail::quicksim<py_sidb_layout>(m);
}

} // namespace pyfiction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ inline void random_sidb_layout_generator(pybind11::module& m)
{
// NOTE be careful with the order of the following calls! Python will resolve the first matching overload!

detail::random_sidb_layout_generator<py_charge_distribution_surface>(m);
detail::random_sidb_layout_generator<py_sidb_layout>(m);
}

} // namespace pyfiction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ inline void sidb_simulation_result(pybind11::module& m)
{
// NOTE be careful with the order of the following calls! Python will resolve the first matching overload!

detail::sidb_simulation_result<py_cds_base>(m);
detail::sidb_simulation_result<py_sidb_layout>(m);
}

} // namespace pyfiction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
#include "pyfiction/types.hpp"

#include <fiction/io/write_location_and_ground_state.hpp>
#include <fiction/utils/layout_utils.hpp>

#include <string_view>

#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

namespace pyfiction
{
Expand All @@ -27,16 +29,16 @@ void write_location_and_ground_state(pybind11::module& m)

m.def(
"write_location_and_ground_state",
[](const fiction::sidb_simulation_result<Lyt>& lyt, const std::string_view& filename)
{ fiction::write_location_and_ground_state(lyt, filename); },
"layout"_a, "filename"_a, DOC(fiction_write_location_and_ground_state));
[](const fiction::sidb_simulation_result<Lyt>& sim_result, const std::string_view& filename)
{ fiction::write_location_and_ground_state(sim_result, filename); },
"sim_result"_a, "filename"_a, DOC(fiction_write_location_and_ground_state));
}

} // namespace detail

inline void write_location_and_ground_state(pybind11::module& m)
{
detail::write_location_and_ground_state<py_cds_base>(m);
detail::write_location_and_ground_state<py_sidb_layout>(m);
}

} // namespace pyfiction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void write_sqd_sim_result(pybind11::module& m)

inline void write_sqd_sim_result(pybind11::module& m)
{
detail::write_sqd_sim_result<py_cds_base>(m);
detail::write_sqd_sim_result<py_sidb_layout>(m);
}

} // namespace pyfiction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,96 +65,18 @@ inline void charge_distribution_surface(pybind11::module& m)

/**
* Charge distribution surface.
*
* @note The charge_distribution_type in pyfiction must be viewed as a stand-alone type. It does not inherit from
* any other existing pyfiction types. Therefore, it does not implement functions of lower level layout types.
*/
py::class_<py_charge_distribution_surface>(m, "charge_distribution_surface",
DOC(fiction_charge_distribution_surface))
py::class_<py_charge_distribution_surface, py_sidb_layout>(m, "charge_distribution_surface",
DOC(fiction_charge_distribution_surface))
.def(py::init<const fiction::sidb_simulation_parameters&, const fiction::sidb_charge_state&>(),
"params"_a = fiction::sidb_simulation_parameters{}, "cs"_a = fiction::sidb_charge_state::NEGATIVE)

.def(py::init<const py_cds_base&, const fiction::sidb_simulation_parameters&,
.def(py::init<const py_sidb_layout&, const fiction::sidb_simulation_parameters&,
const fiction::sidb_charge_state&>(),
"lyt"_a, "params"_a = fiction::sidb_simulation_parameters{}, "cs"_a = fiction::sidb_charge_state::NEGATIVE)

.def(py::init<const py_charge_distribution_surface&>(), "lyt"_a)

.def(py::init(
[](const py_sidb_layout& layout,
const fiction::sidb_simulation_parameters& params = fiction::sidb_simulation_parameters{},
const fiction::sidb_charge_state& cs = fiction::sidb_charge_state::NEGATIVE)
{
auto converted_layout = fiction::convert_to_siqad_coordinates(layout);
return fiction::charge_distribution_surface(converted_layout, params, cs);
}),
"layout"_a, "params"_a = fiction::sidb_simulation_parameters{},
"cs"_a = fiction::sidb_charge_state::NEGATIVE)

.def(
"x", [](const py_charge_distribution_surface& lyt) { return lyt.x(); }, DOC(fiction_cartesian_layout_x))
.def(
"y", [](const py_charge_distribution_surface& lyt) { return lyt.y(); }, DOC(fiction_cartesian_layout_y))
.def(
"z", [](const py_charge_distribution_surface& lyt) { return lyt.z(); }, DOC(fiction_cartesian_layout_z))
.def(
"area", [](const py_charge_distribution_surface& lyt) { return lyt.area(); },
DOC(fiction_cartesian_layout_area))
.def(
"resize",
[](py_charge_distribution_surface& lyt, const py_siqad_coordinate& dimension) { lyt.resize(dimension); },
"dimension"_a, DOC(fiction_cartesian_layout_resize))

.def(
"get_cell_type",
[](const py_charge_distribution_surface& lyt, const fiction::cell<py_charge_distribution_surface>& c)
{ return lyt.get_cell_type(c); },
"c"_a, DOC(fiction_cell_level_layout_get_cell_type))
.def(
"is_empty_cell",
[](const py_charge_distribution_surface& lyt, const fiction::cell<py_charge_distribution_surface>& c)
{ return lyt.is_empty_cell(c); },
"c"_a, DOC(fiction_cell_level_layout_is_empty_cell))
.def(
"assign_cell_name",
[](py_charge_distribution_surface& lyt, const fiction::cell<py_charge_distribution_surface>& c,
const std::string& n) { lyt.assign_cell_name(c, n); },
"c"_a, "n"_a, DOC(fiction_cell_level_layout_assign_cell_name))
.def(
"get_cell_name",
[](const py_charge_distribution_surface& lyt, const fiction::cell<py_charge_distribution_surface>& c)
{ return lyt.get_cell_name(c); },
"c"_a, DOC(fiction_cell_level_layout_get_cell_name))
.def(
"set_layout_name",
[](py_charge_distribution_surface& lyt, const std::string& name) { lyt.set_layout_name(name); }, "name"_a,
DOC(fiction_cell_level_layout_set_layout_name))
.def(
"get_layout_name", [](const py_charge_distribution_surface& lyt) { return lyt.get_layout_name(); },
DOC(fiction_cell_level_layout_get_layout_name))
.def(
"num_cells", [](const py_charge_distribution_surface& lyt) { return lyt.num_cells(); },
DOC(fiction_cell_level_layout_num_cells))
.def(
"is_empty", [](const py_charge_distribution_surface& lyt) { return lyt.is_empty(); },
DOC(fiction_cell_level_layout_is_empty))
.def(
"num_pis", [](const py_charge_distribution_surface& lyt) { return lyt.num_pis(); },
DOC(fiction_cell_level_layout_num_pis))
.def(
"num_pos", [](const py_charge_distribution_surface& lyt) { return lyt.num_pos(); },
DOC(fiction_cell_level_layout_num_pos))
.def(
"is_pi",
[](const py_charge_distribution_surface& lyt, const fiction::cell<py_charge_distribution_surface>& c)
{ return lyt.is_pi(c); },
"c"_a, DOC(fiction_cell_level_layout_is_pi))
.def(
"is_po",
[](const py_charge_distribution_surface& lyt, const fiction::cell<py_charge_distribution_surface>& c)
{ return lyt.is_po(c); },
"c"_a, DOC(fiction_cell_level_layout_is_po))

.def("get_all_sidb_locations_in_nm", &py_charge_distribution_surface::get_all_sidb_locations_in_nm)
.def("assign_cell_type", &py_charge_distribution_surface::assign_cell_type, "c"_a, "ct"_a)
.def("assign_physical_parameters", &py_charge_distribution_surface::assign_physical_parameters, "params"_a)
Expand Down Expand Up @@ -290,7 +212,7 @@ inline void charge_distribution_surface(pybind11::module& m)

.def(
"is_within_bounds",
[](const py_charge_distribution_surface& lyt, const py_siqad_coordinate& c)
[](const py_charge_distribution_surface& lyt, const fiction::coordinate<py_charge_distribution_surface>& c)
{ return lyt.is_within_bounds(c); },
"c"_a, DOC(fiction_cartesian_layout_is_within_bounds))

Expand All @@ -307,7 +229,7 @@ inline void charge_distribution_surface(pybind11::module& m)
[](const py_charge_distribution_surface& lyt)
{
std::stringstream ss;
print_layout(lyt, ss);
print_layout(fiction::convert_to_siqad_coordinates(lyt), ss);
return ss.str();
})

Expand Down
13 changes: 2 additions & 11 deletions bindings/pyfiction/include/pyfiction/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,9 @@ using py_inml_layout = py_cartesian_cell_layout<fiction::inml_technology>;
using py_sidb_layout = py_cartesian_cell_layout<fiction::sidb_technology>;
/**
* Charge distribution surface. This is a special SiDB cell-level layout that is used for the SiDB simulation
* algorithms. It is based on SiQAD coordinates.
* algorithms.
*/
using py_charge_distribution_surface = fiction::charge_distribution_surface<fiction::cell_level_layout<
fiction::sidb_technology, fiction::clocked_layout<fiction::cartesian_layout<fiction::siqad::coord_t>>>>;
/**
* The base type of py_charge_distribution_surface to prevent double inference of charge_distribution_surface in the
* template parameter of many functions, which would yield a type not registered in pyfiction. This type is not
* explicitly exposed. Don't use it on its own elsewhere unless you know what you are doing.
*/
using py_cds_base =
fiction::cell_level_layout<fiction::sidb_technology,
fiction::clocked_layout<fiction::cartesian_layout<fiction::siqad::coord_t>>>;
using py_charge_distribution_surface = fiction::charge_distribution_surface<py_sidb_layout>;

} // namespace pyfiction

Expand Down
Loading

0 comments on commit 27e6513

Please sign in to comment.