Skip to content

Commit

Permalink
busclique integration testing
Browse files Browse the repository at this point in the history
added integration tests for the busclique submodule
* fixed several bugs in busclique c++
* corrected issue where clear_all_caches wasn't removing directories
* addressed a -Werror=format-security issue for printing messages with no arguments
  • Loading branch information
boothby authored Jul 23, 2020
1 parent b0c8c8c commit 696e9dc
Show file tree
Hide file tree
Showing 7 changed files with 307 additions and 14 deletions.
21 changes: 15 additions & 6 deletions include/busclique/biclique_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class yieldcache {
template<typename topo_spec>
class biclique_cache {
public:
biclique_cache(const biclique_cache&) = delete;
biclique_cache(const biclique_cache&) = delete;
biclique_cache(biclique_cache &&) = delete;
const cell_cache<topo_spec> &cells;
private:
Expand Down Expand Up @@ -101,7 +101,7 @@ class biclique_cache {
for(size_t x0 = 0; x0 <= cells.topo.dim[1]-w; x0++)
next.set(y0, x0, 0, bundles.get_line_score(0, x0, y0, y0+h-1));
}
for(size_t w = 2; w < cells.topo.dim[1]; w++) {
for(size_t w = 2; w <= cells.topo.dim[1]; w++) {
yieldcache prev = get(h, w-1);
yieldcache next = get(h, w);
for(size_t y0 = 0; y0 <= cells.topo.dim[0]-h; y0++) {
Expand All @@ -124,7 +124,7 @@ class biclique_cache {
for(size_t x0 = 0; x0 <= cells.topo.dim[1]-w; x0++)
next.set(y0, x0, 1, bundles.get_line_score(1, y0, x0, x0+w-1));
}
for(size_t h = 2; h < cells.topo.dim[0]; h++) {
for(size_t h = 2; h <= cells.topo.dim[0]; h++) {
yieldcache prev = get(h-1, w);
yieldcache next = get(h, w);
for(size_t x0 = 0; x0 <= cells.topo.dim[1]-w; x0++) {
Expand Down Expand Up @@ -177,13 +177,20 @@ class biclique_yield_cache {
vector<vector<bound_t>> biclique_bounds;

public:
biclique_yield_cache(const biclique_yield_cache&) = delete;
biclique_yield_cache(biclique_yield_cache &&) = delete;

biclique_yield_cache(const cell_cache<topo_spec> &c,
const bundle_cache<topo_spec> &b,
const biclique_cache<topo_spec> &bicliques) :
cells(c),
bundles(b),
rows(cells.topo.dim[0]*cells.topo.shore),
cols(cells.topo.dim[1]*cells.topo.shore),

//note: the role of rows and columns is reversed, because the indices
//are chainlengths in a given direction (not the number of chains)
rows(cells.topo.dim[1]*cells.topo.shore),
cols(cells.topo.dim[0]*cells.topo.shore),

chainlength(rows, vector<size_t>(cols, 0)),
biclique_bounds(rows, vector<bound_t>(cols, bound_t(0,0,0,0))) {
compute_cache(bicliques);
Expand All @@ -198,6 +205,8 @@ class biclique_yield_cache {
size_t s0 = cache.get(y, x, 0);
size_t s1 = cache.get(y, x, 1);
if (s0 == 0 || s1 == 0) continue;
minorminer_assert(s0-1 < rows);
minorminer_assert(s1-1 < cols);
size_t maxlen = cells.topo.biclique_length(y, y+h-1, x, x+w-1);
size_t prevlen = chainlength[s0-1][s1-1];
if(prevlen == 0 || prevlen > maxlen) {
Expand Down Expand Up @@ -227,7 +236,7 @@ class biclique_yield_cache {
return true;
}
public:
iterator(size_t _s0, size_t _s1, const size_t r, const size_t c,
iterator(size_t _s0, size_t _s1, const size_t &r, const size_t &c,
const vector<vector<size_t>> &cl,
const vector<vector<bound_t>> &_bounds,
const bundle_cache<topo_spec> &_bundles) :
Expand Down
4 changes: 3 additions & 1 deletion include/busclique/clique_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ class clique_cache {
bundles(b),
width(w),
mem(new size_t[memsize()]{}) {
minorminer_assert(width <= cells.topo.dim[0]);
minorminer_assert(width <= cells.topo.dim[1]);
mem[0] = width;
for(size_t i = 1; i < width; i++)
mem[i] = mem[i-1] + memsize(i-1);
Expand Down Expand Up @@ -399,7 +401,7 @@ class clique_yield_cache {
}
stop_w1_scan:;
}
for(size_t w = 2; w <= cells.topo.dim[0]; w++) {
for(size_t w = 2; w <= min(cells.topo.dim[0], cells.topo.dim[1]); w++) {
size_t min_length, max_length;
get_length_range(bundles, w, min_length, max_length);
for(size_t len = min_length; len < max_length; len++) {
Expand Down
2 changes: 1 addition & 1 deletion include/busclique/find_clique.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ bool find_clique_nice(const cell_cache<pegasus_spec> &cells,
}
if(minw > maxw) return false;
} else {
maxw = (max_length)*6;
maxw = min(cells.topo.dim[0], (max_length)*6);
}
//we've already found an embedding; now try to find one with shorter chains
for(size_t w = minw; w <= maxw; w++) {
Expand Down
11 changes: 10 additions & 1 deletion include/find_embedding/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,20 @@ class optional_parameters {
localInteractionPtr->displayOutput(loglevel, buffer);
}

void print_out(int loglevel, const char* format) const {
localInteractionPtr->displayOutput(loglevel, format);
}


template <typename... Args>
void print_err(int loglevel, const char* format, Args... args) const {
char buffer[1024];
snprintf(buffer, 1024, format, args...);
localInteractionPtr->displayError(loglevel, buffer);
localInteractionPtr->displayError(loglevel, buffer);\
}

void print_err(int loglevel, const char* format) const {
localInteractionPtr->displayError(loglevel, format);
}

template <typename... Args>
Expand Down
14 changes: 10 additions & 4 deletions minorminer/busclique.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import networkx as nx, dwave_networkx as dnx
#increment this version any time there is a change made to the cache format,
#when yield-improving changes are made to clique algorithms, or when bugs are
#fixed in the same.
cdef int __cache_version = 3
cdef int __cache_version = 4

cdef int __lru_size = 100
cdef dict __global_locks = {'clique': threading.Lock(),
Expand Down Expand Up @@ -88,7 +88,7 @@ def find_clique_embedding(nodes, g, use_cache = True):
'chimera': _chimera_busgraph}[family]
except (AttributeError, KeyError):
raise ValueError("g must be either a dwave_networkx.chimera_graph or"
"a dwave_networkx.pegasus_graph")
" a dwave_networkx.pegasus_graph")
if use_cache:
return busgraph_cache(g).find_clique_embedding(nodes)
else:
Expand Down Expand Up @@ -158,12 +158,18 @@ class busgraph_cache:
if rootdir.exists():
dirstack.append(rootdir)
while dirstack:
top = dirstack.pop()
top = dirstack[-1]
substack = []
for item in top.iterdir():
if item.is_dir():
dirstack.append(item)
substack.append(item)
else:
item.unlink()
if substack:
dirstack.extend(substack)
else:
top.rmdir()
dirstack.pop()

def _fetch_cache(self, dirname, compute):
"""
Expand Down
Loading

0 comments on commit 696e9dc

Please sign in to comment.