diff --git a/src/core/algorithms/algorithm.cpp b/src/core/algorithms/algorithm.cpp index 8146176a90..a007d074cf 100644 --- a/src/core/algorithms/algorithm.cpp +++ b/src/core/algorithms/algorithm.cpp @@ -127,5 +127,13 @@ std::type_index Algorithm::GetTypeIndex(std::string_view option_name) const { return it->second->GetTypeIndex(); } +std::unordered_set Algorithm::GetPossibleOptions() const { + std::unordered_set possible_options; + for (const auto& [key, _] : possible_options_) { + possible_options.insert(key); + } + return possible_options; +} + } // namespace algos diff --git a/src/core/algorithms/algorithm.h b/src/core/algorithms/algorithm.h index e3d8b324ce..6976771be6 100644 --- a/src/core/algorithms/algorithm.h +++ b/src/core/algorithms/algorithm.h @@ -102,6 +102,8 @@ class Algorithm { } std::type_index GetTypeIndex(std::string_view option_name) const; + + [[nodiscard]] std::unordered_set GetPossibleOptions() const; }; } // namespace algos diff --git a/src/python_bindings/bindings.cpp b/src/python_bindings/bindings.cpp index 5fb4b5edf7..081242aa6c 100644 --- a/src/python_bindings/bindings.cpp +++ b/src/python_bindings/bindings.cpp @@ -137,6 +137,8 @@ PYBIND11_MODULE(desbordante, module) { "Load data after all options have been set by SetOption calls") .def("get_needed_options", &PyAlgorithmBase::GetNeededOptions, "Get names of options the algorithm needs") + .def("get_possible_options", &PyAlgorithmBase::GetPossibleOptions, + "Get names of options the algorithm may request") .def("set_option", &PyAlgorithmBase::SetOption, "option_name"_a, "option_value"_a = pybind11::none(), "Set option value") .def("get_option_type", &PyAlgorithmBase::GetOptionType, "option_name"_a, diff --git a/src/python_bindings/py_algorithm.cpp b/src/python_bindings/py_algorithm.cpp index 9b54fd9518..6b46c4d04f 100644 --- a/src/python_bindings/py_algorithm.cpp +++ b/src/python_bindings/py_algorithm.cpp @@ -55,6 +55,10 @@ std::unordered_set PyAlgorithmBase::GetNeededOptions() const { return algorithm_->GetNeededOptions(); } +std::unordered_set PyAlgorithmBase::GetPossibleOptions() const { + return algorithm_->GetPossibleOptions(); +} + py::tuple PyAlgorithmBase::GetOptionType(std::string_view option_name) const { auto type_index = algorithm_->GetTypeIndex(option_name); if (type_index == void_index) diff --git a/src/python_bindings/py_algorithm.h b/src/python_bindings/py_algorithm.h index 0ae84b252e..11e7d0652b 100644 --- a/src/python_bindings/py_algorithm.h +++ b/src/python_bindings/py_algorithm.h @@ -28,6 +28,8 @@ class PyAlgorithmBase { [[nodiscard]] std::unordered_set GetNeededOptions() const; + [[nodiscard]] std::unordered_set GetPossibleOptions() const; + [[nodiscard]] pybind11::tuple GetOptionType(std::string_view option_name) const; // For pandas dataframes diff --git a/src/python_bindings/test_bindings.py b/src/python_bindings/test_bindings.py index 400a033bb6..395f7167a7 100644 --- a/src/python_bindings/test_bindings.py +++ b/src/python_bindings/test_bindings.py @@ -2,11 +2,13 @@ import desbordante as desb -for name, type_ in getmembers(desb, isclass): +for algo_name, type_ in getmembers(desb, isclass): if not (issubclass(type_, desb.FdAlgorithm) and type_ is not desb.FdAlgorithm): continue algorithm = type_() + for option_name in algorithm.get_possible_options(): + print(option_name, algorithm.get_option_type(option_name)) algorithm.load_data('WDC_satellites.csv', ',', False) algorithm.execute() - print(name, algorithm.get_fds()) + print(algo_name, algorithm.get_fds())