Exemplo n.º 1
0
 def test_random_opt2(self):
     """
     Check that *Algorithm OPT2* works on 10 randomly generated synchronous circuits.
     """
     for _ in range(10):
         g = gen_random_circuit()
         gr = opt2(g)
         self.assertLessEqual(cp(gr), cp(g))
Exemplo n.º 2
0
def random_test(n=10000):
    for _ in trange(n):
        V = np.random.randint(5, 30)
        E = np.random.randint(5, 30)
        g = gen_random_circuit(V, E)
        cpg = cp(g)
        cpr1 = cp(opt1(g))
        cpr2 = cp(opt2(g))
        assert cpr1 == cpr2 and cpr1 <= cpg and cpr2 <= cpg
Exemplo n.º 3
0
 def test_correlators(self):
     """
     Check that all the correlators of order :math:`1 \leq k \leq 15` optimized either with *Algorithm OPT1* or
     *OPT2* have a clock period not greater that 14.
     """
     for i in range(1, 16):
         g = gen_correlator(i)
         gr1 = opt1(g)
         gr2 = opt2(g)
         self.assertLessEqual(cp(gr1), 14)
         self.assertLessEqual(cp(gr2), 14)
Exemplo n.º 4
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))
Exemplo n.º 5
0
 def test_correlator2_opt1(self):
     """
     Check that *Algorithm OPT1* applied to correlator2 produces a clock period of 13.
     """
     g = load_graph('../graphs/correlator2.dot')
     gr = opt1(g)
     self.assertEqual(cp(gr), 13)
Exemplo n.º 6
0
 def test_correlator2_cp(self):
     """
     Check that the clock period of correlator2 is 17.
     """
     g = load_graph('../graphs/correlator2.dot')
     clock_period = cp(g)
     self.assertEqual(clock_period, 17)
Exemplo n.º 7
0
 def test_correlator1_cp(self):
     """
     Check that the clock period of correlator1 is 24.
     """
     g = load_graph('../graphs/correlator1.dot')
     clock_period = cp(g)
     self.assertEqual(clock_period, 24)
Exemplo n.º 8
0
def run(g, save=None, show_wd=False):
    cpg = cp(g)
    print(f'The original graph has a clock period of {cpg}')
    print('Running algorithm OPT1')
    g1 = opt1(g, show_wd=show_wd)
    if save is not None:
        path = save+'_opt1.dot'
        save_graph(g1, path)
        print(f'Output graph saved to {path}')
    cpr1 = cp(g1)
    print(f'The graph returned by OPT1 has a clock period of {cpr1}')
    print('Running algorithm OPT2')
    g2 = opt2(g, show_wd=show_wd)
    if save is not None:
        path = save+'_opt2.dot'
        save_graph(g2, path)
        print(f'Output graph saved to {path}')
    cpr2 = cp(g2)
    print(f'The graph returned by OPT2 has a clock period of {cpr2}')