Skip to content

Commit

Permalink
✨ Added is_operational to pyfiction
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelwa committed Nov 21, 2023
1 parent dfb3a8d commit 6551596
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//
// Created by marcel on 21.11.23.
//

#ifndef PYFICTION_IS_OPERATIONAL_HPP
#define PYFICTION_IS_OPERATIONAL_HPP

#include "pyfiction/documentation.hpp"
#include "pyfiction/types.hpp"

#include <fiction/algorithms/simulation/sidb/is_operational.hpp>

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

namespace pyfiction
{

namespace detail
{

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

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

} // namespace detail

inline void is_operational(pybind11::module& m)
{
namespace py = pybind11;

py::enum_<fiction::operational_status>(m, "operational_status", DOC(fiction_operational_status))
.value("OPERATIONAL", fiction::operational_status::OPERATIONAL, DOC(fiction_operational_status_OPERATIONAL))
.value("NON_OPERATIONAL", fiction::operational_status::NON_OPERATIONAL,
DOC(fiction_operational_status_NON_OPERATIONAL))

;

py::class_<fiction::is_operational_params>(m, "is_operational_params", DOC(fiction_is_operational_params))
.def(py::init<>())
.def_readwrite("sim_params", &fiction::is_operational_params::sim_params,
DOC(fiction_is_operational_params_simulation_parameter))
.def_readwrite("sim_engine", &fiction::is_operational_params::sim_engine,
DOC(fiction_is_operational_params_sim_engine))
.def_readwrite("bdl_params", &fiction::is_operational_params::bdl_params,
DOC(fiction_is_operational_params_bdl_params))

;

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

} // namespace pyfiction

#endif // PYFICTION_IS_OPERATIONAL_HPP
2 changes: 2 additions & 0 deletions bindings/pyfiction/pyfiction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "pyfiction/algorithms/simulation/sidb/energy_distribution.hpp"
#include "pyfiction/algorithms/simulation/sidb/exhaustive_ground_state_simulation.hpp"
#include "pyfiction/algorithms/simulation/sidb/is_ground_state.hpp"
#include "pyfiction/algorithms/simulation/sidb/is_operational.hpp"
#include "pyfiction/algorithms/simulation/sidb/minimum_energy.hpp"
#include "pyfiction/algorithms/simulation/sidb/occupation_probability_of_excited_states.hpp"
#include "pyfiction/algorithms/simulation/sidb/quicksim.hpp"
Expand Down Expand Up @@ -96,6 +97,7 @@ PYBIND11_MODULE(pyfiction, m)
pyfiction::sidb_simulation_result(m);
pyfiction::can_positive_charges_occur(m);
pyfiction::detect_bdl_pairs(m);
pyfiction::is_operational(m);
pyfiction::exhaustive_ground_state_simulation(m);
pyfiction::quicksim(m);
pyfiction::is_ground_state(m);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from fiction.pyfiction import *
import unittest
import os


class TestIsOperational(unittest.TestCase):

def test_is_operational(self):
lyt = sidb_layout((7, 0))

lyt = charge_distribution_surface(lyt)

lyt.assign_cell_type((0, 0, 1), sidb_technology.cell_type.INPUT)
lyt.assign_cell_type((2, 1, 1), sidb_technology.cell_type.INPUT)

lyt.assign_cell_type((20, 0, 1), sidb_technology.cell_type.INPUT)
lyt.assign_cell_type((19, 1, 1), sidb_technology.cell_type.INPUT)

lyt.assign_cell_type((4, 2, 1), sidb_technology.cell_type.NORMAL)
lyt.assign_cell_type((6, 3, 1), sidb_technology.cell_type.NORMAL)

lyt.assign_cell_type((14, 3, 1), sidb_technology.cell_type.NORMAL)
lyt.assign_cell_type((16, 2, 1), sidb_technology.cell_type.NORMAL)

lyt.assign_cell_type((10, 6, 0), sidb_technology.cell_type.OUTPUT)
lyt.assign_cell_type((10, 7, 0), sidb_technology.cell_type.OUTPUT)

lyt.assign_cell_type((10, 9, 1), sidb_technology.cell_type.NORMAL)

params = is_operational_params()
params.sim_params = sidb_simulation_parameters(2, -0.28)

[op_status, evaluated_input_combinations] = is_operational(lyt, [create_and_tt()], params)

self.assertEqual(op_status, operational_status.OPERATIONAL)

params.sim_params = sidb_simulation_parameters(2, -0.1)

[op_status, evaluated_input_combinations] = is_operational(lyt, [create_and_tt()], params)

self.assertEqual(op_status, operational_status.NON_OPERATIONAL)


if __name__ == '__main__':
unittest.main()

0 comments on commit 6551596

Please sign in to comment.