Skip to content

Commit

Permalink
✨ Added QuickExact to pyfiction
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelwa committed Nov 21, 2023
1 parent 426d591 commit 8360980
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -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 <fiction/algorithms/simulation/sidb/quickexact.hpp>

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

namespace pyfiction
{

namespace detail
{

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

py::enum_<typename fiction::quickexact_params<Lyt>::automatic_base_number_detection>(
m, "automatic_base_number_detection")
.value("ON", fiction::quickexact_params<Lyt>::automatic_base_number_detection::ON)
.value("OFF", fiction::quickexact_params<Lyt>::automatic_base_number_detection::OFF)

;

/**
* QuickExact parameters.
*/
py::class_<fiction::quickexact_params<Lyt>>(m, "quickexact_params", DOC(fiction_quickexact_params))
.def(py::init<>())
.def_readwrite("physical_parameters", &fiction::quickexact_params<Lyt>::physical_parameters,
DOC(fiction_quickexact_params_physical_parameters))
.def_readwrite("base_number_detection", &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,
DOC(fiction_quickexact_params_local_external_potential))
.def_readwrite("global_potential", &fiction::quickexact_params<Lyt>::global_potential,
DOC(fiction_quickexact_params_global_potential))

;

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));
}

} // 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<py_charge_distribution_surface>(m);
}

} // namespace pyfiction

#endif // PYFICTION_QUICKEXACT_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ void quicksim(pybind11::module& m)

m.def(
"quicksim",
[](const Lyt& layout, const fiction::quicksim_params& params) -> fiction::sidb_simulation_result<py_cds_base>
{ return fiction::quicksim<py_cds_base>(layout, params); },
"layout"_a, "params"_a = fiction::quicksim_params{}, DOC(fiction_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));
}

} // namespace detail
Expand Down
2 changes: 2 additions & 0 deletions bindings/pyfiction/pyfiction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand Down
33 changes: 17 additions & 16 deletions include/fiction/algorithms/simulation/sidb/quickexact.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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,
Expand All @@ -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<cell<Lyt>, double> local_external_potential = {};
/**
Expand Down Expand Up @@ -248,6 +235,20 @@ class quickexact_impl
* Simulation results.
*/
sidb_simulation_result<Lyt> 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.
Expand Down

0 comments on commit 8360980

Please sign in to comment.