def clique_battery(self, g, reconstruct, test_python=False, test_nocache=True): bgcg = busclique.busgraph_cache(g) emb0 = bgcg.largest_clique() size = len(emb0) cl = max_chainlength(emb0) N = range(size) yield size, cl yield g, emb0, 'g:bcg.lc', True yield g, bgcg.find_clique_embedding(size), 'g:bcg.fce', True yield g, busclique.find_clique_embedding(size, g), 'g:bc.fce', True if test_nocache: yield (g, busclique.find_clique_embedding(size, g, use_cache=False), 'g:bc.fce,nc', True) yield g, bgcg.largest_clique_by_chainlength(cl), 'g:bc.lcbc', True if test_python: if g.graph['family'] == 'chimera': if g.graph['labels'] == 'int': # this fails on coordinate-labeled graphs... TODO? args = size, g.graph['rows'] kwargs = dict(target_edges=g.edges) yield (g, chimera.find_clique_embedding(*args, **kwargs), 'g:legacy.fce', True) if g.graph['family'] == 'pegasus': kwargs = dict(target_graph=g) yield (g, pegasus.find_clique_embedding(size, **kwargs), 'g:legacy.fce', False) nodes = set(itertools.chain.from_iterable(emb0.values())) h = reconstruct(nodes) bgch = busclique.busgraph_cache(h) yield h, busclique.find_clique_embedding(N, h), 'h:bc.fce', True if test_nocache: yield (h, busclique.find_clique_embedding(N, h, use_cache=False), 'h:bc.fce,nc', True) yield h, bgch.largest_clique(), 'h:bgc.lc', True yield h, bgch.find_clique_embedding(N), 'h:bgc.fce', True yield h, bgch.largest_clique_by_chainlength(cl), 'h:bgc.lcbc', True if test_python: if g.graph['family'] == 'chimera': if g.graph['labels'] == 'int': # this fails on coordinate-labeled graphs... TODO? args = size, h.graph['rows'] kwargs = dict(target_edges=h.edges) yield (h, chimera.find_clique_embedding(*args, **kwargs), 'h:legacy.fce', True) if g.graph['family'] == 'pegasus': kwargs = dict(target_graph=h) yield (h, pegasus.find_clique_embedding(size, **kwargs), 'h:legacy.fce', False)
def largest_clique(self): """The clique embedding with the maximum number of source variables. Returns: dict: The clique embedding with the maximum number of source variables. """ return busgraph_cache(self.target_graph).largest_clique()
def biclique_battery(self, g, reconstruct): bgcg = busclique.busgraph_cache(g) emb0 = bgcg.largest_balanced_biclique() size = len(emb0) // 2 cl = max_chainlength(emb0) N = range(size) yield size, cl yield g, emb0, 'bgc.lbb' yield (g, bgcg.find_biclique_embedding(N, range(size, 2 * size)), 'bgc.fbe,list') yield g, bgcg.find_biclique_embedding(size, size), 'bgc.fbe,ints'
def test_perfect_z6_clique(self): k88 = nx.complete_graph(88) bgc = busclique.busgraph_cache(self.z6) e88_cache = bgc.largest_clique() verify_embedding(e88_cache, k88, self.z6) e88_cache2 = busclique.find_clique_embedding(88, self.z6, use_cache=True) verify_embedding(e88_cache2, k88, self.z6) e88 = busclique.find_clique_embedding(88, self.z6, use_cache=False) verify_embedding(e88, k88, self.z6)
def test_labelings(self): def reconstructor(g): return lambda nodes: g.subgraph(nodes).copy() names = 'c4_nd', 'c4', 'c4_d', 'p4_nd', 'p4', 'p4_d' nocache = False, True, True, False, True, True topos = self.c4_nd, self.c4, self.c4_d, self.p4_nd, self.p4, self.p4_d for (name, test_nocache, G) in zip(names, nocache, topos): g0 = G[0] bgc = busclique.busgraph_cache(g0) K = bgc.largest_clique() B = bgc.largest_balanced_biclique() for g in G: self.run_battery(name, g, reconstructor(g), len(K), max_chainlength(K), len(B) // 2, None, test_python=test_nocache, test_nocache=test_nocache)
# Copyright 2020 D-Wave Systems Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from pegasus_graph import P16 from matplotlib import pyplot as plt import networkx as nx, dwave_networkx as dnx from minorminer import busclique clique_cache = busclique.busgraph_cache(P16) clique_embedding = clique_cache.largest_clique() K = nx.complete_graph(len(clique_embedding)) dnx.draw_pegasus_embedding(P16, clique_embedding, K)
def largest_clique(self): """Return a largest-size clique embedding.""" return busgraph_cache(self.target_graph).largest_clique()
def test_perfect_z6_biclique(self): k88_88 = nx.complete_bipartite_graph(88, 88) bgc = busclique.busgraph_cache(self.z6) e88_88_cache = bgc.largest_balanced_biclique() verify_embedding(e88_88_cache, k88_88, self.z6)