Skip to content

Commit 21d6020

Browse files
committed
Transitive reduction is optional.
1 parent 3a9b894 commit 21d6020

File tree

2 files changed

+27
-30
lines changed

2 files changed

+27
-30
lines changed

cfpq_add_context/add_contexts.py

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,19 @@ def transitive_reduction(assigns, vertices_with_other_edges):
2929
endpoints = vertices_with_other_edges.diag(name = "endpoints")
3030
assigns_transposed = Matrix(BOOL, assigns.ncols, assigns.ncols, name = "assigns_transposed")
3131
assigns_transposed("any") << assigns.T
32-
frontier = vertices_with_other_edges.diag(name = "frontier")
33-
#filter("any") << frontier
32+
frontier = vertices_with_other_edges.diag(name = "frontier")
3433
visited = Matrix(BOOL, assigns.ncols, assigns.ncols, name = "visited")
3534
visited("any") << frontier
3635
while True:
37-
print ("Frontier nvals = ", frontier.nvals)
38-
#print("Frontier: ", frontier)
36+
print ("Frontier nvals = ", frontier.nvals)
3937
if frontier.nvals == 0:
4038
break
4139
new_frontier = Matrix(BOOL, assigns.ncols, assigns.ncols, name = "new_frontier")
42-
new_frontier(~visited.S) << Matrix.mxm(frontier, assigns, "any_pair")
43-
#print("New frontier: ", new_frontier)
44-
filter = Matrix(BOOL, assigns.ncols, assigns.ncols, name = "filter")
45-
#print("Endpoints: ", endpoints)
40+
new_frontier(~visited.S) << Matrix.mxm(frontier, assigns, "any_pair")
41+
filter = Matrix(BOOL, assigns.ncols, assigns.ncols, name = "filter")
4642
x = new_frontier.reduce_rowwise("any").diag()
4743
filter(~x.S) << endpoints
4844

49-
#print("Filter: ", filter)
50-
#to_result = Matrix(BOOL, assigns.ncols, assigns.ncols, name = "to_result")
51-
#to_result << (Matrix.mxm(new_frontier, filter, "any_pair"))
52-
#print("To result: ", to_result)
53-
5445
result("any") << (Matrix.mxm(new_frontier, filter, "any_pair"))
5546

5647
print ("Result nvals = ", result.nvals)
@@ -59,12 +50,12 @@ def transitive_reduction(assigns, vertices_with_other_edges):
5950

6051
new_frontier_2 = Matrix(BOOL, assigns.ncols, assigns.ncols, name = "new_frontier_2")
6152
new_frontier_2(~result.S) << new_frontier
62-
#print("New frontier 2: ", new_frontier_2)
53+
6354
frontier = new_frontier_2
6455

6556
return result
6657

67-
def to_label_decomposed_graph(graph, automata_size, initial_graph_size):
58+
def to_label_decomposed_graph(graph, automata_size, initial_graph_size, do_transitive_reduction=False):
6859
vertex_count = graph.nrows
6960
alloc = Matrix(BOOL, graph.ncols, graph.nrows, name = "alloc_after_intersection")
7061
alloc << graph.select(graphblas.select.select_alloc)
@@ -74,11 +65,11 @@ def to_label_decomposed_graph(graph, automata_size, initial_graph_size):
7465
alloc_r << alloc.T
7566
print("Boolean matrix for alloc_r nvals: ", alloc_r.nvals)
7667

77-
print("mask start")
78-
mask_v = Vector(BOOL, graph.ncols, name = "mask_vector")
79-
####exit_mask_v = Vector(BOOL, graph.ncols, name = "exit_mask_vector")
80-
mask_v("any") << alloc.reduce_columnwise("any")
81-
mask_v("any") << alloc.reduce_rowwise("any")
68+
if (do_transitive_reduction):
69+
print("mask start")
70+
mask_v = Vector(BOOL, graph.ncols, name = "mask_vector")
71+
mask_v("any") << alloc.reduce_columnwise("any")
72+
mask_v("any") << alloc.reduce_rowwise("any")
8273

8374
print("entrypoints start")
8475

@@ -97,11 +88,12 @@ def to_label_decomposed_graph(graph, automata_size, initial_graph_size):
9788
store_i << graph.select(graphblas.select.select_store).apply(graphblas.unary.decode_store)
9889
print("Matrix for store_i nvals: ", store_i.nvals)
9990

100-
mask_v("any") << load_i.reduce_columnwise("any")
101-
mask_v("any") << load_i.reduce_rowwise("any")
91+
if (do_transitive_reduction):
92+
mask_v("any") << load_i.reduce_columnwise("any")
93+
mask_v("any") << load_i.reduce_rowwise("any")
10294

103-
mask_v("any") << store_i.reduce_columnwise("any")
104-
mask_v("any") << store_i.reduce_rowwise("any")
95+
mask_v("any") << store_i.reduce_columnwise("any")
96+
mask_v("any") << store_i.reduce_rowwise("any")
10597

10698
store_block_count = store_i.reduce_scalar("max").get(0) + 1
10799
load_block_count = load_i.reduce_scalar("max").get(0) + 1
@@ -136,8 +128,8 @@ def to_label_decomposed_graph(graph, automata_size, initial_graph_size):
136128
assign << graph.select(graphblas.select.select_assign)
137129
print("Boolean matrix for assign nvals: ", assign.nvals)
138130

139-
140-
assign << transitive_reduction(assign, mask_v)
131+
if (do_transitive_reduction):
132+
assign << transitive_reduction(assign, mask_v)
141133

142134
assign_r = Matrix(BOOL, graph.ncols, graph.nrows, name = "assign_r_after_intersection")
143135
assign_r << assign.T
@@ -184,7 +176,7 @@ def get_new_v_id(v_id):
184176
ncols=first_free_v_id, name = "remapped_graph")
185177
return result
186178

187-
def add_context(file_path, max_num_of_contexts, depth):
179+
def add_context(file_path, max_num_of_contexts, depth, do_transitive_reduction):
188180
load_graph_start = time.perf_counter()
189181

190182
graph,number_of_contexts = load_graph(file_path, max_num_of_contexts)
@@ -216,7 +208,7 @@ def add_context(file_path, max_num_of_contexts, depth):
216208
print("Vertices in intersection: ", result.ncols)
217209
print("Edges in intersection: ", result.nvals)
218210

219-
decomposed_result = to_label_decomposed_graph(result, automata.nrows, graph.nrows)
211+
decomposed_result = to_label_decomposed_graph(result, automata.nrows, graph.nrows, do_transitive_reduction)
220212
decomposition_end = time.perf_counter()
221213
print("Graph decomposition completed in ", decomposition_end - vertices_remapping_end)
222214

cfpq_cli/run_all_pairs_cflr.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@ def run_all_pairs_cflr(
2929
expected_path: str = "",
3030
max_num_of_contexts = 30,
3131
trace_graphblas = False,
32+
do_transitive_reduction = False,
3233
depth=1,
3334
):
3435
if trace_graphblas: graphblas.ss.burble.enable()
3536
total_start = time()
3637
algo = get_all_pairs_cfl_reachability_algo(algo_name)
3738
if add_contexts:
38-
graph,initial_graph_nvertices = add_context(graph_path, max_num_of_contexts,depth)
39+
graph,initial_graph_nvertices = add_context(graph_path, max_num_of_contexts, depth, do_transitive_reduction)
3940
else:
4041
graph = LabelDecomposedGraph.read_from_pocr_graph_file(graph_path)
4142
grammar = CnfGrammarTemplate.read_from_pocr_cnf_file(grammar_path)
@@ -108,6 +109,9 @@ def main(raw_args: List[str]):
108109
parser.add_argument('--trace-graphblas', dest='trace_graphblas', default=False,
109110
help='Turn GraphBLAS burble on.'
110111
)
112+
parser.add_argument('--do-transitive-reduction', dest='do_transitive_reduction', default=False,
113+
help='Perform transitive reduction of ASSIGN relation before CFL-r main loop.'
114+
)
111115
parser.add_argument('--expected_path', dest='expected_path', default="",
112116
help='If specified, it will be checked wether solver\'s result is overapproximation of represented in the file.'
113117
)
@@ -124,7 +128,8 @@ def main(raw_args: List[str]):
124128
time_limit_sec=args.time_limit,
125129
out_path=args.out,
126130
max_num_of_contexts=args.max_num_of_contexts,
127-
depth = args.depth,
131+
depth=args.depth,
132+
do_transitive_reduction=args.do_transitive_reduction,
128133
settings=settings_manager.read_args(args)
129134
)
130135
settings_manager.report_unused()

0 commit comments

Comments
 (0)