Skip to content

Commit

Permalink
🐍 fix python bindings.
Browse files Browse the repository at this point in the history
  • Loading branch information
Drewniok committed Nov 1, 2024
1 parent d761ae0 commit f3fedf1
Show file tree
Hide file tree
Showing 19 changed files with 360 additions and 379 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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 <fiction/algorithms/simulation/sidb/defect_influence_operational_domain.hpp>

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

#include <vector>

namespace pyfiction
{

namespace detail
{

template <typename Lyt>
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, py_tt>, "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, py_tt>, "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, py_tt>, "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_<fiction::defect_operational_domain<py_sidb_100_lattice>>(
m, "defect_operational_domain_100")
.def(py::init<>());

py::class_<fiction::defect_operational_domain<py_sidb_111_lattice>>(
m, "defect_operational_domain_111")
.def(py::init<>());

py::class_<fiction::defect_operational_domain<py_sidb_100_lattice_cube>>(
m, "defect_operational_domain_100_cube")
.def(py::init<>());

py::class_<fiction::defect_operational_domain<py_sidb_111_lattice_cube>>(
m, "defect_operational_domain_111_cube")
.def(py::init<>());

py::class_<fiction::defect_operational_domain_params>(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_<fiction::defect_operational_domain_stats>(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<py_sidb_100_lattice_cube>(m);
detail::defect_influence_operational_domain_detail<py_sidb_111_lattice_cube>(m);
}

} // namespace pyfiction

#endif // PYFICTION_DEFECT_INFLUENCE_OPERATIONAL_DOMAIN_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,16 @@ inline void determine_physically_valid_parameters(pybind11::module& m)
[](const fiction::operational_domain<fiction::parameter_point, uint64_t>& 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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!

Expand Down
46 changes: 8 additions & 38 deletions bindings/pyfiction/include/pyfiction/inout/read_sqd_layout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace detail
{

template <typename Lyt>
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;
Expand All @@ -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<Lyt>;

if constexpr (fiction::is_sidb_lattice_100_v<Lyt> && fiction::has_cube_coord_v<Lyt>)
{
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<Lyt> && !fiction::has_cube_coord_v<Lyt>)
{
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<Lyt> && fiction::has_cube_coord_v<Lyt>)
{
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<Lyt> && !fiction::has_cube_coord_v<Lyt>)
{
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<py_sidb_100_lattice>(m);
}

inline void read_sqd_layout_111(pybind11::module& m)
{
detail::read_sqd_layout<py_sidb_111_lattice>(m);
}

inline void read_sqd_layout_100_cube(pybind11::module& m)
{
detail::read_sqd_layout<py_sidb_100_lattice_cube>(m);
}

inline void read_sqd_layout_111_cube(pybind11::module& m)
{
detail::read_sqd_layout<py_sidb_111_lattice_cube>(m);
detail::read_sqd_layout<py_sidb_100_lattice>(m, "100", "");
detail::read_sqd_layout<py_sidb_111_lattice>(m, "111", "");
detail::read_sqd_layout<py_sidb_100_lattice_cube>(m, "100", "_cube");
detail::read_sqd_layout<py_sidb_111_lattice_cube>(m, "111", "_cube");
}

} // namespace pyfiction
Expand Down
Loading

0 comments on commit f3fedf1

Please sign in to comment.