311 in prover params (K (K (K ""))) problem end |
311 in prover params (K (K (K ""))) problem end |
312 |
312 |
313 |
313 |
314 (*** Low-level communication with MaSh ***) |
314 (*** Low-level communication with MaSh ***) |
315 |
315 |
316 fun write_file write file = |
316 fun write_file (xs, f) file = |
317 let val path = Path.explode file in |
317 let val path = Path.explode file in |
318 File.write path ""; write (File.append path) |
318 File.write path ""; |
|
319 xs |> chunk_list 500 |
|
320 |> List.app (File.append path o space_implode "" o map f) |
319 end |
321 end |
320 |
322 |
321 fun mash_info overlord = |
323 fun mash_info overlord = |
322 if overlord then (getenv "ISABELLE_HOME_USER", "") |
324 if overlord then (getenv "ISABELLE_HOME_USER", "") |
323 else (getenv "ISABELLE_TMP", serial_string ()) |
325 else (getenv "ISABELLE_TMP", serial_string ()) |
329 val command = |
331 val command = |
330 mash_home () ^ "/mash.py --quiet --outputDir " ^ mash_state_dir () ^ |
332 mash_home () ^ "/mash.py --quiet --outputDir " ^ mash_state_dir () ^ |
331 " --log " ^ log_file ^ " " ^ core ^ " 2>&1 > " ^ err_file |
333 " --log " ^ log_file ^ " " ^ core ^ " 2>&1 > " ^ err_file |
332 in |
334 in |
333 trace_msg ctxt (fn () => "Running " ^ command); |
335 trace_msg ctxt (fn () => "Running " ^ command); |
334 write_file (K ()) log_file; |
336 write_file ([], K "") log_file; |
335 write_file (K ()) err_file; |
337 write_file ([], K "") err_file; |
336 Isabelle_System.bash command; () |
338 Isabelle_System.bash command; () |
337 end |
339 end |
338 |
340 |
339 fun run_mash_init ctxt overlord write_access write_feats write_deps = |
341 fun run_mash_init ctxt overlord write_access write_feats write_deps = |
340 let |
342 let |
352 let |
354 let |
353 val info as (temp_dir, serial) = mash_info overlord |
355 val info as (temp_dir, serial) = mash_info overlord |
354 val sugg_file = temp_dir ^ "/mash_suggs" ^ serial |
356 val sugg_file = temp_dir ^ "/mash_suggs" ^ serial |
355 val cmd_file = temp_dir ^ "/mash_commands" ^ serial |
357 val cmd_file = temp_dir ^ "/mash_commands" ^ serial |
356 in |
358 in |
357 write_file (K ()) sugg_file; |
359 write_file ([], K "") sugg_file; |
358 write_file write_cmds cmd_file; |
360 write_file write_cmds cmd_file; |
359 run_mash ctxt info |
361 run_mash ctxt info |
360 ("--inputFile " ^ cmd_file ^ " --predictions " ^ sugg_file ^ |
362 ("--inputFile " ^ cmd_file ^ " --predictions " ^ sugg_file ^ |
361 " --numberOfPredictions " ^ string_of_int max_suggs ^ |
363 " --numberOfPredictions " ^ string_of_int max_suggs ^ |
362 (if save then " --saveModel" else "")); |
364 (if save then " --saveModel" else "")); |
383 |
385 |
384 fun mash_INIT ctxt _ [] = mash_RESET ctxt |
386 fun mash_INIT ctxt _ [] = mash_RESET ctxt |
385 | mash_INIT ctxt overlord upds = |
387 | mash_INIT ctxt overlord upds = |
386 (trace_msg ctxt (fn () => "MaSh INIT " ^ |
388 (trace_msg ctxt (fn () => "MaSh INIT " ^ |
387 elide_string 1000 (space_implode " " (map #1 upds))); |
389 elide_string 1000 (space_implode " " (map #1 upds))); |
388 run_mash_init ctxt overlord |
390 run_mash_init ctxt overlord (upds, init_str_of_update #2) |
389 (fn append => List.app (append o init_str_of_update #2) upds) |
391 (upds, init_str_of_update #3) (upds, init_str_of_update #4)) |
390 (fn append => List.app (append o init_str_of_update #3) upds) |
|
391 (fn append => List.app (append o init_str_of_update #4) upds)) |
|
392 |
392 |
393 fun mash_ADD _ _ [] = () |
393 fun mash_ADD _ _ [] = () |
394 | mash_ADD ctxt overlord upds = |
394 | mash_ADD ctxt overlord upds = |
395 (trace_msg ctxt (fn () => "MaSh ADD " ^ |
395 (trace_msg ctxt (fn () => "MaSh ADD " ^ |
396 elide_string 1000 (space_implode " " (map #1 upds))); |
396 elide_string 1000 (space_implode " " (map #1 upds))); |
397 run_mash_commands ctxt overlord true 0 |
397 run_mash_commands ctxt overlord true 0 (upds, str_of_update) (K ())) |
398 (fn append => List.app (append o str_of_update) upds) (K ())) |
|
399 |
398 |
400 fun mash_QUERY ctxt overlord max_suggs (query as (_, feats)) = |
399 fun mash_QUERY ctxt overlord max_suggs (query as (_, feats)) = |
401 (trace_msg ctxt (fn () => "MaSh QUERY " ^ space_implode " " feats); |
400 (trace_msg ctxt (fn () => "MaSh QUERY " ^ space_implode " " feats); |
402 run_mash_commands ctxt overlord false max_suggs |
401 run_mash_commands ctxt overlord false max_suggs |
403 (fn append => append (str_of_query query)) |
402 ([query], str_of_query) |
404 (fn suggs => snd (extract_query (List.last (suggs ())))) |
403 (fn suggs => snd (extract_query (List.last (suggs ())))) |
405 handle List.Empty => []) |
404 handle List.Empty => []) |
406 |
405 |
407 |
406 |
408 (*** High-level communication with MaSh ***) |
407 (*** High-level communication with MaSh ***) |