Skip to content

Commit

Permalink
🎨 first working version with Si-lattice support.
Browse files Browse the repository at this point in the history
  • Loading branch information
Drewniok committed Apr 10, 2024
1 parent 3b5742f commit a061efe
Show file tree
Hide file tree
Showing 26 changed files with 675 additions and 245 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ 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_sidb_100_lattice>(m);
detail::exhaustive_ground_state_simulation<py_sidb_111_lattice>(m);
// detail::exhaustive_ground_state_simulation<py_sidb_100_lattice>(m);
// detail::exhaustive_ground_state_simulation<py_sidb_111_lattice>(m);
detail::exhaustive_ground_state_simulation<py_sidb_layout>(m);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,20 @@
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

#include <string>

namespace pyfiction
{

namespace detail
{

template <typename Lyt>
void is_operational(pybind11::module& m)
void is_operational(pybind11::module& m, const std::string lattice = "")
{
using namespace pybind11::literals;

m.def("is_operational", &fiction::is_operational<Lyt, py_tt>, "lyt"_a, "spec"_a,
m.def(fmt::format("is_operational{}", lattice).c_str(), &fiction::is_operational<Lyt, py_tt>, "lyt"_a, "spec"_a,
"params"_a = fiction::is_operational_params{}, DOC(fiction_is_operational));
}

Expand Down Expand Up @@ -54,7 +56,9 @@ inline void is_operational(pybind11::module& m)

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

detail::is_operational<py_charge_distribution_surface>(m);
detail::is_operational<py_sidb_100_lattice>(m, "_100");
detail::is_operational<py_sidb_111_lattice>(m, "_111");
detail::is_operational<py_sidb_layout>(m);
}

} // namespace pyfiction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,23 @@
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

#include <string>

namespace pyfiction
{

namespace detail
{

template <typename Lyt>
void quickexact(pybind11::module& m)
void quickexact(pybind11::module& m, const std::string& lattice = "")
{
namespace py = pybind11;
using namespace pybind11::literals;

py::enum_<typename fiction::quickexact_params<Lyt>::automatic_base_number_detection>(
m, "automatic_base_number_detection", DOC(fiction_quickexact_params_automatic_base_number_detection))
m, fmt::format("automatic_base_number_detection{}", lattice).c_str(),
DOC(fiction_quickexact_params_automatic_base_number_detection))
.value("ON", fiction::quickexact_params<Lyt>::automatic_base_number_detection::ON,
DOC(fiction_quickexact_params_automatic_base_number_detection_ON))
.value("OFF", fiction::quickexact_params<Lyt>::automatic_base_number_detection::OFF,
Expand All @@ -37,21 +40,26 @@ void quickexact(pybind11::module& m)
/**
* QuickExact parameters.
*/
py::class_<fiction::quickexact_params<Lyt>>(m, "quickexact_params", DOC(fiction_quickexact_params))
py::class_<fiction::quickexact_params<Lyt>>(m, fmt::format("quickexact_params{}", lattice).c_str(),
DOC(fiction_quickexact_params))
.def(py::init<>())
.def_readwrite("simulation_parameters", &fiction::quickexact_params<Lyt>::simulation_parameters,
.def_readwrite(fmt::format("simulation_parameters{}", lattice).c_str(),
&fiction::quickexact_params<Lyt>::simulation_parameters,
DOC(fiction_quickexact_params_physical_parameters))
.def_readwrite("base_number_detection", &fiction::quickexact_params<Lyt>::base_number_detection,
.def_readwrite(fmt::format("base_number_detection{}", lattice).c_str(),
&fiction::quickexact_params<Lyt>::base_number_detection,
DOC(fiction_quickexact_params_base_number_detection))
.def_readwrite("local_external_potential", &fiction::quickexact_params<Lyt>::local_external_potential,
.def_readwrite(fmt::format("local_external_potential{}", lattice).c_str(),
&fiction::quickexact_params<Lyt>::local_external_potential,
DOC(fiction_quickexact_params_local_external_potential))
.def_readwrite("global_potential", &fiction::quickexact_params<Lyt>::global_potential,
.def_readwrite(fmt::format("global_potential{}", lattice).c_str(),
&fiction::quickexact_params<Lyt>::global_potential,
DOC(fiction_quickexact_params_global_potential))

;

m.def("quickexact", &fiction::quickexact<Lyt>, "lyt"_a, "params"_a = fiction::quickexact_params<Lyt>{},
DOC(fiction_quickexact));
m.def(fmt::format("quickexact{}", lattice).c_str(), &fiction::quickexact<Lyt>, "lyt"_a,
"params"_a = fiction::quickexact_params<Lyt>{}, DOC(fiction_quickexact));
}

} // namespace detail
Expand All @@ -60,8 +68,8 @@ 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_sidb_100_lattice>(m);
// detail::quickexact<py_sidb_111_lattice>(m);
detail::quickexact<py_sidb_100_lattice>(m, "_100");
detail::quickexact<py_sidb_111_lattice>(m, "_111");
detail::quickexact<py_sidb_layout>(m);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,21 @@
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

#include <string>

namespace pyfiction
{

namespace detail
{

template <typename Lyt>
void quicksim(pybind11::module& m)
void quicksim(pybind11::module& m, const std::string& lattice = "")
{
using namespace pybind11::literals;

m.def("quicksim", &fiction::quicksim<Lyt>, "lyt"_a, "params"_a = fiction::quicksim_params{}, DOC(fiction_quicksim));
m.def(fmt::format("quicksim{}", lattice).c_str(), &fiction::quicksim<Lyt>, "lyt"_a,
"params"_a = fiction::quicksim_params{}, DOC(fiction_quicksim));
}

} // namespace detail
Expand All @@ -49,8 +52,8 @@ 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_sidb_100_lattice>(m);
detail::quicksim<py_sidb_111_lattice>(m);
detail::quicksim<py_sidb_100_lattice>(m, "_100");
detail::quicksim<py_sidb_111_lattice>(m, "_111");
detail::quicksim<py_sidb_layout>(m);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace detail
{

template <typename Lyt>
void sidb_simulation_result(pybind11::module& m)
void sidb_simulation_result(pybind11::module& m, const std::string = "")
{
namespace py = pybind11;
using namespace pybind11::literals;
Expand All @@ -48,7 +48,6 @@ void sidb_simulation_result(pybind11::module& m)
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_sidb_layout>(m);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ namespace detail
{

template <typename Lyt>
void time_to_solution(pybind11::module& m)
void time_to_solution(pybind11::module& m, const std::string lattice = "")
{
using namespace pybind11::literals;

m.def("time_to_solution", &fiction::time_to_solution<Lyt>, "lyt"_a, "quickim_params"_a,
"tts_params"_a = fiction::time_to_solution_params{}, "ps"_a = nullptr, DOC(fiction_time_to_solution));
m.def(fmt::format("time_to_solution{}", lattice).c_str(), &fiction::time_to_solution<Lyt>, "lyt"_a,
"quickim_params"_a, "tts_params"_a = fiction::time_to_solution_params{}, "ps"_a = nullptr, DOC(fiction_time_to_solution));
}

} // namespace detail
Expand Down Expand Up @@ -67,6 +67,8 @@ inline void time_to_solution(pybind11::module& m)

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

detail::time_to_solution<py_sidb_100_lattice>(m, "_100");
detail::time_to_solution<py_sidb_111_lattice>(m, "_111");
detail::time_to_solution<py_sidb_layout>(m);
}

Expand Down
12 changes: 10 additions & 2 deletions bindings/pyfiction/include/pyfiction/inout/read_sqd_layout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,16 @@ 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<Lyt>;

m.def("read_sqd_layout", read_sqd_layout_function_pointer, "filename"_a, "layout_name"_a = "",
DOC(fiction_read_sqd_layout_3));
if constexpr (fiction::is_sidb_lattice_100_v<Lyt>)
{
m.def("read_sqd_layout_100", read_sqd_layout_function_pointer, "filename"_a, "layout_name"_a = "",
DOC(fiction_read_sqd_layout_3));
}
else
{
m.def("read_sqd_layout_111", read_sqd_layout_function_pointer, "filename"_a, "layout_name"_a = "",
DOC(fiction_read_sqd_layout_3));
}
}

} // namespace detail
Expand Down
15 changes: 3 additions & 12 deletions bindings/pyfiction/include/pyfiction/layouts/sidb_lattice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,16 @@ void sidb_lattice_cell_level_layout(pybind11::module& m)
// fetch technology name
auto orientation = std::string{fiction::sidb_lattice_name<LatticeOrientation>};
std::transform(orientation.begin(), orientation.end(), orientation.begin(), ::tolower);
std::cout << orientation << std::endl;

/**
* FCN cell technology.
*/
// const py::class_<LatticeOrientation> tech(m, fmt::format("{}_technology", orientation).c_str());

using py_sidb_lattice = py_sidb_lattice<LatticeOrientation>;

/**
* SiDB lattice.
*/
py::class_<py_sidb_lattice, fiction::cell_level_layout<fiction::sidb_technology,
fiction::clocked_layout<fiction::tile_based_layout<
fiction::cartesian_layout<fiction::offset::ucoord_t>>>>>(
m, fmt::format("{}_lattice", orientation).c_str(), DOC(fiction_cell_level_layout))
py::class_<py_sidb_lattice, py_sidb_layout>(m, fmt::format("sidb_lattice{}", orientation).c_str(),
DOC(fiction_cell_level_layout), py::module_local())
.def(py::init<>())
.def(py::init<const fiction::aspect_ratio<py_sidb_lattice>&, const std::string&>(), "dimension"_a,
"name"_a = "", DOC(fiction_cell_level_layout_cell_level_layout))
.def(py::init<const fiction::aspect_ratio<py_sidb_layout>&, const std::string&>(), "dimension"_a, "name"_a = "", DOC(fiction_cell_level_layout_cell_level_layout))

;
}
Expand Down
Loading

0 comments on commit a061efe

Please sign in to comment.