Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit492b6d4

Browse files
authored
Fix documentation (#81)
* update requirements* fix names in to_dot* doc* fix doc* doc* fix doc* doc
1 parentdcc2ddd commit492b6d4

File tree

7 files changed

+44
-23
lines changed

7 files changed

+44
-23
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

‎_doc/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
"ast":"https://docs.python.org/3/library/ast.html",
118118
"cProfile.Profile":"https://docs.python.org/3/library/profile.html#profile.Profile",
119119
"DOT":"https://graphviz.org/doc/info/lang.html",
120+
"Graphviz":"https://graphviz.org/",
120121
"inner API":"https://onnx.ai/onnx/intro/python.html",
121122
"JIT":"https://en.wikipedia.org/wiki/Just-in-time_compilation",
122123
"onnx":"https://onnx.ai/onnx/",

‎_doc/tutorial/onnx_api.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ the true implementation would be the following.
7171
n2 = oh.make_node("Pow", ["dxy", "two"], ["dxy2"])
7272
n3 = oh.make_node("ReduceSum", ["dxy2"], [output_name])
7373
graph = oh.make_graph([n1, n2, n3], "euclidian", [X, Y], [Z], [two])
74-
model = oh.make_model(graph, opset_imports=[oh.make_opsetid("", opset)])
74+
model = oh.make_model(
75+
graph,
76+
opset_imports=[oh.make_opsetid("", opset)],
77+
ir_version=9,
78+
)
7579
return model
7680

7781

‎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
defdot_name(text):
119-
returntext.replace("/","_").replace(":","__").replace(".","_")
119+
return (
120+
text.replace("/","_")
121+
.replace(":","__")
122+
.replace(".","_")
123+
.replace("-","_")
124+
)
120125

121126
defdot_label(text):
122127
iftextisNone:

‎onnx_array_api/plotting/graphviz_helper.py

Lines changed: 24 additions & 16 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-
ifraise_exception:
96+
iferrorandraise_exception:
9697
raiseRuntimeError(
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-
returnoutput
101+
returnoutput+"\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
ifos.path.exists(image):
136138
os.remove(image)
137-
output=_run_subprocess([exe,f"-T{ext[1:]}",filename,"-o",image])
138-
assertos.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+
assertos.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
returnoutput
140146

141147

@@ -190,23 +196,25 @@ def plot_dot(
190196
:param image: output image, None, just returns the output
191197
:param engine: *dot* or *neato*
192198
: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
195200
196201
.. plot::
197202
198203
import matplotlib.pyplot as plt
199204
import onnx.parser
205+
from onnx_array_api.plotting.graphviz_helper import plot_dot
200206
201207
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)
210218
ax.set_title("Dummy graph")
211219
plt.show()
212220
"""

‎onnx_array_api/reference/evaluator_yield.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,9 @@ def enumerate_summarized(
237237
Executes the onnx model and enumerate intermediate results without their names.
238238
239239
:param output_names: requested outputs by names, None for all
240-
:param feed_inputs: dictionary `{ input name: input value }`
241-
:param raise_exc: raises an exception if the execution fails or stop
242-
where it is
243-
:param keep_tensor:keep the tensor in order to compute precise distances
240+
:param feed_inputs: dictionary ``{ input name: input value }``
241+
:param raise_exc: raises an exception if the execution fails or stop where it is
242+
:param keep_tensor: keep the tensor in order to compute precise distances
244243
:return: iterator on ResultExecution
245244
"""
246245
forkind,name,value,op_typeinself.enumerate_results(

‎onnx_array_api/validation/docs.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ def make_euclidean(
3030
n2=oh.make_node("Pow", ["dxy","two"], ["dxy2"])
3131
n3=oh.make_node("ReduceSum", ["dxy2"], [output_name])
3232
graph=oh.make_graph([n1,n2,n3],"euclidian", [X,Y], [Z], [two])
33-
model=oh.make_model(graph,opset_imports=[oh.make_opsetid("",opset)])
33+
model=oh.make_model(
34+
graph,opset_imports=[oh.make_opsetid("",opset)],ir_version=9
35+
)
3436
returnmodel
3537

3638

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp