-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
bindings/pyfiction/include/pyfiction/algorithms/simulation/sidb/is_operational.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
bindings/pyfiction/test/algorithms/simulation/sidb/test_is_operational.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |