1- from load_graph import load_graph
2- from intersection import intersection
3- from gen_automata import generate
1+ import graphblas
2+
3+ from cfpq_add_context .load_graph import load_graph
4+ from cfpq_add_context .intersection import intersection
5+ from cfpq_add_context .gen_automata import generate
6+ from graphblas .core .dtypes import BOOL , UINT64
7+ from graphblas .core .matrix import Matrix
8+
9+ from cfpq_matrix .block .block_matrix_space_impl import BlockMatrixSpaceImpl
10+ from cfpq_model .cnf_grammar_template import Symbol
11+ from cfpq_model .label_decomposed_graph import LabelDecomposedGraph
12+
413import time
514
15+ def indexed_to_boolean_decomposition (graph , block_count ):
16+ #print("graph = ", graph)
17+ #print("block count = ", block_count )
18+ vertex_count = graph .nrows
19+ edges = graph .to_edgelist ()
20+ edges = zip (edges [0 ], edges [1 ])
21+ new_edges = [(_edg [0 ] + vertex_count * _lbl , _edg [1 ]) for (_edg , _lbl ) in edges ]
22+ result = Matrix .from_edgelist (new_edges , values = True , dtype = BOOL , nrows = block_count * vertex_count ,
23+ ncols = vertex_count , name = "boolean_decomposition_of_indexed" )
24+ return result
25+
26+ def to_label_decomposed_graph (graph ):
27+ vertex_count = graph .nrows
28+ alloc = Matrix (BOOL , graph .ncols , graph .nrows , name = "alloc_after_intersection" )
29+ alloc << graph .select (graphblas .select .select_alloc )
30+
31+ alloc_r = Matrix (BOOL , graph .ncols , graph .nrows , name = "alloc_r_after_intersection" )
32+ alloc_r << graph .select (graphblas .select .select_alloc_r )
33+
34+ assign = Matrix (BOOL , graph .ncols , graph .nrows , name = "assign_after_intersection" )
35+ assign << graph .select (graphblas .select .select_assign )
36+
37+ assign_r = Matrix (BOOL , graph .ncols , graph .nrows , name = "assign_r_after_intersection" )
38+ assign_r << graph .select (graphblas .select .select_assign_r )
39+
40+ load_i = Matrix (UINT64 , graph .ncols , graph .nrows , name = "load_i_after_intersection" )
41+ load_i << graph .select (graphblas .select .select_load ).apply (graphblas .unary .decode_load )
42+
43+ load_r_i = Matrix (UINT64 , graph .ncols , graph .nrows , name = "load_r_i_after_intersection" )
44+ load_r_i << graph .select (graphblas .select .select_load_r ).apply (graphblas .unary .decode_load_r )
45+
46+ store_i = Matrix (UINT64 , graph .ncols , graph .nrows , name = "store_i_after_intersection" )
47+ store_i << graph .select (graphblas .select .select_store ).apply (graphblas .unary .decode_store )
48+
49+ store_r_i = Matrix (UINT64 , graph .ncols , graph .nrows , name = "store_r_i_after_intersection" )
50+ store_r_i << graph .select (graphblas .select .select_store_r ).apply (graphblas .unary .decode_store_r )
51+
52+ store_block_count = store_i .reduce_scalar ("max" ).get (0 ) + 1
53+ load_block_count = load_i .reduce_scalar ("max" ).get (0 ) + 1
54+ block_count = max (store_block_count , load_block_count )
55+
56+ boolean_decompose_load = indexed_to_boolean_decomposition (load_i , block_count )
57+ boolean_decompose_load_r = indexed_to_boolean_decomposition (load_r_i , block_count )
58+ boolean_decompose_store = indexed_to_boolean_decomposition (store_i , block_count )
59+ boolean_decompose_store_r = indexed_to_boolean_decomposition (store_r_i , block_count )
60+
61+ matrices : Dict [Symbol , Matrix ] = {}
62+
63+ matrices [Symbol ('alloc' )] = alloc
64+ matrices [Symbol ('alloc_r' )] = alloc_r
65+
66+ matrices [Symbol ('assign' )] = assign
67+ matrices [Symbol ('assign_r' )] = assign_r
68+
69+ matrices [Symbol ('store_i' )] = boolean_decompose_store
70+ matrices [Symbol ('load_i' )] = boolean_decompose_load
71+ matrices [Symbol ('store_r_i' )] = boolean_decompose_store_r
72+ matrices [Symbol ('load_r_i' )] = boolean_decompose_load_r
73+
74+ return LabelDecomposedGraph (
75+ vertex_count = vertex_count ,
76+ block_matrix_space = BlockMatrixSpaceImpl (n = vertex_count , block_count = block_count ),
77+ dtype = BOOL ,
78+ matrices = matrices
79+ )
80+
681def add_context (file_path ):
782 load_graph_start = time .perf_counter ()
883
984 graph ,number_of_contexts = load_graph (file_path )
1085
1186 load_graph_end = time .perf_counter ()
1287 print ("Graph loaded in " , load_graph_end - load_graph_start )
88+ print ("Vertices in graph: " , graph .ncols )
89+ print ("Edges in graph: " , graph .nvals )
90+ print ("Numer of contexts: " , number_of_contexts )
1391
1492 automata = generate (number_of_contexts )
1593
1694 automata_generation_end = time .perf_counter ()
1795 print ("Automata generated in " , automata_generation_end - load_graph_end )
96+ print ("Vertices in automata: " , automata .ncols )
97+ print ("Edges in automata: " , automata .nvals )
1898
1999 result = intersection (graph , automata )
20100
21101 intersection_end = time .perf_counter ()
22102 print ("Graph and automata intersection competed in " , intersection_end - automata_generation_end )
103+ print ("Vertices in intersection: " , result .ncols )
104+ print ("Edges in intersection: " , result .nvals )
23105
24- return result
106+ return to_label_decomposed_graph (result )
107+
108+
0 commit comments