feat: better iogam

This commit is contained in:
Martino Ferrari
2024-03-12 07:12:16 +01:00
parent 58672bc9d4
commit 432e3d7549
4 changed files with 117 additions and 68 deletions
+1 -2
View File
@@ -7,7 +7,6 @@ Email: martinogiordano.ferrari@iter.org
import json
import logging
import os
import pprint
import sys
from argparse import ArgumentParser
@@ -62,7 +61,7 @@ def main():
f"Impossible to parse file `{args.filename}` at position ({e.line},{e.col}): {e.msg}`"
)
sys.exit(1)
except Exception as e:
except Exception:
logging.error(f"Sometihng went wrong with file `{args.filename}`")
sys.exit(1)
else:
Binary file not shown.
Binary file not shown.
+116 -66
View File
@@ -3,7 +3,6 @@ Autodoc functions
"""
import logging
import os
import sys
__PATH__ = "."
@@ -41,8 +40,16 @@ def __num_bytes__(sig):
noe = 1 if "NumberOfElements" not in sig else int(sig["NumberOfElements"])
nod = 1 if "NumberOfDimensions" not in sig else int(sig["NumberOfDimensions"])
nod = nod if nod > 0 else 1
noe = noe if noe > 0 else 1
bytes = __type_bytes__(sig["Type"])
return noe * nod * bytes
tot = noe * nod
if "Ranges" in sig:
tot = 0
for i0, ie in sig["Ranges"]:
tot += int(ie) - int(i0) + 1
return tot * bytes
def __doc_app_state__(state, tab=""):
@@ -66,7 +73,8 @@ def __sig_type__(sig):
nod = int(sig["NumberOfDimensions"]) if "NumberOfDimensions" in sig else 1
nod = nod if nod > 0 else 1
dim = noe * nod
return (type_name, dim)
range = sig["Ranges"] if "Ranges" in sig else []
return (type_name, dim, range)
def __sig_alias__(name, signal):
@@ -158,59 +166,71 @@ def __doc_iogam__(id, obj, edges, thread):
output_names = list(outputs.keys())
input_names = list(inputs.keys())
j = 0
isize = 0
osize = 0
input_size = 0
output_size = 0
i = 0
irow = ""
orow = ""
while i < len(inputs):
in_label = input_names[i]
input = inputs[in_label]
if irow:
irow += " | "
irow += f"<in_{__sig_name__(in_label)}> {in_label}"
isize += __num_bytes__(input)
i += 1
alias = __sig_alias__(in_label, input)
mtype = __sig_type__(input)
datasrc = input["DataSource"]
edges.append(
__edge__(
__sig__(datasrc, alias, mtype),
__sig__(id, in_label, mtype),
thread,
counter = 0
while i < len(inputs) and j < len(outputs):
irelcount = 0
orelcount = 0
bold = False
while input_size <= output_size and i < len(inputs):
in_label = input_names[i]
input = inputs[in_label]
if irow:
irow += " | "
input_size += __num_bytes__(input)
i += 1
alias = __sig_alias__(in_label, input)
mtype = __sig_type__(input)
if mtype[2]:
bold = True
irow += f"<in_{irelcount}> {__type_to_str__(mtype)}"
datasrc = input["DataSource"]
edges.append(
__edge__(
__sig__(datasrc, alias, mtype),
__sig__(f"{id}_{counter}", f"{irelcount}", mtype),
thread,
)
)
)
while osize < isize and j < len(outputs):
irelcount += 1
while output_size < input_size and j < len(outputs):
out_label = output_names[j]
output = outputs[out_label]
osize += __num_bytes__(output)
output_size += __num_bytes__(output)
if orow:
orow += " | "
orow += f"<out_{__sig_name__(out_label)}> {out_label}"
j += 1
alias = __sig_alias__(out_label, output)
mtype = __sig_type__(output)
if mtype[2]:
bold = True
orow += f"<out_{orelcount}> {__type_to_str__(mtype)}"
datasrc = output["DataSource"]
edges.append(
__edge__(
__sig__(id, out_label, mtype),
__sig__(f"{id}_{counter}", f"{orelcount}", mtype),
__sig__(datasrc, alias, mtype),
thread,
)
)
if isize == osize and irow and orow:
if node:
node += " | "
node += "{ {" + irow + "} | {" + orow + "} }"
irow = ""
orow = ""
if irow or orow:
if node:
node += " | "
orelcount += 1
fill = "#999"
fsize = 14.0
if bold or irelcount > 1 or orelcount > 1:
fill = "#333"
else:
fsize = 8.0
node += f'{id}_{counter} [tooltip=" IOGAM::{id} " label="'
node += "{ {" + irow + "} | {" + orow + "} }"
node += f'", fillcolor="{fill}", color="#666", style=filled,'
node += f' fontcolor="#fff", fontsize={fsize}, height=0];\n'
irow = ""
orow = ""
counter += 1
return node, edges
@@ -222,7 +242,11 @@ def __doc_constgam__(id, obj, edges, thread):
alias = __sig_alias__(l, sig)
mtype = __sig_type__(sig)
edges.append(
__edge__(__sig__(id, l, mtype), __sig__(datasrc, alias, mtype), thread)
__edge__(
__sig__(id, l, mtype),
__sig__(datasrc, alias, mtype),
thread,
)
)
if i != 0:
node += " | "
@@ -241,7 +265,7 @@ def __doc_gam__(label, obj, edges, thread):
if cls == "ConstantGAM":
sigs, datasources = __doc_constgam__(id, obj, edges, thread)
elif cls == "IOGAM":
sigs, datasources = __doc_iogam__(id, obj, edges, thread)
return __doc_iogam__(id, obj, edges, thread)
elif cls == "TriggeredIOGAM":
sigs, datasources = __doc_triggered_iogam__(id, obj, edges, thread)
else:
@@ -255,37 +279,48 @@ def __doc_gam__(label, obj, edges, thread):
def __process_gamds__(name, signals, edges):
node = ""
ok = False
outputs = {}
inputs = {}
for sig_name in signals:
done = False
while not done:
signals = {}
for edge in edges:
if edge[0][0] == name and edge[0][1] == sig_name:
if edge[0][0] == name:
sig_name = edge[0][1]
signals[sig_name] = edge[0][2]
if sig_name not in outputs:
outputs[sig_name] = []
outputs[sig_name].append(edge)
elif edge[1][0] == name and edge[1][1] == sig_name:
elif edge[1][0] == name:
sig_name = edge[1][1]
signals[sig_name] = edge[1][2]
if sig_name not in inputs:
inputs[sig_name] = []
inputs[sig_name].append(edge)
to_reduce = []
to_keep = []
for sig_name in signals:
if sig_name in inputs and sig_name in outputs:
to_reduce.append(sig_name)
else:
to_keep.append(sig_name)
for sig_name in to_reduce:
ins = inputs[sig_name]
outs = outputs[sig_name]
for edge in ins:
edges.remove(edge)
for edge in outs:
edges.remove(edge)
for in_edge in ins:
for out_edge in outs:
edge = (in_edge[0], out_edge[1], in_edge[-1])
edges.append(edge)
to_reduce = []
to_keep = []
done = True
for sig_name in signals:
if sig_name in inputs and sig_name in outputs:
to_reduce.append(sig_name)
else:
to_keep.append(sig_name)
for sig_name in to_reduce:
ins = inputs[sig_name]
outs = outputs[sig_name]
for edge in ins:
if edge in edges:
done = False
edges.remove(edge)
for edge in outs:
if edge in edges:
done = False
edges.remove(edge)
for in_edge in ins:
for out_edge in outs:
edge = (in_edge[0], out_edge[1], in_edge[-1])
edges.append(edge)
for i, sig_name in enumerate(to_keep):
if i > 0:
@@ -346,14 +381,26 @@ def __process_ds__(name, obj, edges):
node += f"<{__sig_name__(sig_name)}> {sig_name} ({__type_to_str__(sig_type)})"
node += '", color=blue];\n'
if not multi_thread and node:
node = f"subgraph cluster_{thread}" + "{" + node + "};"
node = f"subgraph cluster_{thread}" + "{\n" + node + "};\n"
return node, edges
def __type_to_str__(mtype):
range = ""
if mtype[2]:
range = (
"("
+ ", ".join(
[
str(i0) if i0 == i1 else (str(i0) + ":" + str(int(i1) + 1))
for i0, i1 in mtype[2]
]
)
+ ")"
)
if mtype[1] != 1:
return f"{mtype[0]}[{mtype[1]}]"
return mtype[0]
return f"{mtype[0]}[{mtype[1]}]{range}"
return mtype[0] + range
def __process_edges__(edges, datasources):
@@ -387,7 +434,7 @@ def __doc_state__(label, state, app):
graph += "graph [ranksep=2];\n"
graph += "rankdir = LR;\n"
graph += "beautify = true;\n"
graph += "node [shape=record];\n"
graph += "node [shape=Mrecord];\n"
graph += "\n"
arrows = ""
ext = ""
@@ -403,7 +450,10 @@ def __doc_state__(label, state, app):
obj = app["+Functions"][f"+{fn}"]
node, edges = __doc_gam__(fn, obj, edges, tname[1:])
graph += f"{node}\n"
graph += f' label = "{tname[1:]}";\n'
graph += f"\n label = < <B>{tname[1:]}</B> >;\n"
graph += " fontsize = 24.0;\n"
graph += " penwidth = 3;\n"
graph += ' color = "#0A0";\n'
graph += "}\n"
if "+Data" in app:
for key, obj in app["+Data"].items():