src/HOL/Tools/Sledgehammer/sledgehammer_mash.ML
changeset 50310 b00eeb8e352e
parent 50229 78f3be5e51d2
child 50311 c9d7ccd090e1
equal deleted inserted replaced
50309:38870ee59311 50310:b00eeb8e352e
    99 val learn_isarN = "learn_isar"
    99 val learn_isarN = "learn_isar"
   100 val learn_atpN = "learn_atp"
   100 val learn_atpN = "learn_atp"
   101 val relearn_isarN = "relearn_isar"
   101 val relearn_isarN = "relearn_isar"
   102 val relearn_atpN = "relearn_atp"
   102 val relearn_atpN = "relearn_atp"
   103 
   103 
   104 fun mash_home () = getenv "ISABELLE_SLEDGEHAMMER_MASH"
   104 fun mash_script () = Path.explode "$ISABELLE_SLEDGEHAMMER_MASH/src/mash.py"
   105 fun mash_model_dir () =
   105 fun mash_model_dir () =
   106   getenv "ISABELLE_HOME_USER" ^ "/mash"
   106   Path.explode "$ISABELLE_HOME_USER/mash"
   107   |> tap (Isabelle_System.mkdir o Path.explode)
   107   |> tap Isabelle_System.mkdir
   108 val mash_state_dir = mash_model_dir
   108 val mash_state_dir = mash_model_dir
   109 fun mash_state_file () = mash_state_dir () ^ "/state"
   109 fun mash_state_file () = Path.append (mash_state_dir ()) (Path.explode "state")
   110 
   110 
   111 
   111 
   112 (*** Isabelle helpers ***)
   112 (*** Isabelle helpers ***)
   113 
   113 
   114 fun meta_char c =
   114 fun meta_char c =
   444     val core =
   444     val core =
   445       "--inputFile " ^ cmd_file ^ " --predictions " ^ sugg_file ^
   445       "--inputFile " ^ cmd_file ^ " --predictions " ^ sugg_file ^
   446       " --numberOfPredictions " ^ string_of_int max_suggs ^
   446       " --numberOfPredictions " ^ string_of_int max_suggs ^
   447       (if save then " --saveModel" else "")
   447       (if save then " --saveModel" else "")
   448     val command =
   448     val command =
   449       mash_home () ^ "/src/mash.py --quiet --outputDir " ^ mash_model_dir () ^
   449       Path.implode (mash_script ()) ^ " --quiet --outputDir " ^
   450       " --log " ^ log_file ^ " " ^ core ^ " >& " ^ err_file
   450       Path.implode (mash_model_dir ()) ^ " --log " ^ log_file ^ " " ^ core ^
       
   451       " >& " ^ err_file
   451       |> tap (fn _ => trace_msg ctxt (fn () =>
   452       |> tap (fn _ => trace_msg ctxt (fn () =>
   452              case try File.read (Path.explode err_file) of
   453              case try File.read (Path.explode err_file) of
   453                NONE => "Done"
   454                NONE => "Done"
   454              | SOME "" => "Done"
   455              | SOME "" => "Done"
   455              | SOME s => "Error: " ^ elide_string 1000 s))
   456              | SOME s => "Error: " ^ elide_string 1000 s))
   476 
   477 
   477 fun str_of_query (parents, feats) =
   478 fun str_of_query (parents, feats) =
   478   "? " ^ escape_metas parents ^ "; " ^ escape_metas feats ^ "\n"
   479   "? " ^ escape_metas parents ^ "; " ^ escape_metas feats ^ "\n"
   479 
   480 
   480 fun mash_CLEAR ctxt =
   481 fun mash_CLEAR ctxt =
   481   let val path = mash_model_dir () |> Path.explode in
   482   let val path = mash_model_dir () in
   482     trace_msg ctxt (K "MaSh CLEAR");
   483     trace_msg ctxt (K "MaSh CLEAR");
   483     File.fold_dir (fn file => fn _ =>
   484     File.fold_dir (fn file => fn _ =>
   484                       try File.rm (Path.append path (Path.basic file)))
   485                       try File.rm (Path.append path (Path.basic file)))
   485                   path NONE;
   486                   path NONE;
   486     ()
   487     ()
   550 
   551 
   551 val version = "*** MaSh 0.0 ***"
   552 val version = "*** MaSh 0.0 ***"
   552 
   553 
   553 fun load _ (state as (true, _)) = state
   554 fun load _ (state as (true, _)) = state
   554   | load ctxt _ =
   555   | load ctxt _ =
   555     let val path = mash_state_file () |> Path.explode in
   556     let val path = mash_state_file () in
   556       (true,
   557       (true,
   557        case try File.read_lines path of
   558        case try File.read_lines path of
   558          SOME (version' :: node_lines) =>
   559          SOME (version' :: node_lines) =>
   559          let
   560          let
   560            fun add_edge_to name parent =
   561            fun add_edge_to name parent =
   589         case dirty of
   590         case dirty of
   590           SOME names =>
   591           SOME names =>
   591           (NONE, fold (append_entry o Graph.get_entry fact_G) names [])
   592           (NONE, fold (append_entry o Graph.get_entry fact_G) names [])
   592         | NONE => (SOME (version ^ "\n"), Graph.fold append_entry fact_G [])
   593         | NONE => (SOME (version ^ "\n"), Graph.fold append_entry fact_G [])
   593     in
   594     in
   594       write_file banner (entries, str_of_entry) (mash_state_file ());
   595       write_file banner (entries, str_of_entry)
       
   596                  (Path.implode (mash_state_file ()));
   595       trace_msg ctxt (fn () =>
   597       trace_msg ctxt (fn () =>
   596           "Saved fact graph (" ^ graph_info fact_G ^
   598           "Saved fact graph (" ^ graph_info fact_G ^
   597           (case dirty of
   599           (case dirty of
   598              SOME dirty =>
   600              SOME dirty =>
   599              "; " ^ string_of_int (length dirty) ^ " dirty fact(s)"
   601              "; " ^ string_of_int (length dirty) ^ " dirty fact(s)"