Skip to content

Commit 1feac72

Browse files
committed
fix names in to_dot
1 parent 3770528 commit 1feac72

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

_doc/api/plotting.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Dot
66

77
.. autofunction:: onnx_array_api.plotting.dot_plot.to_dot
88

9+
.. autofunction:: onnx_array_api.plotting.graphviz_helper.plot_dot
10+
911
Statistics
1012
++++++++++
1113

onnx_array_api/plotting/dot_plot.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,12 @@ def myloss(x, y):
116116
clean_label_reg2 = re.compile("\\\\p\\{[0-9P]{1,6}\\}")
117117

118118
def dot_name(text):
119-
return text.replace("/", "_").replace(":", "__").replace(".", "_")
119+
return (
120+
text.replace("/", "_")
121+
.replace(":", "__")
122+
.replace(".", "_")
123+
.replace("-", "_")
124+
)
120125

121126
def dot_label(text):
122127
if text is None:

onnx_array_api/plotting/graphviz_helper.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def _run_subprocess(
7373
shell=False,
7474
env=os.environ,
7575
stdout=subprocess.PIPE,
76-
stderr=subprocess.STDOUT,
76+
stderr=subprocess.PIPE,
7777
)
7878
raise_exception = False
7979
output = ""
@@ -91,12 +91,14 @@ def _run_subprocess(
9191
):
9292
raise_exception = True
9393
p.poll()
94+
error = p.stderr.readline().decode(errors="ignore")
9495
p.stdout.close()
95-
if raise_exception:
96+
if error and raise_exception:
9697
raise RuntimeError(
97-
"An error was found in the output. The build is stopped.\n{output}"
98+
f"An error was found in the output. The build is stopped."
99+
f"\n{output}\n---\n{error}"
98100
)
99-
return output
101+
return output + "\n" + error
100102

101103

102104
def _run_graphviz(filename: str, image: str, engine: str = "dot") -> str:
@@ -134,8 +136,12 @@ def _run_graphviz(filename: str, image: str, engine: str = "dot") -> str:
134136
exe = engine
135137
if os.path.exists(image):
136138
os.remove(image)
137-
output = _run_subprocess([exe, f"-T{ext[1:]}", filename, "-o", image])
138-
assert os.path.exists(image), f"Graphviz failed due to {output}"
139+
cmd = [exe, f"-T{ext[1:]}", filename, "-o", image]
140+
output = _run_subprocess(cmd)
141+
assert os.path.exists(image), (
142+
f"Unable to find {image!r}, command line is "
143+
f"{' '.join(cmd)!r}, Graphviz failed due to\n{output}"
144+
)
139145
return output
140146

141147

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy