Beispiel #1
0
 def test_correlator2_retimed_opt2_synchronous_circuit(self):
     """
     Check that the circuit retimed with *Algorithm OPT2* starting from correlator2 is actually a synchronous circuit.
     """
     g = load_graph('../graphs/correlator2.dot')
     gr = opt2(g)
     self.assertTrue(check_if_synchronous_circuit(gr))
Beispiel #2
0
 def test_already_minimum_graph(self):
     """
     Check that *Algorithms OPT1* and *OPT2* work on already minimum graphs.
     """
     g = nx.MultiDiGraph()
     add_weighted_node(g, 'h', 0)
     add_weighted_node(g, 'u', 2)
     add_weighted_node(g, 'v', 3)
     g.add_weighted_edges_from([('h', 'u', 0), ('u', 'v', 1), ('v', 'h', 1)])
     self.assertTrue(check_if_synchronous_circuit(g))
     gr = opt1(g)
     self.assertEqual(cp(gr), cp(g))
     gr = opt2(g)
     self.assertEqual(cp(gr), cp(g))
Beispiel #3
0
def gen_random_circuit(V=8, E=11, save=False):
    """
    Generate a random synchronous circuit.

    :param V: The number of nodes.
    :param E: The number of edges.
    :param save: If different from ``None`` or ``False``, the path where to save the generated graph.
    :return: The generated graph.
    """
    while True:
        g = nx.gnm_random_graph(V, E, directed=True)
        for v in g.nodes:
            g.nodes[v]['weight'] = np.random.randint(1, 10)
        g.nodes[0]['weight'] = 0
        for e in g.edges:
            g.edges[e]['weight'] = np.random.randint(10)
        if check_if_synchronous_circuit(g):
            if save:
                save_graph(g, save)
            return g
Beispiel #4
0
 def test_correlator2_synchronous_circuit(self):
     """
     Check that correlator2 is actually a synchronous circuit.
     """
     g = load_graph('../graphs/correlator2.dot')
     self.assertTrue(check_if_synchronous_circuit(g))