def test_pybind_pr_with_return(self): module = graphit.compile_and_load(self.root_test_input_dir + "export_pr_with_return.gt") graph = csr_matrix(([0, 0, 0, 0, 0, 0], [1, 2, 3, 0, 0, 0], [0, 3, 4, 5, 6])) ranks = module.export_func(graph) self.assertEqual(np.sum(ranks), 1.0)
def test_pybind_cf(self): module = graphit.compile_and_load( self.root_test_input_dir + "export_cf_vector_input_with_return.gt") graph = csr_matrix(([0, 0, 0, 0, 0, 0], [1, 2, 3, 0, 0, 0], [0, 3, 4, 5, 6])) cf_result = module.export_func(graph) self.assertEqual(cf_result.shape, (4, 1))
def test_pybind_constant_size_vector_of_vector_return(self): module = graphit.compile_and_load( self.root_test_input_dir + "export_constant_size_vector_of_vector_return.gt") vector_return = module.export_func() self.assertEqual(vector_return.shape, (10, 10)) self.assertEqual(np.sum(vector_return), 550)
def test_pybind_vector_of_constant_size_arg(self): module = graphit.compile_and_load( self.root_test_input_dir + "export_vector_of_constant_size_arg.gt") graph = csr_matrix(([0, 0, 0, 0, 0, 0], [1, 2, 3, 0, 0, 0], [0, 3, 4, 5, 6])) vector_of_constant_size = np.ones(100) module.export_func(graph, vector_of_constant_size)
def test_pybind_pr_load_file(self): module = graphit.compile_and_load(self.root_test_input_dir + "export_pr_with_return.gt") graph = csr_matrix(scipy.io.mmread(self.root_test_graph_dir + "4.mtx")) ranks = module.export_func(graph) self.assertEqual(len(ranks), graph.shape[0]) self.assertTrue(abs(np.sum(ranks) - 1.0) < 0.1)
def test_pybind_vector_of_vector_arg(self): module = graphit.compile_and_load(self.root_test_input_dir + "export_vector_of_vector.gt") graph = csr_matrix(([0, 0, 0, 0, 0, 0], [1, 2, 3, 0, 0, 0], [0, 3, 4, 5, 6])) vector_of_vector = np.ones((4, 100)) output_data = module.export_func(graph, vector_of_vector) self.assertEqual(output_data.sum(), 404)
def test_pybind_pr_with_vector_input(self): module = graphit.compile_and_load( self.root_test_input_dir + "export_pagerank_with_vector_input.gt") graph = csr_matrix(([0, 0, 0, 0, 0, 0], [1, 2, 3, 0, 0, 0], [0, 3, 4, 5, 6])) new_rank_array = np.array([0, 0, 0, 0, 0], dtype=np.int32) ranks = module.export_func(graph, new_rank_array) self.assertEqual(np.sum(ranks), 1.0)
def test_pybind_pr_delta(self): module = graphit.compile_and_load(self.root_test_input_dir + "export_pr_delta.gt") graph = csr_matrix(([4, 5, 6, 4, 5, 6], [1, 2, 3, 0, 0, 0], [0, 3, 4, 5, 6])) ranks = module.export_func(graph) self.assertEqual(len(ranks), 4) self.assertTrue(abs(np.sum(ranks) - 1.0) < 0.001)
def test_pybind_extern_apply_src_add_one(self): module = graphit.compile_and_load( self.root_test_input_dir + "export_extern_simple_edgeset_appply.gt", [self.root_test_input_dir + "extern_src_add_one.cpp"]) graph = csr_matrix(([4, 5, 6, 4, 5, 6], [1, 2, 3, 0, 0, 0], [0, 3, 4, 5, 6])) sum_returned = module.export_func(graph) self.assertEqual(sum_returned, 6)
def test_pybind_various_type_vector_args(self): module = graphit.compile_and_load(self.root_test_input_dir + "export_various_types_vector_arg.gt") graph = csr_matrix(([0, 0, 0, 0, 0, 0], [1, 2, 3, 0, 0, 0], [0, 3, 4, 5, 6])) vector_of_vector = np.ones((4, 100)) vector_of_constant_size = np.ones(100) output = module.export_func(graph, vector_of_vector, vector_of_constant_size) self.assertEqual(output.sum(), 800)
def test_pybind_sssp_UW(self): module = graphit.compile_and_load(self.root_test_input_dir + "export_sssp_UW.gt") graph = csr_matrix(([4, 5, 6, 4, 5, 6], [1, 2, 3, 0, 0, 0], [0, 3, 4, 5, 6])) distances = module.do_sssp(graph, 0) self.assertEqual(len(distances), 4) self.assertEqual(distances[0], 0) self.assertEqual(distances[1], 4) self.assertEqual(distances[2], 5) self.assertEqual(distances[3], 6)
import graphit from scipy.sparse import csr_matrix import torch # In GraphIt, `edgeset`s define graphs. Use SciPy's `csr_matrix` to # create these values, which we'll pass into a GraphIt function. graph = csr_matrix(( [4, 5, 6, 4, 5, 6], [1, 2, 3, 0, 0, 0], [0, 3, 4, 5, 6], )) # Compile a GraphIt source file and load it so we can call its function. sssp_module = graphit.compile_and_load("/workspace/py-graphit-example/sssp.gt") # Invoke the `do_sssp` GraphIt function from the loaded module. distances = sssp_module.do_sssp(graph, 0) # A vector{Vertex} value is represented as a NumPy array. Use # `torch.tensor(...)` to convert it to a tensor. print(torch.tensor(distances))
import graphit import scipy.io from scipy.sparse import csr_matrix import sys import time module = graphit.compile_and_load("pagerank_delta_export.gt") graph = csr_matrix(scipy.io.mmread(sys.argv[1])) module.set_graph(graph) start_time = time.perf_counter() ranks = module.do_pagerank_delta() end_time = time.perf_counter() print("Time elapsed = " + str(end_time - start_time) + " seconds")
def benchmark_paperank(self): module = graphit.compile_and_load(GRAPHIT_SOURCE_DIRECTORY + "pagerank.gt", parallelization_type=PARALLEL_OPENMP) for dataset in datasets: graph = scipy.sparse.load_npz(PATH + dataset) module.export_func(graph)
# This file is copied from a repo - (https://github.com/bespoke-silicon-group/hb_starlite/tree/master/py-graphit-example) # author: mrutt92 import graphit from scipy.sparse import csr_matrix # In GraphIt, `edgeset`s define graphs. Use SciPy's `csr_matrix` to # create these values, which we'll pass into a GraphIt function. graph = csr_matrix(( [4, 5, 6, 4, 5, 6], [1, 2, 3, 0, 0, 0], [0, 3, 4, 5, 6], )) # Compile a GraphIt source file and load it so we can call its function. sssp_module = graphit.compile_and_load("./sssp.gt") # Invoke the `do_sssp` GraphIt function from the loaded module. distances = sssp_module.do_sssp(graph, 0) # A vector{Vertex} value is represented as a NumPy array. Use # `torch.tensor(...)` to convert it to a tensor. print(distances)