def test_impossible_clique(self):
        k = 55
        m = 2

        # Find embedding
        pg = pegasus_graph(m)

        with self.assertRaises(ValueError):
            find_clique_embedding(k, target_graph=pg)
Example #2
0
def get_embedding():
    embedding = []
    if path.exists(f'_data/embedding/{embedding_kind}_{U}_{Grids}_{Slack}.json'
                   ) == False:
        print(f"Finding {embedding_kind} Embedding")
        if embedding_kind == "regular":
            embedding = find_embedding(
                nx.complete_graph(scope).edges(), sampler.edgelist)
        elif embedding_kind == "clique":
            embedding = find_clique_embedding(
                scope, target_graph=sampler.to_networkx_graph())
        #print(embedding)

        with open(f'_data/embedding/{embedding_kind}_{U}_{Grids}_{Slack}.json',
                  "w") as ff:
            json.dump(embedding, ff)
    else:
        print(f"Importing saved {embedding_kind} Embedding")
    f = open(f'_data/embedding/{embedding_kind}_{U}_{Grids}_{Slack}.json')
    embedding = json.load(f)

    #dnx.draw_pegasus_embedding(sampler.to_networkx_graph(), embedding, unused_color=None)
    #plt.savefig(f'images/embedding_{embedding_type}N{N}q{q:.2f}B{B}P{P:.3f}.png')

    return embedding
    def test_valid_clique_coord(self):
        k = nx.complete_graph(55)
        m = 6

        # Find embedding
        pg = pegasus_graph(m, coordinates=True)
        embedding = find_clique_embedding(k, target_graph=pg)

        self.assertTrue(is_valid_embedding(embedding, k, pg))
Example #4
0
    def test_valid_clique_ints(self):
        k = nx.complete_graph(15)
        m = 4

        # Find embedding
        pg = pegasus_graph(m)
        embedding = find_clique_embedding(k, target_graph=pg)

        self.assertTrue(is_valid_embedding(embedding, k, pg))
Example #5
0
    def test_k_parameter_int(self):
        k_int = 5
        m = 3

        # Find embedding
        pg = pegasus_graph(m, coordinates=True)
        embedding = find_clique_embedding(k_int, target_graph=pg)

        self.assertTrue(is_valid_embedding(embedding, nx.complete_graph(k_int), pg))
Example #6
0
    def test_one_clique(self):
        k = 1
        m = 4

        # Find embedding
        pg = pegasus_graph(m, coordinates=True)
        embedding = find_clique_embedding(k, target_graph=pg)

        self.assertTrue(is_valid_embedding(embedding, nx.complete_graph(k), pg))
Example #7
0
    def test_k_parameter_list(self):
        k_nodes = ['one', 'two', 'three']
        m = 4

        # Find embedding
        pg = pegasus_graph(m, coordinates=True)
        embedding = find_clique_embedding(k_nodes, target_graph=pg)

        self.assertTrue(is_valid_embedding(embedding, nx.complete_graph(k_nodes), pg))
    def test_zero_clique(self):
        k = 0
        m = 3

        # Find embedding
        pg = pegasus_graph(m)
        embedding = find_clique_embedding(k, target_graph=pg)

        self.assertEqual(k, len(embedding))
        self.assertEqual({}, embedding)
Example #9
0
    def test_clique_incomplete_graph(self):
        k = 5
        m = 2

        # Nodes in a known K5 embedding
        # Note: {0: [14, 32], 1: [33, 15], 2: [16, 34], 3: [35, 17], 4: [36, 12]}
        known_embedding_nodes = {14, 32, 33, 15, 16, 34, 35, 17, 36, 12}

        # Create graph with missing nodes
        incomplete_pg = pegasus_graph(m)
        removed_nodes = set(incomplete_pg.nodes) - known_embedding_nodes
        incomplete_pg.remove_nodes_from(removed_nodes)

        # See if clique embedding is found
        embedding = find_clique_embedding(k, target_graph=incomplete_pg)
        self.assertTrue(is_valid_embedding(embedding, nx.complete_graph(k), incomplete_pg))
Example #10
0
    def test_clique_missing_edges(self):
        k = 9
        m = 2

        pg = pegasus_graph(m)

        #pick a random ordering of the edges
        edges = list(pg.edges())
        shuffle(edges)

        K = nx.complete_graph(k)

        #now delete edges, one at a time, until we can no longer embed K
        with self.assertRaises(ValueError):
            while 1:
                (u, v) = edges.pop()
                pg.remove_edge(u, v)

                # See if clique embedding is found
                embedding = find_clique_embedding(k, target_graph=pg)
                self.assertTrue(is_valid_embedding(embedding, K, pg))