Skip to content

Commit

Permalink
Remove Python features for C++ interface
Browse files Browse the repository at this point in the history
  • Loading branch information
DillonZChen committed Jan 16, 2025
1 parent e81d34c commit 7af90cb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ include(GNUInstallDirs)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -Wextra -pedantic -fPIC -O3 -DNDEBUG -fomit-frame-pointer")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -Wextra -pedantic -fPIC -O3 -DNDEBUG -DNOPYTHON -fomit-frame-pointer")

# Gather source files
# Do NOT glob src/main.cpp because that is only for creating Python bindings and requires pybind11
# Do NOT glob src/main.cpp because that is only for creating Python bindings
file(GLOB_RECURSE SRC_FILES "src/**/*.cpp")

# Define the library target
Expand Down
19 changes: 17 additions & 2 deletions src/feature_generation/pruning/maxsat.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#include "../../../include/feature_generation/pruning/maxsat.hpp"

#include <chrono>
#include <iostream>

#ifndef NOPYTHON
#include <pybind11/embed.h>
#include <pybind11/functional.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/typing.h>

namespace py = pybind11;
#endif

using std::chrono::duration;
using std::chrono::duration_cast;
Expand All @@ -32,7 +35,7 @@ namespace feature_generation {
<< std::endl;
exit(-1);
}
for (int i = 0; i < variables.size(); i++) {
for (size_t i = 0; i < variables.size(); i++) {
if (variables[i] < 1) {
std::cout << "error: variables in MaxSatClause should be strictly positive!" << std::endl;
exit(-1);
Expand Down Expand Up @@ -99,6 +102,7 @@ namespace feature_generation {
}

std::map<int, int> MaxSatProblem::call_solver() {
#ifndef NOPYTHON

std::string maxsat_wcnf_string = to_string();
py::object pysat_rc2 = py::module::import("pysat.examples.rc2").attr("RC2");
Expand Down Expand Up @@ -128,9 +132,15 @@ namespace feature_generation {
solution[variable] = (value > 0);
}
return solution;
#else
std::cout << "error: MaxSAT feature pruning is not supported in the C++ interface."
<< std::endl;
exit(-1);
#endif
}

std::map<int, int> MaxSatProblem::solve() {
#ifndef NOPYTHON
if (Py_IsInitialized() == 0) {
// interpreter is not running
py::scoped_interpreter guard{};
Expand All @@ -139,5 +149,10 @@ namespace feature_generation {
// interpreter is running (e.g. Python calling wlplan)
return call_solver();
}
#else
std::cout << "error: MaxSAT feature pruning is not supported in the C++ interface."
<< std::endl;
exit(-1);
#endif
}
} // namespace feature_generation

0 comments on commit 7af90cb

Please sign in to comment.