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/Parity.py.hpp" 11 : #include "./enums/TransformationType.py.hpp" 12 : #include "./interfaces/DiagonalizerInterface.py.hpp" 13 : #include "./interfaces/TransformationBuilderInterface.py.hpp" 14 : #include "./ket/Ket.py.hpp" 15 : #include "./paths.py.hpp" 16 : #include "./system/System.py.hpp" 17 : #include "./tools/run_unit_tests.py.hpp" 18 : #include "./version.py.hpp" 19 : #include "pairinteraction/utils/TaskControl.hpp" 20 : 21 : #include <nanobind/nanobind.h> 22 : #include <nanobind/stl/string.h> 23 : #include <nanobind/stl/vector.h> 24 : 25 : namespace nb = nanobind; 26 : 27 8 : NB_MODULE(_backend, m) // NOLINT 28 : { 29 : // https://nanobind.readthedocs.io/en/latest/faq.html#why-am-i-getting-errors-about-leaked-functions-and-types 30 2 : nb::set_leak_warnings(false); 31 : 32 : // wrap the get_pending_logs method of the logger bridge instance 33 2 : static LoggerBridge bridge; 34 2 : nb::class_<LoggerBridge::LogEntry>(m, "LogEntry") 35 2 : .def_ro("level", &LoggerBridge::LogEntry::level) 36 1805 : .def_prop_ro("message", [](const LoggerBridge::LogEntry &e) { 37 1803 : return nb::bytes(e.message.data(), e.message.size()); 38 : }); 39 56960 : m.def("get_pending_logs", []() { return bridge.get_pending_logs(); }); 40 : 41 : // wrap task control functions 42 : static nb::exception<pairinteraction::TaskAbortedError> task_aborted_error(m, 43 2 : "TaskAbortedError"); 44 2 : m.def("request_task_abort", &pairinteraction::request_task_abort); 45 2 : m.def("reset_task_status", &pairinteraction::reset_task_status); 46 2 : m.def("get_task_info", &pairinteraction::get_task_info); 47 2 : m.def("get_progress_count", &pairinteraction::get_progress_count); 48 : 49 : // enums 50 2 : bind_operator_type(m); 51 2 : bind_parity(m); 52 2 : bind_transformation_type(m); 53 2 : bind_float_type(m); 54 : 55 : // interfaces 56 2 : bind_diagonalizer_interface(m); 57 2 : bind_transformation_builder_interface(m); 58 : 59 : // database 60 2 : bind_database(m); 61 : 62 : // diagonalizer 63 2 : bind_diagonalizer(m); 64 : 65 : // ket 66 2 : bind_ket(m); 67 : 68 : // basis 69 2 : bind_basis(m); 70 : 71 : // system 72 2 : bind_system(m); 73 : 74 : // tools 75 2 : bind_run_unit_tests(m); 76 : 77 : // paths 78 2 : bind_paths(m); 79 : 80 : // version 81 2 : bind_version(m); 82 2 : }