-
Notifications
You must be signed in to change notification settings - Fork 0
/
vis_tot_graph.py
46 lines (40 loc) · 1.58 KB
/
vis_tot_graph.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import pickle
#from ToT_Exp import MyChecker
# Load the object from a file
class IgnoreMissingClassUnpickler(pickle.Unpickler):
def find_class(self, module, name):
try:
return super().find_class(module, name)
except (AttributeError, ModuleNotFoundError):
# Provide a default implementation or a dummy class
return type('MissingClass', (object,), {})
# Load the object using the custom unpickler
with open('classtree.pkl', 'rb') as file:
loaded_object = IgnoreMissingClassUnpickler(file).load()
# Use the loaded object
print(loaded_object) # This will print an instance of MissingClass if the original class is not found
tot_chain = loaded_object
breakpoint()
import pygraphviz as pgv
def add_nodes_edges(graph, level):
if len(tot_chain.tot_memory.stack[level].children) == 0:
return
node_data = tot_chain.tot_memory.stack[level]
label = node_data.text
graph.add_node(level, label=label, shape='box', style='filled', fillcolor='lightyellow', color='black')
children = node_data.children
for child, child_data in children.items():
add_nodes_edges(graph, child)
graph.add_edge(level, child)
# Create a new graph
G = pgv.AGraph(directed=True)
# Add the root node with a textbox style
root = 0 # Assuming the root is at level 0
root_data = tot_chain.tot_memory.stack[root]
root_label = root_data.text
G.add_node(root, label=root_label, shape='box', style='filled', fillcolor='lightyellow', color='black')
add_nodes_edges(G, root)
# Layout and render the graph
G.layout(prog='dot')
G.draw('tree.png')
#######