mirror of
https://github.com/VLSIDA/OpenRAM.git
synced 2026-08-29 09:30:38 +02:00
Added graph store and read functionality
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import copy
|
||||
from collections import defaultdict
|
||||
import debug
|
||||
import json
|
||||
|
||||
|
||||
class timing_graph():
|
||||
@@ -139,6 +140,35 @@ class timing_graph():
|
||||
|
||||
return [self.edge_mods[(path[i], path[i+1])] for i in range(len(path)-1)]
|
||||
|
||||
def write(self, filename):
|
||||
"""
|
||||
Export graph to a JSON file
|
||||
"""
|
||||
# TODO: Find a proper way to store edge_mods values
|
||||
with open(filename, 'w') as f:
|
||||
f.write(
|
||||
json.dumps(
|
||||
{
|
||||
'graph':
|
||||
{key: list(val) for key, val in self.graph.items()},
|
||||
'edge_mods':
|
||||
{
|
||||
', '.join(key): str(value)
|
||||
for key, value in self.edge_mods.items()
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
def read(self, filename):
|
||||
"""
|
||||
Read graph from JSON file
|
||||
"""
|
||||
with open(filename, 'r') as f:
|
||||
d = json.loads(f.read())
|
||||
self.graph = {key: set(value) for key, value in d['graph'].items()}
|
||||
self.edge_mods = {tuple(key.split(', ')): value for key, value in d['edge_mods'].items()}
|
||||
|
||||
def __str__(self):
|
||||
""" override print function output """
|
||||
|
||||
|
||||
Reference in New Issue
Block a user