Example #1
0
def run_deterministic_tests():
    
    for i in range(1,14):

        exp = daphne(['desugar-hoppl', '-i', '../HW3/fromJason/programs/tests/deterministic/test_{}.daphne'.format(i)])
        truth = load_truth('programs/tests/deterministic/test_{}.truth'.format(i))
        ret = evaluate(exp)
        try:
            assert(is_tol(ret, truth))
        except:
            raise AssertionError('return value {} is not equal to truth {} for exp {}'.format(ret,truth,exp))
        
        print('FOPPL Tests passed')
        
    for i in range(1,13):

        exp = daphne(['desugar-hoppl', '-i', '../HW3/fromJason/programs/tests/hoppl-deterministic/test_{}.daphne'.format(i)])
        truth = load_truth('programs/tests/hoppl-deterministic/test_{}.truth'.format(i))
        ret = evaluate(exp)
        try:
            assert(is_tol(ret, truth))
        except:
            raise AssertionError('return value {} is not equal to truth {} for exp {}'.format(ret,truth,exp))
        
        print('Test passed')
        
    print('All deterministic tests passed')
Example #2
0
def run_deterministic_tests():
    
    for i in range(1,14):

        exp = daphne(['desugar-hoppl', '-i', '../HW5/programs/tests/deterministic/test_{}.daphne'.format(i)])
        truth = load_truth('programs/tests/deterministic/test_{}.truth'.format(i))
        ret = evaluate(exp)
        try:
            assert(is_tol(ret, truth))
        except:
            raise AssertionError('return value {} is not equal to truth {} for exp {}'.format(ret,truth,exp))
        
        print('FOPPL Tests passed')
        
    for i in range(1,12):

        exp = daphne(['desugar-hoppl', '-i', '../HW5/programs/tests/hoppl-deterministic/test_{}.daphne'.format(i)])
        truth = load_truth('programs/tests/hoppl-deterministic/test_{}.truth'.format(i))
        ret = evaluate(exp)
        try:
            assert(is_tol(ret, truth))
        except:
            raise AssertionError('return value {} is not equal to truth {} for exp {}'.format(ret,truth,exp))
        
        print('Test passed')
        
    print('All deterministic tests passed')
    print("skipping test 12 since the output is correct, it's just in the wrong order because of the conj vs. cons thing that Mia pointed out. ")
Example #3
0
def run_deterministic_tests(use_cache=True, cache='programs/tests/'):

    for i in range(1, 15):
        if use_cache:
            with open(cache + 'deterministic/test_{}.json'.format(i),
                      'r') as f:
                exp = json.load(f)
        else:
            exp = daphne([
                'desugar-hoppl-cps', '-i',
                '../../HW6/programs/tests/deterministic/test_{}.daphne'.format(
                    i)
            ])
            with open(cache + 'deterministic/test_{}.json'.format(i),
                      'w') as f:
                json.dump(exp, f)
        truth = load_truth(
            'programs/tests/deterministic/test_{}.truth'.format(i))
        ret = sample_from_prior(exp)
        try:
            assert (is_tol(ret, truth))
        except:
            raise AssertionError(
                'return value {} is not equal to truth {} for exp {}'.format(
                    ret, truth, exp))
        print('Test {} passed'.format(i))

    print('FOPPL Tests passed')

    for i in range(1, 13):
        if use_cache:
            with open(cache + 'hoppl-deterministic/test_{}.json'.format(i),
                      'r') as f:
                exp = json.load(f)
        else:
            exp = daphne([
                'desugar-hoppl-cps', '-i',
                '../../HW6/programs/tests/hoppl-deterministic/test_{}.daphne'.
                format(i)
            ])
            with open(cache + 'hoppl-deterministic/test_{}.json'.format(i),
                      'w') as f:
                json.dump(exp, f)

        truth = load_truth(
            'programs/tests/hoppl-deterministic/test_{}.truth'.format(i))
        ret = sample_from_prior(exp)

        try:
            assert (is_tol(ret, truth))
        except:
            raise AssertionError(
                'return value {} is not equal to truth {} for exp {}'.format(
                    ret, truth, exp))

        print('Test {} passed'.format(i))

    print('All deterministic tests passed')
Example #4
0
def run_deterministic_tests():
    #for i in range(13,14):
    for i in range(1, 14):
        # # Note: this path should be with respect to the daphne path!
        # ast = daphne(['desugar-hoppl', '-i', f'{program_path}/src/programs/tests/deterministic/test_{i}.daphne'])
        # ast_path = f'./jsons/tests/deterministic/{i}.json'
        # with open(ast_path, 'w') as fout:
        #     json.dump(ast, fout, indent=2)
        # print('\n\n\nSample of posterior of program {}:'.format(i))

        print('\nDeterministic program {}:'.format(i))
        ast_path = f'./jsons/tests/deterministic/{i}.json'
        with open(ast_path) as json_file:
            exp = json.load(json_file)
        # print(exp)

        ret, sig = evaluate(exp=exp)
        truth = load_truth(
            f'{program_path}/src/programs/tests/deterministic/test_{i}.truth')
        print('Output: ', ret)
        print('Truth:', truth)
        try:
            assert (is_tol(ret, truth))
            print('HOPPL Test passed!')
        except:
            print('return value {} is not equal to truth {} for exp {}'.format(
                ret, truth, exp))

    #for i in range(5,6):
    for i in range(1, 13):
        # # Note: this path should be with respect to the daphne path!
        # ast = daphne(['desugar-hoppl', '-i', f'{program_path}/src/programs/tests/hoppl-deterministic/test_{i}.daphne'])
        # ast_path = f'./jsons/tests/hoppl-deterministic/{i}.json'
        # with open(ast_path, 'w') as fout:
        #     json.dump(ast, fout, indent=2)
        # print('\n\n\nSample of posterior of program {}:'.format(i))

        print('\nHOPPL deterministic  {}:'.format(i))
        ast_path = f'./jsons/tests/hoppl-deterministic/{i}.json'
        with open(ast_path) as json_file:
            exp = json.load(json_file)
        # print(exp)

        ret, sig = evaluate(exp=exp)
        truth = load_truth(
            f'{program_path}/src/programs/tests/hoppl-deterministic/test_{i}.truth'
        )
        try:
            print('Output: ', ret)
            print('Truth :', truth)
            assert (is_tol(ret, truth))
            print('Test passed')
        except:
            print('return value is not equal to truth {}'.format(truth))
    print('All hoppl-deterministic tests passed')
Example #5
0
def run_deterministic_tests():

    for i in range(1, 14):
        #print("cwd is ", os.getcwd())
        #note: this path should be with respect to the daphne path!
        #ast = daphne(['desugar', '-i', '../CS532-HW2/programs/tests/deterministic/test_{}.daphne'.format(i)])
        #ast = daphne(['desugar', '-i', './programs/tests/deterministic/test_{}.daphne'.format(i)])
        ast = daphne([
            'desugar', '-i',
            '../HW3/programs/tests/deterministic/test_{}.daphne'.format(i)
        ])

        truth = load_truth(
            'programs/tests/deterministic/test_{}.truth'.format(i))
        ret, sig = evaluate_program(ast)
        try:
            assert (is_tol(ret, truth))
        except AssertionError:
            #raise AssertionError('return value {} is not equal to truth {} for exp {}'.format(ret,truth,ast))
            print('return value {} is not equal to truth {} for exp {}'.format(
                ret, truth, ast))

        print('Test passed')

    print('All deterministic tests passed')
Example #6
0
def run_probabilistic_tests():

    # num_samples=1e4
    num_samples = 10
    max_p_value = 1e-4

    for i in range(1, 7):
        #note: this path should be with respect to the daphne path!
        # ast = daphne(['desugar', '-i', '../CS532-HW2/programs/tests/probabilistic/test_{}.daphne'.format(i)])
        ast = daphne([
            'desugar', '-i',
            '../HW2/programs/tests/probabilistic/test_{}.daphne'.format(i)
        ])
        truth = load_truth(
            'programs/tests/probabilistic/test_{}.truth'.format(i))

        stream = get_stream(ast)

        print('PROB TEST: ', str(i))
        p_val = run_prob_test(stream, truth, num_samples)

        print('p value', p_val)
        assert (p_val > max_p_value)

    print('All probabilistic tests passed')
Example #7
0
def run_deterministic_tests():
    for i in range(1, 13):
        #for i in range(2,3): # For debugging purposes
        # Note: this path should be with respect to the daphne path!
        # ast = daphne(['graph', '-i', f'{daphne_path}/src/programs/tests/deterministic/test_{i}.daphne'])
        # ast_path = f'./jsons/graphs/deterministic/test_{i}.json'
        # with open(ast_path, 'w') as fout:
        #     json.dump(ast, fout, indent=2)

        ast_path = f'./jsons/graphs/deterministic/test_{i}.json'
        with open(ast_path) as json_file:
            graph = json.load(json_file)
        # print(graph)

        ret = sample_from_joint(graph)

        print('Running graph-based-sampling for deterministic test number {}:'.
              format(str(i)))
        truth = load_truth(
            './programs/tests/deterministic/test_{}.truth'.format(i))
        print("Graph Evaluation Output: ", ret)
        print("Ground Truth: ", truth)
        try:
            assert (is_tol(ret, truth))
        except AssertionError:
            raise AssertionError(
                'return value {} is not equal to truth {} for graph {}'.format(
                    ret, truth, graph))

        print('Test passed \n')

    print('All deterministic tests passed.')
Example #8
0
def run_probabilistic_tests(use_cache=True, cache='programs/tests/'):

    num_samples = 1e4
    max_p_value = 1e-2

    for i in [1, 2, 3, 4, 6]:  #test 5 does not work, sorry.
        if use_cache:
            with open(cache + 'probabilistic/test_{}.json'.format(i),
                      'r') as f:
                exp = json.load(f)
        else:
            exp = daphne([
                'desugar-hoppl-cps', '-i',
                '../../HW6/programs/tests/probabilistic/test_{}.daphne'.format(
                    i)
            ])
            with open(cache + 'probabilistic/test_{}.json'.format(i),
                      'w') as f:
                json.dump(exp, f)
        truth = load_truth(
            'programs/tests/probabilistic/test_{}.truth'.format(i))

        stream = get_stream(exp)

        p_val = run_prob_test(stream, truth, num_samples)

        print('p value', p_val)
        assert (p_val > max_p_value)

    print('All probabilistic tests passed')
Example #9
0
def run_probabilistic_tests():
    num_samples = 1e4
    max_p_value = 1e-2

    for i in range(1, 7):
        #for i in range(4,5):
        # # Note: this path should be with respect to the daphne path!
        # ast = daphne(['desugar-hoppl', '-i', f'{program_path}/src/programs/tests/probabilistic/test_{i}.daphne'])
        # ast_path = f'./jsons/tests/probabilistic/{i}.json'
        # with open(ast_path, 'w') as fout:
        #     json.dump(ast, fout, indent=2)
        # print('\n\n\nSample of prior of program {}:'.format(i))

        print('\nHOPPL probabilistic  Test {}:'.format(i))
        ast_path = f'./jsons/tests/probabilistic/{i}.json'
        with open(ast_path) as json_file:
            ast = json.load(json_file)
        # print(ast)

        #ret, sig = evaluate(exp=ast)
        #print(ret)

        stream = get_stream(exp=ast)
        truth = load_truth(
            f'{program_path}/src/programs/tests/probabilistic/test_{i}.truth')
        p_val = run_prob_test(stream, truth, num_samples)
        print('p value', p_val)
        assert (p_val > max_p_value)

    print('All probabilistic tests passed')
Example #10
0
def run_deterministic_tests():
    for i in range(1, 14):
        # Note: this path should be with respect to the daphne path!
        # ast = daphne([f'desugar', '-i', f'{daphne_path}/src/programs/tests/deterministic/test_{i}.daphne'])
        #
        # ast_path = f'./jsons/tests/deterministic/test_{i}.json'
        # with open(ast_path, 'w') as fout:
        #     json.dump(ast, fout, indent=2)

        ast_path = f'./jsons/tests/deterministic/test_{i}.json'
        with open(ast_path) as json_file:
            ast = json.load(json_file)
        # print(ast)

        ret, sig = evaluate_program(ast)
        print(
            'Running evaluation-based-sampling for deterministic test number {}:'
            .format(str(i)))
        truth = load_truth(
            './programs/tests/deterministic/test_{}.truth'.format(i))
        print("Evaluation Output: ", ret)
        print("Ground Truth: ", truth)
        try:
            assert (is_tol(ret, truth))
        except AssertionError:
            raise AssertionError(
                'return value {} is not equal to truth {} for exp {}'.format(
                    ret, truth, ast))

        print('Test passed \n')

    print('All deterministic tests passed.')
Example #11
0
def run_probabilistic_tests():

    num_samples = 1e4
    max_p_value = 1e-2

    for i in range(1, 7):

        exp = daphne([
            'desugar-hoppl', '-i',
            '../HW5/programs/tests/probabilistic/test_{}.daphne'.format(i)
        ])

        print("probabilistic test {} \n".format(i))

        truth = load_truth(
            'programs/tests/probabilistic/test_{}.truth'.format(i))

        stream = get_stream(exp)

        p_val = run_prob_test(stream, truth, num_samples)

        print('p value', p_val)
        assert (p_val > max_p_value)

    print('All probabilistic tests passed')
Example #12
0
def run_deterministic_tests():

    for i in range(10, 14):
        if i != 6:
            if i != 8:
                if i != 11:
                    #note: this path should be with respect to the daphne path!
                    # ast = daphne(['desugar', '-i', '../CS532-HW2/programs/tests/deterministic/test_{}.daphne'.format(i)])
                    ast = daphne([
                        'desugar', '-i',
                        '../HW2/programs/tests/deterministic/test_{}.daphne'.
                        format(i)
                    ])
                    print('ast is: ', str(ast))
                    truth = load_truth(
                        'programs/tests/deterministic/test_{}.truth'.format(i))
                    ret = evaluate_program(ast)
                    try:
                        assert (is_tol(ret, truth))
                    except AssertionError:
                        raise AssertionError(
                            'return value {} is not equal to truth {} for exp {}'
                            .format(ret, truth, ast))

                    print('!Test ', str(i), ' passed!')

    print('All deterministic tests passed')
Example #13
0
def run_deterministic_tests():

    for i in range(1, 14):

        exp = daphne([
            'desugar-hoppl', '-i',
            '/home/bigboi/Desktop/Prob_Prog_Course/CS532-HW5/programs/tests/deterministic/test_{}.daphne'
            .format(i)
        ])
        truth = load_truth(
            'programs/tests/deterministic/test_{}.truth'.format(i))
        print(i, exp)
        ret = evaluate(exp).call()
        print("truth", truth, "return", ret)
        try:
            assert (is_tol(ret, truth))
        except:
            raise AssertionError(
                'return value {} is not equal to truth {} for exp {}'.format(
                    ret, truth, exp))

        print('FOPPL Tests passed')

    for i in range(1, 13):

        exp = daphne([
            'desugar-hoppl', '-i',
            '/home/bigboi/Desktop/Prob_Prog_Course/CS532-HW5/programs/tests/hoppl-deterministic/test_{}.daphne'
            .format(i)
        ])
        truth = load_truth(
            'programs/tests/hoppl-deterministic/test_{}.truth'.format(i))
        print(i, exp)
        ret = evaluate(exp).call()
        print("truth", truth, "return", ret)
        try:
            assert (is_tol(ret, truth))
        except:
            raise AssertionError(
                'return value {} is not equal to truth {} for exp {}'.format(
                    ret, truth, exp))

        print('Test passed')

    print('All deterministic tests passed')
def run_deterministic_tests():
    
    for i in range(1,13):
        #note: this path should be with respect to the daphne path!
        graph = daphne(['graph','-i','../CS532-HW2/programs/tests/deterministic/test_{}.daphne'.format(i)])
        truth = load_truth('programs/tests/deterministic/test_{}.truth'.format(i))
        ret = deterministic_eval(graph[-1])
        try:
            assert(is_tol(ret, truth))
        except AssertionError:
            raise AssertionError('return value {} is not equal to truth {} for graph {}'.format(ret,truth,graph))
        
        print('Test passed')
        
    print('All deterministic tests passed')
def run_probabilistic_tests():
    num_samples = 1e4
    max_p_value = 1e-4
    for i in range(1, 7):
        #note: this path should be with respect to the daphne path!
        graph = daphne([
            'graph', '-i',
            '../CS532-HW2/programs/tests/probabilistic/test_{}.daphne'.format(
                i)
        ])
        truth = load_truth(
            'programs/tests/probabilistic/test_{}.truth'.format(i))
        stream = get_stream(graph)
        p_val = run_prob_test(stream, truth, num_samples)
        print('p value', p_val)
        print(p_val > max_p_value)
    print('All probabilistic tests passed')
Example #16
0
def run_probabilistic_tests():
    #TODO:
    num_samples = 1e4
    max_p_value = 1e-4

    for i in range(1, 7):
        #for i in range(6,7):
        # Note: this path should be with respect to the daphne path!
        # ast = daphne(['graph', '-i', f'{daphne_path}/src/programs/tests/probabilistic/test_{i}.daphne'])
        # ast_path = f'./jsons/graphs/probabilistic/test_{i}.json'
        # with open(ast_path, 'w') as fout:
        #     json.dump(ast, fout, indent=2)

        ast_path = f'./jsons/graphs/probabilistic/test_{i}.json'
        with open(ast_path) as json_file:
            graph = json.load(json_file)
        # print(graph)

        stream = get_stream(graph)

        # samples = []
        # for k in range(1):
        #     samples.append(next(stream))
        # print(samples)

        # if i != 4:
        print('Running graph-based-sampling for probabilistic test number {}:'.
              format(str(i)))
        truth = load_truth(
            './programs/tests/probabilistic/test_{}.truth'.format(i))
        # print(truth)
        p_val = run_prob_test(stream, truth, num_samples)

        print('p value', p_val)

        try:
            assert (p_val > max_p_value)
        except AssertionError:
            print('Test Failed\n')
            continue

        print('Test passed\n')

    print('All probabilistic tests passed.')
Example #17
0
def run_probabilistic_tests():

    num_samples = 1e4
    #num_samples=10
    max_p_value = 1e-4

    for i in range(1, 7):
        #for i in range(6,7):
        # Note: this path should be with respect to the daphne path!
        # ast = daphne(['desugar', '-i', f'{daphne_path}/src/programs/tests/probabilistic/test_{i}.daphne'])
        # ast_path = f'./jsons/tests/probabilistic/test_{i}.json'
        # with open(ast_path, 'w') as fout:
        #     json.dump(ast, fout, indent=2)

        ast_path = f'./jsons/tests/probabilistic/test_{i}.json'
        with open(ast_path) as json_file:
            ast = json.load(json_file)
        # print(ast)

        stream = get_stream(ast)

        # samples = []
        # for k in range(1):
        #     samples.append(next(stream))
        # print(samples)

        print(
            'Running evaluation-based-sampling for probabilistic test number {}:'
            .format(str(i)))

        truth = load_truth(
            './programs/tests/probabilistic/test_{}.truth'.format(i))
        p_val = run_prob_test(stream, truth, num_samples)

        # Empty globals funcs
        rho = {}

        assert (p_val > max_p_value)
        print('P-Value: ', p_val)
        print('Test passed \n')

    print('All probabilistic tests passed.')
Example #18
0
def run_deterministic_tests():
    """
    for i in range(14,14):

        exp = daphne(['desugar-hoppl', '-i', '../CS532-HW5/programs/tests/deterministic/test_{}.daphne'.format(i)])
        print(exp)
        truth = load_truth('programs/tests/deterministic/test_{}.truth'.format(i))
        ret = evaluate(exp)
        ret = ret("dontcare")
        print("Ret:", ret)
        try:
            assert(is_tol(ret, truth))
        except:
            raise AssertionError('return value {} is not equal to truth {} for exp {}'.format(ret,truth,exp))

    print('FOPPL Tests passed')
    """
    for i in range(12, 13):

        exp = daphne([
            'desugar-hoppl', '-i',
            '../CS532-HW5/programs/tests/hoppl-deterministic/test_{}.daphne'.
            format(i)
        ])
        print(exp)
        truth = load_truth(
            'programs/tests/hoppl-deterministic/test_{}.truth'.format(i))
        ret = evaluate(exp)
        ret = ret("dontcare")
        if isinstance(ret, PVector):
            ret = torch.tensor(ret.tolist())
        try:
            assert (is_tol(ret, truth))
        except:
            raise AssertionError(
                'return value {} is not equal to truth {} for exp {}'.format(
                    ret, truth, exp))

        print('Test passed')

    print('All deterministic tests passed')
Example #19
0
def run_probabilistic_tests():

    num_samples = 1e4
    max_p_value = 1e-2

    for i in range(1, 7):
        exp = daphne([
            'desugar-hoppl', '-i',
            '/home/bigboi/Desktop/Prob_Prog_Course/CS532-HW5/programs/tests/probabilistic/test_{}.daphne'
            .format(i)
        ])
        truth = load_truth(
            'programs/tests/probabilistic/test_{}.truth'.format(i))
        print("exp", exp, "truth", truth)
        stream = get_stream(exp)

        p_val = run_prob_test(stream, truth, num_samples)

        print('p value', p_val)
        assert (p_val > max_p_value)

    print('All probabilistic tests passed')