Exemplo n.º 1
0
    def test_instantiate_expr_two_indices(self):
        result = _instantiate_expr(parse_expr("Forall (i,j) a_i_j=1"), 2, False)
        expected = parse_expr("a_0_1=1 * a_1_0=1")

        result_data = _get_sorted_conjuncts_str(result)
        expected_data = _get_sorted_conjuncts_str(expected)
        self.assertEqual(expected_data, result_data)
Exemplo n.º 2
0
    def test_instantiate_expr_two_indices(self):
        result = _instantiate_expr(parse_expr('Forall (i,j) a_i_j=1'), 2,
                                   False)
        expected = parse_expr('a_0_1=1 * a_1_0=1')

        result_data = _get_sorted_conjuncts_str(result)
        expected_data = _get_sorted_conjuncts_str(expected)
        self.assertEqual(expected_data, result_data)
Exemplo n.º 3
0
    def test_sched_optimization(self):
        scheduler = InterleavingScheduler()

        forall_expr = scheduler.assumptions[0]  # Forall(i) GFsched_i=1

        instantiated_expr = _instantiate_expr(forall_expr, 2, False)  # GFsched_0=1 * GFsched_1=1

        result_expr = _apply_log_bit_optimization("sch", instantiated_expr, 2, scheduler)
        expected_expr = BinOp(
            "*", UnaryOp("G", UnaryOp("F", _get_is_true("sch", 0))), UnaryOp("G", UnaryOp("F", _get_is_false("sch", 0)))
        )

        result_str = _get_sorted_conjuncts_str(result_expr)
        expected_str = _get_sorted_conjuncts_str(expected_expr)

        self.assertEqual(expected_str, result_str)
Exemplo n.º 4
0
    def test_sched_optimization(self):
        scheduler = InterleavingScheduler()

        forall_expr = scheduler.assumptions[0]  # Forall(i) GFsched_i=1

        instantiated_expr = _instantiate_expr(
            forall_expr, 2, False)  # GFsched_0=1 * GFsched_1=1

        result_expr = _apply_log_bit_optimization('sch', instantiated_expr, 2,
                                                  scheduler)
        expected_expr = BinOp(
            '*', UnaryOp('G', UnaryOp('F', _get_is_true('sch', 0))),
            UnaryOp('G', UnaryOp('F', _get_is_false('sch', 0))))

        result_str = _get_sorted_conjuncts_str(result_expr)
        expected_str = _get_sorted_conjuncts_str(expected_expr)

        self.assertEqual(expected_str, result_str)
Exemplo n.º 5
0
    def test_sched_visual(self):
        scheduler = InterleavingScheduler()
        forall_expr = normalize_conjuncts([parse_expr("Forall(i) a_i=1"), scheduler.assumptions[0]])

        instantiated_expr = _instantiate_expr(forall_expr, 4, False)  # GFsched_0=1 * GFsched_1=1

        result_expr = _apply_log_bit_optimization("sch", instantiated_expr, 4, scheduler)
        print(
            """::test_sched_visual::
Check visually the correctness.
The original expr is Forall(i) a_i=1 * GFfair_sched_i=1,
 after scheduler_log_bit optimization and instantiation with cutoff=4
 it is expected to receive
  a_0=1 * a_1=1 * a_2=1 * a_3=1 *
  GF(sch0=0 * sch1=0) *
  GF(sch0=0 * sch1=1) *
  GF(sch0=1 * sch1=0) *
  GF(sch0=1 * sch1=1)
        """,
            result_expr,
        )
        print("The result is")
        print(result_expr)
Exemplo n.º 6
0
    def test_sched_visual(self):
        scheduler = InterleavingScheduler()
        forall_expr = normalize_conjuncts(
            [parse_expr('Forall(i) a_i=1'), scheduler.assumptions[0]])

        instantiated_expr = _instantiate_expr(
            forall_expr, 4, False)  # GFsched_0=1 * GFsched_1=1

        result_expr = _apply_log_bit_optimization('sch', instantiated_expr, 4,
                                                  scheduler)
        print(
            '''::test_sched_visual::
Check visually the correctness.
The original expr is Forall(i) a_i=1 * GFfair_sched_i=1,
 after scheduler_log_bit optimization and instantiation with cutoff=4
 it is expected to receive
  a_0=1 * a_1=1 * a_2=1 * a_3=1 *
  GF(sch0=0 * sch1=0) *
  GF(sch0=0 * sch1=1) *
  GF(sch0=1 * sch1=0) *
  GF(sch0=1 * sch1=1)
        ''', result_expr)
        print('The result is')
        print(result_expr)
Exemplo n.º 7
0
    def test_instantiate_expr_not_quantified(self):
        result = _instantiate_expr(parse_expr("a_1=1"), 2, False)
        expected = parse_expr("a_1=1")

        self.assertEqual(str(expected), str(result))
Exemplo n.º 8
0
    def test_instantiate_expr_one_index(self):
        result = _instantiate_expr(parse_expr("Forall (i) a_i=1"), 2, False)
        expected = parse_expr("a_0=1 * a_1=1")

        self.assertEqual(str(expected), str(result))
Exemplo n.º 9
0
    def test_instantiate_expr_not_quantified(self):
        result = _instantiate_expr(parse_expr('a_1=1'), 2, False)
        expected = parse_expr('a_1=1')

        self.assertEqual(str(expected), str(result))
Exemplo n.º 10
0
    def test_instantiate_expr_one_index(self):
        result = _instantiate_expr(parse_expr('Forall (i) a_i=1'), 2, False)
        expected = parse_expr('a_0=1 * a_1=1')

        self.assertEqual(str(expected), str(result))