Skip to content

Commit

Permalink
found bug again in maxsat
Browse files Browse the repository at this point in the history
  • Loading branch information
DillonZChen committed Jan 17, 2025
1 parent 08d5af9 commit 7355e47
Show file tree
Hide file tree
Showing 18 changed files with 239 additions and 138 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/publish_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,17 @@ jobs:
- name: Display Python version
run: python -c "import sys; print(sys.version)"

- name: Pass tests
run: |
python -m pip install -r tests/test-requirements.txt
pytest tests/check_not_debug.py
pytest
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine auditwheel pybind11-stubgen
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
Expand Down
17 changes: 10 additions & 7 deletions include/feature_generation/features.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespace feature_generation {
std::shared_ptr<planning::Domain> domain;
std::shared_ptr<graph::GraphGenerator> graph_generator;
bool collected;
bool collapse_pruned;
bool pruned;
bool collecting;
int cur_collecting_layer;
std::shared_ptr<NeighbourContainer> neighbour_container;
Expand Down Expand Up @@ -130,13 +130,16 @@ namespace feature_generation {

/* Pruning functions */

std::set<int> features_to_prune_this_iteration(int iteration,
std::vector<std::vector<int>> &cur_colours);
std::set<int> features_to_prune(const std::vector<graph::Graph> &graphs);
void prune_this_iteration(int iteration,
const std::vector<graph::Graph> &graphs,
std::vector<std::vector<int>> &cur_colours);
void prune_bulk(const std::vector<graph::Graph> &graphs);

std::set<int> greedy_iteration_pruner(int iteration,
std::vector<std::vector<int>> &cur_colours);
std::set<int> maxsat_bulk_pruner(std::vector<Embedding> X);
std::set<int> prune_collapse_layer(int iteration, std::vector<std::vector<int>> &cur_colours);
std::set<int> prune_collapse_layer_x(int iteration,
const std::vector<graph::Graph> &graphs,
std::vector<std::vector<int>> &cur_colours);
std::set<int> prune_maxsat(std::vector<Embedding> X);

/* Prediction functions */

Expand Down
2 changes: 2 additions & 0 deletions include/feature_generation/pruning_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ namespace feature_generation {
static const std::string NONE;
static const std::string COLLAPSE_ALL;
static const std::string COLLAPSE_LAYER;
static const std::string COLLAPSE_LAYER_X;

static const std::vector<std::string> get_all();
static const bool is_layer_pruning(const std::string &pruning_option);
};
} // namespace feature_generation

Expand Down
26 changes: 15 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,22 @@
# Read version from wlplan/__version__.py file
exec(open("wlplan/__version__.py").read())

# Compiler flags
COMPILER_FLAGS = [
# "-O3",
"-DDEBUG",
]

files = [glob("src/*.cpp"), glob("src/**/*.cpp"), glob("src/**/**/*.cpp")]

ext_modules = [
Pybind11Extension(
"_wlplan",
# Sort input source files if you glob sources to ensure bit-for-bit
# reproducible builds (https://github.com/pybind/python_example/pull/53)
sorted([f for file_group in files for f in file_group]),
# Example: passing in the version to the compiled code
define_macros=[("WLPLAN_VERSION", __version__)],
),
]
ext_module = Pybind11Extension(
"_wlplan",
# Sort input source files if you glob sources to ensure bit-for-bit
# reproducible builds (https://github.com/pybind/python_example/pull/53)
sorted([f for file_group in files for f in file_group]),
define_macros=[("WLPLAN_VERSION", __version__)],
)
ext_module._add_cflags(COMPILER_FLAGS)

setup(
name="wlplan",
Expand All @@ -30,7 +34,7 @@
long_description_content_type="text/markdown",
packages=["wlplan", "_wlplan"],
package_data={"_wlplan": ["py.typed", "*.pyi", "**/*.pyi"]},
ext_modules=ext_modules,
ext_modules=[ext_module],
cmdclass={"build_ext": build_ext},
project_urls={"GitHub": "https://github.com/DillonZChen/wlplan"},
license="MIT License",
Expand Down
20 changes: 2 additions & 18 deletions src/feature_generation/feature_generators/wl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,27 +120,11 @@ namespace feature_generation {
}

// layer pruning
std::set<int> to_prune = features_to_prune_this_iteration(iteration, graph_colours);
if (to_prune.size() != 0) {
std::map<int, int> remap = remap_colour_hash(to_prune);
for (size_t graph_i = 0; graph_i < graphs.size(); graph_i++) {
for (size_t node_i = 0; node_i < graph_colours[graph_i].size(); node_i++) {
int col = graph_colours[graph_i][node_i];
if (remap.count(col) > 0) {
graph_colours[graph_i][node_i] = remap[col];
} else {
graph_colours[graph_i][node_i] = UNSEEN_COLOUR;
}
}
}
}
prune_this_iteration(iteration, graphs, graph_colours);
}

// bulk pruning
std::set<int> to_prune = features_to_prune(graphs);
if (to_prune.size() != 0) {
remap_colour_hash(to_prune);
}
prune_bulk(graphs);
layer_redundancy_check();
}

Expand Down
50 changes: 27 additions & 23 deletions src/feature_generation/features.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace feature_generation {
this->domain = std::make_shared<planning::Domain>(domain);
graph_generator = graph::create_graph_generator(graph_representation, domain);
collected = false;
collapse_pruned = false;
pruned = false;
collecting = false;
neighbour_container = std::make_shared<NeighbourContainer>(multiset_hash);
seen_colour_statistics = std::vector<std::vector<long>>(2, std::vector<long>(iterations, 0));
Expand Down Expand Up @@ -149,7 +149,9 @@ namespace feature_generation {
// make new_colours a copy of colours
std::vector<int> new_colours = colours;

// debug_vec(colours); // DEBUG
#ifdef DEBUG
debug_vec(colours);
#endif

// colours should always show up in remap by their construction
for (const int i : get_neighbour_colour_indices(colours)) {
Expand Down Expand Up @@ -197,23 +199,25 @@ namespace feature_generation {
}

//////////////////////////////////////////
// DEBUG
// std::cout << "initial_colours" << std::endl;
// for (const int i : seen_initial_colours) {
// std::cout << "INITIAL " << i << std::endl;
// }
// std::cout << "old_hash" << std::endl;
// for (const auto &[key, val] : colour_hash) {
// std::cout << "HASH "; debug_hash(key, val);
// }
// std::cout << "to_prune" << std::endl;
// for (const int i : to_prune) {
// std::cout << "PRUNE " << i << std::endl;
// }
// std::cout << "remap" << std::endl;
// for (const auto &[key, val] : remap) {
// std::cout << "REMAP " << key << " -> " << val << std::endl;
// }
#ifdef DEBUG
std::cout << "initial_colours" << std::endl;
for (const int i : seen_initial_colours) {
std::cout << "INITIAL " << i << std::endl;
}
std::cout << "old_hash" << std::endl;
for (const auto &[key, val] : colour_hash) {
std::cout << "HASH ";
debug_hash(key, val);
}
std::cout << "to_prune" << std::endl;
for (const int i : to_prune) {
std::cout << "PRUNE " << i << std::endl;
}
std::cout << "remap" << std::endl;
for (const auto &[key, val] : remap) {
std::cout << "REMAP " << key << " -> " << val << std::endl;
}
#endif
//////////////////////////////////////////

// remap keys
Expand Down Expand Up @@ -267,17 +271,17 @@ namespace feature_generation {
}

void Features::collect(const std::vector<graph::Graph> &graphs) {
if (pruning == PruningOptions::COLLAPSE_LAYER && collapse_pruned) {
std::cout << "collect with collapse pruning can only be called at most once" << std::endl;
if (pruning != PruningOptions::NONE && pruned) {
std::cout << "collect with pruning can only be called at most once" << std::endl;
exit(-1);
}

collecting = true;

collect_impl(graphs);

if (pruning == PruningOptions::COLLAPSE_LAYER) {
collapse_pruned = true;
if (pruning == PruningOptions::NONE) {
pruned = true;
}
collected = true;
collecting = false;
Expand Down
4 changes: 3 additions & 1 deletion src/feature_generation/maxsat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ namespace feature_generation {

std::string maxsat_wcnf_string = to_string();

// std::cout << maxsat_wcnf_string << std::endl; // DEBUG
#ifdef DEBUG
std::cout << maxsat_wcnf_string << std::endl;
#endif

py::object pysat_rc2 = py::module::import("pysat.examples.rc2").attr("RC2");
py::object pysat_wcnf = py::module::import("pysat.formula").attr("WCNF");
Expand Down
Loading

0 comments on commit 7355e47

Please sign in to comment.