From 8360980b107b477f65b1f41d16f99f34598729c4 Mon Sep 17 00:00:00 2001 From: Marcel Walter Date: Tue, 21 Nov 2023 15:38:29 +0100 Subject: [PATCH] :sparkles: Added QuickExact to pyfiction --- .../algorithms/simulation/sidb/quickexact.hpp | 79 +++++++++++++++++++ .../algorithms/simulation/sidb/quicksim.hpp | 6 +- bindings/pyfiction/pyfiction.cpp | 2 + .../algorithms/simulation/sidb/quickexact.hpp | 33 ++++---- 4 files changed, 101 insertions(+), 19 deletions(-) create mode 100644 bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/quickexact.hpp diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/quickexact.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/quickexact.hpp new file mode 100644 index 000000000..343e4d14b --- /dev/null +++ b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/quickexact.hpp @@ -0,0 +1,79 @@ +// +// Created by marcel on 21.11.23. +// + +#ifndef PYFICTION_QUICKEXACT_HPP +#define PYFICTION_QUICKEXACT_HPP + +#include "pyfiction/documentation.hpp" +#include "pyfiction/types.hpp" + +#include + +#include +#include + +namespace pyfiction +{ + +namespace detail +{ + +template +void quickexact(pybind11::module& m) +{ + namespace py = pybind11; + using namespace pybind11::literals; + + py::enum_::automatic_base_number_detection>( + m, "automatic_base_number_detection") + .value("ON", fiction::quickexact_params::automatic_base_number_detection::ON) + .value("OFF", fiction::quickexact_params::automatic_base_number_detection::OFF) + + ; + + /** + * QuickExact parameters. + */ + py::class_>(m, "quickexact_params", DOC(fiction_quickexact_params)) + .def(py::init<>()) + .def_readwrite("physical_parameters", &fiction::quickexact_params::physical_parameters, + DOC(fiction_quickexact_params_physical_parameters)) + .def_readwrite("base_number_detection", &fiction::quickexact_params::base_number_detection, + DOC(fiction_quickexact_params_base_number_detection)) + .def_readwrite("local_external_potential", &fiction::quickexact_params::local_external_potential, + DOC(fiction_quickexact_params_local_external_potential)) + .def_readwrite("global_potential", &fiction::quickexact_params::global_potential, + DOC(fiction_quickexact_params_global_potential)) + + ; + + m.def( + "quickexact", + [](const Lyt& lyt, + const typename fiction::quickexact_params& params) -> fiction::sidb_simulation_result + { + fiction::quickexact_params converted_params{ + params.physical_parameters, + params.base_number_detection == fiction::quickexact_params::automatic_base_number_detection::ON ? + fiction::quickexact_params::automatic_base_number_detection::ON : + fiction::quickexact_params::automatic_base_number_detection::OFF, + params.local_external_potential, params.global_potential}; + + return fiction::quickexact(lyt, converted_params); + }, + "lyt"_a, "params"_a = fiction::quickexact_params{}, DOC(fiction_quickexact)); +} + +} // namespace detail + +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(m); +} + +} // namespace pyfiction + +#endif // PYFICTION_QUICKEXACT_HPP diff --git a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/quicksim.hpp b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/quicksim.hpp index 74e043e66..dbcd8e73a 100644 --- a/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/quicksim.hpp +++ b/bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/quicksim.hpp @@ -26,9 +26,9 @@ void quicksim(pybind11::module& m) m.def( "quicksim", - [](const Lyt& layout, const fiction::quicksim_params& params) -> fiction::sidb_simulation_result - { return fiction::quicksim(layout, params); }, - "layout"_a, "params"_a = fiction::quicksim_params{}, DOC(fiction_quicksim)); + [](const Lyt& lyt, const fiction::quicksim_params& params) -> fiction::sidb_simulation_result + { return fiction::quicksim(lyt, params); }, + "lyt"_a, "params"_a = fiction::quicksim_params{}, DOC(fiction_quicksim)); } } // namespace detail diff --git a/bindings/pyfiction/pyfiction.cpp b/bindings/pyfiction/pyfiction.cpp index f5c817152..590f138bb 100644 --- a/bindings/pyfiction/pyfiction.cpp +++ b/bindings/pyfiction/pyfiction.cpp @@ -31,6 +31,7 @@ #include "pyfiction/algorithms/simulation/sidb/minimum_energy.hpp" #include "pyfiction/algorithms/simulation/sidb/occupation_probability_of_excited_states.hpp" #include "pyfiction/algorithms/simulation/sidb/operational_domain.hpp" +#include "pyfiction/algorithms/simulation/sidb/quickexact.hpp" #include "pyfiction/algorithms/simulation/sidb/quicksim.hpp" #include "pyfiction/algorithms/simulation/sidb/sidb_charge_state.hpp" #include "pyfiction/algorithms/simulation/sidb/sidb_simulation_engine.hpp" @@ -104,6 +105,7 @@ PYBIND11_MODULE(pyfiction, m) // pyfiction::maximum_defect_influence_distance(m); pyfiction::exhaustive_ground_state_simulation(m); pyfiction::quicksim(m); + pyfiction::quickexact(m); pyfiction::is_ground_state(m); pyfiction::minimum_energy(m); pyfiction::energy_distribution(m); diff --git a/include/fiction/algorithms/simulation/sidb/quickexact.hpp b/include/fiction/algorithms/simulation/sidb/quickexact.hpp index 15fedafd8..a2b92ce81 100644 --- a/include/fiction/algorithms/simulation/sidb/quickexact.hpp +++ b/include/fiction/algorithms/simulation/sidb/quickexact.hpp @@ -24,20 +24,7 @@ namespace fiction { -/** - * Base number required for the correct physical simulation. - */ -enum class required_simulation_base_number -{ - /** - * Two state simulation (i.e., negative and neutral) is sufficient. - */ - TWO, - /** - * Three state simulation (i.e., negative, neutral, and positive) is required. - */ - THREE -}; + /** * This struct stores the parameters for the *QuickExact* algorithm. */ @@ -50,7 +37,7 @@ struct quickexact_params enum class automatic_base_number_detection { /** - * Simulation is conducted with the required base number (i.e, if positively charged SiDBs can occur, three + * Simulation is conducted with the required base number (i.e., if positively charged SiDBs can occur, three * state simulation is conducted). */ ON, @@ -69,7 +56,7 @@ struct quickexact_params */ automatic_base_number_detection base_number_detection = automatic_base_number_detection::ON; /** - * Local external electrostatic potentials (e.g locally applied electrodes). + * Local external electrostatic potentials (e.g., locally applied electrodes). */ std::unordered_map, double> local_external_potential = {}; /** @@ -248,6 +235,20 @@ class quickexact_impl * Simulation results. */ sidb_simulation_result result{}; + /** + * Base number required for the correct physical simulation. + */ + enum class required_simulation_base_number + { + /** + * Two state simulation (i.e., negative and neutral) is sufficient. + */ + TWO, + /** + * Three state simulation (i.e., negative, neutral, and positive) is required. + */ + THREE + }; /** * This function initializes the charge layout with necessary parameters, and conducts * the physical simulation based on whether a three-state simulation is required.