@@ -73,7 +73,7 @@ def _run_subprocess(
73
73
shell = False ,
74
74
env = os .environ ,
75
75
stdout = subprocess .PIPE ,
76
- stderr = subprocess .STDOUT ,
76
+ stderr = subprocess .PIPE ,
77
77
)
78
78
raise_exception = False
79
79
output = ""
@@ -91,12 +91,14 @@ def _run_subprocess(
91
91
):
92
92
raise_exception = True
93
93
p .poll ()
94
+ error = p .stderr .readline ().decode (errors = "ignore" )
94
95
p .stdout .close ()
95
- if raise_exception :
96
+ if error and raise_exception :
96
97
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 } "
98
100
)
99
- return output
101
+ return output + " \n " + error
100
102
101
103
102
104
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:
134
136
exe = engine
135
137
if os .path .exists (image ):
136
138
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
+ )
139
145
return output
140
146
141
147
@@ -190,23 +196,25 @@ def plot_dot(
190
196
:param image: output image, None, just returns the output
191
197
:param engine: *dot* or *neato*
192
198
:param figsize: figsize of ax is None
193
- :return: :epkg:`Graphviz` output or
194
- the dot text if *image* is None
199
+ :return: :epkg:`Graphviz` output or, the dot text if *image* is None
195
200
196
201
.. plot::
197
202
198
203
import matplotlib.pyplot as plt
199
204
import onnx.parser
205
+ from onnx_array_api.plotting.graphviz_helper import plot_dot
200
206
201
207
model = onnx.parser.parse_model(
202
- '''
203
- <ir_version: 8, opset_import: [ "": 18]>
204
- agraph (float[N] x) => (float[N] z) {
205
- two = Constant <value_float=2.0> ()
206
- four = Add(two, two)
207
- z = Mul(four, four)
208
- }''')
209
- ax = plot_dot(dot)
208
+ '''
209
+ <ir_version: 8, opset_import: [ "": 18]>
210
+ agraph (float[N] x) => (float[N] z) {
211
+ two = Constant <value_float=2.0> ()
212
+ four = Add(two, two)
213
+ z = Mul(four, four)
214
+ }
215
+ ''')
216
+
217
+ ax = plot_dot(model)
210
218
ax.set_title("Dummy graph")
211
219
plt.show()
212
220
"""
0 commit comments