Line data Source code
1 : // SPDX-FileCopyrightText: 2024 PairInteraction Developers 2 : // SPDX-License-Identifier: LGPL-3.0-or-later 3 : 4 : #include "./LoggerBridge.hpp" 5 : #include "./basis/Basis.py.hpp" 6 : #include "./database/Database.py.hpp" 7 : #include "./diagonalize/Diagonalizer.py.hpp" 8 : #include "./enums/FloatType.py.hpp" 9 : #include "./enums/OperatorType.py.hpp" 10 : #include "./enums/SorterType.py.hpp" 11 : #include "./interfaces/DiagonalizerInterface.py.hpp" 12 : #include "./interfaces/SorterBuilderInterface.py.hpp" 13 : #include "./ket/Ket.py.hpp" 14 : #include "./paths.py.hpp" 15 : #include "./system/System.py.hpp" 16 : #include "./tools/run_unit_tests.py.hpp" 17 : #include "./version.py.hpp" 18 : #include "pairinteraction/utils/TaskControl.hpp" 19 : 20 : #include <nanobind/nanobind.h> 21 : #include <nanobind/stl/string.h> 22 : #include <nanobind/stl/vector.h> 23 : 24 : namespace nb = nanobind; 25 : 26 10 : NB_MODULE(_backend, m) // NOLINT 27 : { 28 : // https://nanobind.readthedocs.io/en/latest/faq.html#why-am-i-getting-errors-about-leaked-functions-and-types 29 2 : nb::set_leak_warnings(false); 30 : 31 : // wrap the get_pending_logs method of the logger bridge instance 32 2 : static LoggerBridge bridge; 33 2 : nb::class_<LoggerBridge::LogEntry>(m, "LogEntry") 34 2 : .def_ro("level", &LoggerBridge::LogEntry::level) 35 2100 : .def_prop_ro("message", [](const LoggerBridge::LogEntry &e) { 36 2098 : return nb::bytes(e.message.data(), e.message.size()); 37 : }); 38 2353287 : m.def("get_pending_logs", []() { return bridge.get_pending_logs(); }); 39 : 40 : // wrap task control functions 41 : static nb::exception<pairinteraction::TaskAbortedError> task_aborted_error(m, 42 2 : "TaskAbortedError"); 43 2 : m.def("request_task_abort", &pairinteraction::request_task_abort); 44 2 : m.def("reset_task_status", &pairinteraction::reset_task_status); 45 2 : m.def("get_task_info", &pairinteraction::get_task_info); 46 2 : m.def("get_progress_count", &pairinteraction::get_progress_count); 47 : 48 : // enums 49 2 : bind_operator_type(m); 50 2 : bind_sorter_type(m); 51 2 : bind_float_type(m); 52 : 53 : // interfaces 54 2 : bind_diagonalizer_interface(m); 55 2 : bind_sorter_builder_interface(m); 56 : 57 : // database 58 2 : bind_database(m); 59 : 60 : // diagonalizer 61 2 : bind_diagonalizer(m); 62 : 63 : // ket 64 2 : bind_ket(m); 65 : 66 : // basis 67 2 : bind_basis(m); 68 : 69 : // system 70 2 : bind_system(m); 71 : 72 : // tools 73 2 : bind_run_unit_tests(m); 74 : 75 : // paths 76 2 : bind_paths(m); 77 : 78 : // version 79 2 : bind_version(m); 80 2 : }