Skip to content

Commit bf6cf2b

Browse files
committed
added functionality to not save graph attributes to rule trace making it more memory efficient
1 parent f81243d commit bf6cf2b

File tree

6 files changed

+83
-48
lines changed

6 files changed

+83
-48
lines changed

pyreason/pyreason.py

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def __init__(self):
2929
self.__memory_profile = False
3030
self.__reverse_digraph = False
3131
self.__atom_trace = False
32+
self.__save_graph_attributes_to_trace = False
3233

3334
@property
3435
def verbose(self) -> bool:
@@ -94,7 +95,16 @@ def atom_trace(self) -> bool:
9495
9596
:return: bool
9697
"""
97-
return self.__atom_trace
98+
return self.__atom_trace
99+
100+
@property
101+
def save_graph_attributes_to_trace(self) -> bool:
102+
"""Returns whether to save the graph attribute facts to the rule trace. Graphs are large and turning this on can result in more memory usage.
103+
NOTE: Turning this on may increase memory usage
104+
105+
:return: bool
106+
"""
107+
return self.__save_graph_attributes_to_trace
98108

99109
@verbose.setter
100110
def verbose(self, value: bool) -> None:
@@ -137,7 +147,7 @@ def output_file_name(self, file_name: str) -> None:
137147
def graph_attribute_parsing(self, value: bool) -> None:
138148
"""Whether to parse graphml file for attributes. Default is True
139149
140-
:param file_name: Whether to parse graphml or not
150+
:param value: Whether to parse graphml or not
141151
:raises TypeError: If not bool raise error
142152
"""
143153
if not isinstance(value, bool):
@@ -149,7 +159,7 @@ def graph_attribute_parsing(self, value: bool) -> None:
149159
def abort_on_inconsistency(self, value: bool) -> None:
150160
"""Whether to abort program if inconsistency is found. Default is False
151161
152-
:param file_name: Whether to abort on inconsistency or not
162+
:param value: Whether to abort on inconsistency or not
153163
:raises TypeError: If not bool raise error
154164
"""
155165
if not isinstance(value, bool):
@@ -161,7 +171,7 @@ def abort_on_inconsistency(self, value: bool) -> None:
161171
def memory_profile(self, value: bool) -> None:
162172
"""Whether to profile the program's memory usage. Default is False
163173
164-
:param file_name: Whether to profile program's memory usage or not
174+
:param value: Whether to profile program's memory usage or not
165175
:raises TypeError: If not bool raise error
166176
"""
167177
if not isinstance(value, bool):
@@ -174,7 +184,7 @@ def reverse_digraph(self, value: bool) -> None:
174184
"""Whether to reverse the digraph. if the graphml contains an edge: a->b
175185
setting reverse as true will make the edge b->a. Default is False
176186
177-
:param file_name: Whether to reverse graphml edges or not
187+
:param value: Whether to reverse graphml edges or not
178188
:raises TypeError: If not bool raise error
179189
"""
180190
if not isinstance(value, bool):
@@ -187,13 +197,26 @@ def atom_trace(self, value: bool) -> None:
187197
"""Whether to save all atoms that were responsible for the firing of a rule.
188198
NOTE: this can be very memory heavy. Default is False
189199
190-
:param file_name: Whether to save all atoms or not
200+
:param value: Whether to save all atoms or not
191201
:raises TypeError: If not bool raise error
192202
"""
193203
if not isinstance(value, bool):
194204
raise TypeError('value has to be a bool')
195205
else:
196206
self.__atom_trace = value
207+
208+
@save_graph_attributes_to_trace.setter
209+
def save_graph_attributes_to_trace(self, value: bool) -> None:
210+
"""Whether to save all graph attribute facts. Graphs are large so turning this on can be memory heavy
211+
NOTE: this can be very memory heavy. Default is False
212+
213+
:param value: Whether to save all graph attribute facts in the trace or not
214+
:raises TypeError: If not bool raise error
215+
"""
216+
if not isinstance(value, bool):
217+
raise TypeError('value has to be a bool')
218+
else:
219+
self.__save_graph_attributes_to_trace = value
197220

198221
# VARIABLES
199222
__graph = None
@@ -339,7 +362,7 @@ def _reason(timesteps, convergence_threshold, convergence_bound_threshold):
339362
__edge_facts.extend(__non_fluent_graph_facts_edge)
340363

341364
# Setup logical program
342-
program = Program(__graph, timesteps, __node_facts, __edge_facts, __rules, __ipl, settings.reverse_digraph, settings.atom_trace)
365+
program = Program(__graph, timesteps, __node_facts, __edge_facts, __rules, __ipl, settings.reverse_digraph, settings.atom_trace, settings.save_graph_attributes_to_trace)
343366
program.available_labels_node = __node_labels
344367
program.available_labels_edge = __edge_labels
345368
program.specific_node_labels = __specific_node_labels

pyreason/scripts/args.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ def argparser():
3838
# Rule trace with ground atoms (not done)
3939
parser.add_argument("--atom_trace", dest='atom_trace', action='store_true', help='Option to track the ground atoms which lead to a rule firing. This could be very memory heavy. Default is off')
4040
parser.set_defaults(atom_trace=False)
41+
parser.add_argument("--save_graph_attributes_to_trace", dest='save_graph_attributes_to_trace', action='store_true', help='Option to save graph attributes to trace. Graphs are big and turning this on can be very memory heavy. Graph attributes are represented as facts. Default is off')
42+
parser.set_defaults(save_graph_attributes_to_trace=False)
4143
# Convergence options
4244
parser.add_argument("--convergence_threshold", type=int, default=-1, help='Number of interpretations that have changed between timesteps or fixed point operations until considered convergent. Program will end at convergence. -1 => Perfect convergence. This option is default')
4345
parser.add_argument("--convergence_bound_threshold", type=float, default=-1, help='Max change in any interpretation between timesteps or fixed point operations until considered convergent. Program will end at convergence. --convergence_threshold is default')

pyreason/scripts/diffuse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def main(args):
6060
ipl = yaml_parser.parse_ipl(args.ipl_yaml_path)
6161

6262
# Program comes here
63-
program = Program(graph, tmax, facts_node, facts_edge, rules, ipl, args.reverse_digraph, args.atom_trace)
63+
program = Program(graph, tmax, facts_node, facts_edge, rules, ipl, args.reverse_digraph, args.atom_trace, args.save_graph_attributes_to_trace)
6464
program.available_labels_node = node_labels
6565
program.available_labels_edge = edge_labels
6666
program.specific_node_labels = specific_node_labels

0 commit comments

Comments
 (0)