21
21
22
22
JULIA_COMMAND = ["julia" , "--color=yes" , "--project=." , "main.jl" ]
23
23
24
+
25
+ def try_float (value ):
26
+ try :
27
+ return float (value )
28
+ except ValueError :
29
+ return value
30
+
31
+
24
32
def run_and_capture (command ):
25
33
"""Run a command and capture its output."""
26
34
result = sp .run (command , text = True , check = True , stdout = sp .PIPE )
@@ -80,7 +88,7 @@ def run_ad(args):
80
88
print (f"Running { model_key } with { adtype } ..." )
81
89
try :
82
90
output = run_and_capture ([* RUN_JULIA_COMMAND , "--run" , model_key , adtype ])
83
- result = output .splitlines ()[- 1 ]
91
+ result = try_float ( output .splitlines ()[- 1 ])
84
92
except sp .CalledProcessError as e :
85
93
result = "error"
86
94
@@ -116,13 +124,6 @@ def get_model_definition(model_key):
116
124
return "\n " .join (lines )
117
125
118
126
119
- def try_float (value ):
120
- try :
121
- return float (value )
122
- except ValueError :
123
- return value
124
-
125
-
126
127
def html (_args ):
127
128
web_dir = Path (__file__ ).parent / "web"
128
129
json_output_dirs = [web_dir / "src" / "data" , web_dir / "public" ]
@@ -149,11 +150,7 @@ def html(_args):
149
150
# We do some processing to turn it into a dict of dicts, then dump it
150
151
# to the website
151
152
results = json .loads (results )
152
- new_data = {}
153
- for entry in results :
154
- model_name = entry ["model_name" ]
155
- results = {k : try_float (v ) for k , v in entry ["results" ].items ()}
156
- new_data [model_name ] = results
153
+ new_data = {entry ["model_name" ]: entry ["results" ] for entry in results }
157
154
for dir in json_output_dirs :
158
155
with open (dir / "adtests.json" , "w" ) as f :
159
156
json .dump (new_data , f , indent = 2 )
0 commit comments