src/HOL/Tools/ATP/watcher.ML
changeset 16156 2f6fc19aba1e
parent 16100 f80fc4bff933
child 16185 bb71c91e781e
     1.1 --- a/src/HOL/Tools/ATP/watcher.ML	Tue May 31 12:36:01 2005 +0200
     1.2 +++ b/src/HOL/Tools/ATP/watcher.ML	Tue May 31 12:42:36 2005 +0200
     1.3 @@ -1,4 +1,5 @@
     1.4  (*  Title:      Watcher.ML
     1.5 +
     1.6      ID:         $Id$
     1.7      Author:     Claire Quigley
     1.8      Copyright   2004  University of Cambridge
     1.9 @@ -162,27 +163,28 @@
    1.10  	  val _ = File.append (File.tmp_path (Path.basic"thmstring_in_watcher"))                                                                     
    1.11  	              (thmstring^"\n goals_watched"^(string_of_int(!goals_being_watched))^"\n")
    1.12  	 (*** want to cat clasimp ax hyps prob, then send the resulting file to tptp2x ***)
    1.13 -	  val probID = ReconOrderClauses.last(explode probfile)
    1.14 +	 val probID = ReconOrderClauses.last(explode probfile)
    1.15  	  val wholefile = File.tmp_path (Path.basic ("ax_prob_"^probID))
    1.16  	  (*** only include problem and clasimp for the moment, not sure how to refer to ***)
    1.17 -	  (*** hyps/local axioms just now                                                ***)
    1.18 -          (*FIXME: find a way that works for SML/NJ too: it regards > as a filename!*)
    1.19 -	  val whole_prob_file = Unix.execute("/bin/cat", [clasimpfile,(*,axfile, hypsfile,*)probfile,  ">", (File.sysify_path wholefile)])
    1.20 +
    1.21 +	  (*** hyps/local axioms just now (*,axfile, hypsfile,*)                                               ***)
    1.22 +	  val whole_prob_file = system ("/bin/cat " ^ clasimpfile ^" "^ probfile ^ " > " ^ (File.sysify_path wholefile))
    1.23 +
    1.24  	  val dfg_create = if File.exists dfg_dir 
    1.25  			   then warning("dfg dir exists")
    1.26  			   else File.mkdir dfg_dir; 
    1.27  	  
    1.28  	  val dfg_path = File.sysify_path dfg_dir;
    1.29 -	  val tptp2x_args = ["-fdfg", "-d " ^ dfg_path, File.sysify_path wholefile]
    1.30  	  val exec_tptp2x = 
    1.31 - 	      Unix.execute(getenv "TPTP2X_HOME" ^ "/tptp2X", tptp2x_args)
    1.32 +	        Unix.execute(getenv "TPTP2X_HOME" ^ "/tptp2X",  
    1.33 +	                     ["-fdfg", "-d " ^ dfg_path, File.sysify_path wholefile])
    1.34  	(*val _ = Posix.Process.wait ()*)
    1.35  	(*val _ =Unix.reap exec_tptp2x*)
    1.36  	  val newfile = dfg_path^"/ax_prob"^"_"^(probID)^".dfg"
    1.37   
    1.38         in   
    1.39  	  goals_being_watched := (!goals_being_watched) + 1;
    1.40 -	  Posix.Process.sleep(Time.fromSeconds 4); 
    1.41 +	  Posix.Process.sleep(Time.fromSeconds 1); 
    1.42  	  (warning ("probfile is: "^probfile));
    1.43  	  (warning("dfg file is: "^newfile));
    1.44  	  (warning ("wholefile is: "^(File.sysify_path wholefile)));
    1.45 @@ -195,8 +197,8 @@
    1.46  	  if File.exists
    1.47  	        (Path.append dfg_dir (Path.basic ("ax_prob"^"_" ^ probID ^ ".dfg")))
    1.48  	  then callResProvers (toWatcherStr, args)
    1.49 -	  else error ("tptp2X failed: " ^ getenv "TPTP2X_HOME" ^ "/tptp2X " ^
    1.50 -	              space_implode " " tptp2x_args)
    1.51 +	  else error ("tptp2X failed: " ^ getenv "TPTP2X_HOME" ^ "/tptp2X" ^
    1.52 +	              " -fdfg " ^ File.sysify_path wholefile ^ " -d " ^ dfg_path)
    1.53        end
    1.54  (*
    1.55  fun callResProversStr (toWatcherStr,  []) =  "End of calls\n" 
    1.56 @@ -381,7 +383,7 @@
    1.57  			 in 
    1.58  			 if (isSome pd ) then 
    1.59  			     let val pd' = OS.IO.pollIn (valOf pd)
    1.60 -				 val pdl = OS.IO.poll ([pd'], SOME (Time.fromMilliseconds 100)) 
    1.61 +				 val pdl = OS.IO.poll ([pd'], SOME (Time.fromMilliseconds 2000)) 
    1.62  			     in
    1.63  				if null pdl 
    1.64  				then
    1.65 @@ -407,7 +409,7 @@
    1.66  			 in 
    1.67  			 if (isSome pd ) then 
    1.68  			     let val pd' = OS.IO.pollIn (valOf pd)
    1.69 -				 val pdl = OS.IO.poll ([pd'], SOME (Time.fromMilliseconds 100)) 
    1.70 +				 val pdl = OS.IO.poll ([pd'], SOME (Time.fromMilliseconds 2000)) 
    1.71  			     in
    1.72  				if null pdl 
    1.73  				then
    1.74 @@ -456,7 +458,7 @@
    1.75  			  (* check here for prover label on child*)
    1.76  			  let val _ = File.write (File.tmp_path (Path.basic "child_incoming"))  ("subgoals forked to checkChildren: "^prems_string^prover^thmstring^goalstring^childCmd) 
    1.77  		      val childDone = (case prover of
    1.78 -	    (* "vampire" => startVampireTransfer(childInput, toParentStr, parentID, childCmd)                                               |*)"spass" => (checkSpassProofFound(childInput, toParentStr, parentID,thmstring,goalstring, childCmd, thm, sg_num,clause_arr, num_of_clauses)     ) )
    1.79 +	    (* "vampire" => startVampireTransfer(childInput, toParentStr, parentID, childCmd)                                               |*)"spass" => (SpassComm.checkSpassProofFound(childInput, toParentStr, parentID,thmstring,goalstring, childCmd, thm, sg_num,clause_arr, num_of_clauses)     ) )
    1.80  			   in
    1.81  			    if childDone      (**********************************************)
    1.82  			    then              (* child has found a proof and transferred it *)
    1.83 @@ -700,81 +702,123 @@
    1.84  		status
    1.85  	end
    1.86  
    1.87 -fun createWatcher (thm,clause_arr, ( num_of_clauses:int)) = 
    1.88 -  let val mychild = childInfo (setupWatcher(thm,clause_arr,  num_of_clauses))
    1.89 -      val streams =snd mychild
    1.90 -      val childin = fst streams
    1.91 -      val childout = snd streams
    1.92 -      val childpid = fst mychild
    1.93 -      val sign = sign_of_thm thm
    1.94 -      val prems = prems_of thm
    1.95 -      val prems_string =  Meson.concat_with_and (map (Sign.string_of_term sign) prems) 
    1.96 -      val _ = (warning ("subgoals forked to createWatcher: "^prems_string));
    1.97 -      fun vampire_proofHandler (n) =
    1.98 -	    (Pretty.writeln(Pretty.str ( (concat[(oct_char "360"), (oct_char "377")])));
    1.99 -	    getVampInput childin; Pretty.writeln(Pretty.str  (oct_char "361"));() )               
   1.100 -     
   1.101 +
   1.102 +fun createWatcher (thm,clause_arr, ( num_of_clauses:int)) = let val mychild = childInfo (setupWatcher(thm,clause_arr,  num_of_clauses))
   1.103 +			   val streams =snd mychild
   1.104 +                           val childin = fst streams
   1.105 +                           val childout = snd streams
   1.106 +                           val childpid = fst mychild
   1.107 +                           val sign = sign_of_thm thm
   1.108 +                           val prems = prems_of thm
   1.109 +                           val prems_string =  Meson.concat_with_and (map (Sign.string_of_term sign) prems) 
   1.110 +                           val _ = (warning ("subgoals forked to createWatcher: "^prems_string));
   1.111 +                           fun vampire_proofHandler (n) =
   1.112 +                           (Pretty.writeln(Pretty.str ( (concat[(oct_char "360"), (oct_char "377")])));
   1.113 +                           getVampInput childin; Pretty.writeln(Pretty.str  (oct_char "361"));() )               
   1.114 +                          
   1.115 +
   1.116 +fun spass_proofHandler (n) = (
   1.117 +                                 let  val  outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "foo_signal1")));
   1.118 +                                      val _ = TextIO.output (outfile, ("In signal handler now\n"))
   1.119 +                                      val _ =  TextIO.closeOut outfile
   1.120 +                                      val (reconstr, thmstring, goalstring) = SpassComm.getSpassInput childin
   1.121 +                                      val  outfile = TextIO.openAppend(File.sysify_path(File.tmp_path (Path.basic "foo_signal")));
   1.122 +
   1.123 +                                      val _ = TextIO.output (outfile, ("In signal handler  "^reconstr^thmstring^goalstring^"goals_being_watched is: "^(string_of_int (!goals_being_watched))))
   1.124 +                                      val _ =  TextIO.closeOut outfile
   1.125 +                                      in          (* if a proof has been found and sent back as a reconstruction proof *)
   1.126 +                                                  if ( (substring (reconstr, 0,1))= "[")
   1.127 +                                                  then 
   1.128  
   1.129 -      fun spass_proofHandler (n) = (
   1.130 -	let val _ = File.write (File.tmp_path (Path.basic "foo_signal1")) "In signal handler now\n"
   1.131 -	    val (reconstr, thmstring, goalstring) = getSpassInput childin
   1.132 -	    val _ = File.append (File.tmp_path (Path.basic "foo_signal"))
   1.133 -	              ("In signal handler  "^reconstr^thmstring^goalstring^"goals_being_watched is: "^(string_of_int (!goals_being_watched)))
   1.134 -        in (* if a proof has been found and sent back as a reconstruction proof *)
   1.135 -	  if ( (substring (reconstr, 0,1))= "[")
   1.136 -	  then 
   1.137 -	    (
   1.138 -	     Pretty.writeln(Pretty.str ( (concat[(oct_char "360"), (oct_char "377")])));
   1.139 -	     Recon_Transfer.apply_res_thm reconstr goalstring;
   1.140 -	     Pretty.writeln(Pretty.str  (oct_char "361"));
   1.141 -	     
   1.142 -	     goals_being_watched := ((!goals_being_watched) - 1);
   1.143 -     
   1.144 -	     if ((!goals_being_watched) = 0)
   1.145 -	     then 
   1.146 -		(let val _ = File.write (File.tmp_path (Path.basic "foo_reap_found"))
   1.147 -		     ("Reaping a watcher, goals watched is: "^(string_of_int (!goals_being_watched))^"\n")
   1.148 -		 in
   1.149 -		     reapWatcher (childpid,childin, childout); ()
   1.150 -		 end)
   1.151 -	     else ()
   1.152 -	    )
   1.153 -	    (* if there's no proof, but a message from Spass *)
   1.154 -	    else if ((substring (reconstr, 0,5))= "SPASS")
   1.155 -		 then
   1.156 -		    (goals_being_watched := (!goals_being_watched) -1;
   1.157 -		     Pretty.writeln(Pretty.str ( (concat[(oct_char "360"), (oct_char "377")])));
   1.158 -		      Pretty.writeln(Pretty.str (goalstring^reconstr));
   1.159 -		      Pretty.writeln(Pretty.str  (oct_char "361"));
   1.160 -		      if (!goals_being_watched = 0)
   1.161 -		      then 
   1.162 -			  (File.write (File.tmp_path (Path.basic "foo_reap_comp"))
   1.163 -			       ("Reaping a watcher, goals watched is: "^(string_of_int (!goals_being_watched))^"\n");
   1.164 -			   reapWatcher (childpid,childin, childout); ())
   1.165 -		      else
   1.166 -			 ()
   1.167 -		)
   1.168 -		  (* if proof translation failed *)
   1.169 -		  else if ((substring (reconstr, 0,5)) = "Proof")
   1.170 -		  then 
   1.171 -		     (goals_being_watched := (!goals_being_watched) -1;
   1.172 -		      Pretty.writeln(Pretty.str ( (concat[(oct_char "360"), (oct_char "377")])));
   1.173 -		       Pretty.writeln(Pretty.str (goalstring^reconstr));
   1.174 -		       Pretty.writeln(Pretty.str  (oct_char "361"));
   1.175 -		       if (!goals_being_watched = 0)
   1.176 -		       then 
   1.177 -			  (File.write(File.tmp_path (Path.basic "foo_reap_comp"))
   1.178 -			      ("Reaping a watcher, goals watched is: "^(string_of_int (!goals_being_watched))^"\n");
   1.179 -			   reapWatcher (childpid,childin, childout); ())		       
   1.180 -		       else ())
   1.181 -	 	  else () (* add something here ?*)
   1.182 -	     end)
   1.183 +                                                            (
   1.184 +                                                                 Pretty.writeln(Pretty.str ( (concat[(oct_char "360"), (oct_char "377")])));
   1.185 +                                                                 Recon_Transfer.apply_res_thm reconstr goalstring;
   1.186 +                                                                 Pretty.writeln(Pretty.str  (oct_char "361"));
   1.187 +                                                                 
   1.188 +                                                                 goals_being_watched := ((!goals_being_watched) - 1);
   1.189 +                                                         
   1.190 +                                                                 if ((!goals_being_watched) = 0)
   1.191 +                                                                 then 
   1.192 +                                                                    (let val  outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "foo_reap_found")));
   1.193 +                                                                         val _ = TextIO.output (outfile, ("Reaping a watcher, goals watched is: "^(string_of_int (!goals_being_watched))^"\n"))
   1.194 +                                                                         val _ =  TextIO.closeOut outfile
   1.195 +                                                                     in
   1.196 +                                                                         killWatcher (childpid); reapWatcher (childpid,childin, childout); ()
   1.197 +                                                                     end)
   1.198 +                                                                 else
   1.199 +                                                                    ()
   1.200 +                                                            )
   1.201 +                                                    (* if there's no proof, but a message from Spass *)
   1.202 +                                                    else if ((substring (reconstr, 0,5))= "SPASS")
   1.203 +                                                         then
   1.204 +                                                                 (
   1.205 +                                                                     goals_being_watched := (!goals_being_watched) -1;
   1.206 +                                                                     Pretty.writeln(Pretty.str ( (concat[(oct_char "360"), (oct_char "377")])));
   1.207 +                                                                      Pretty.writeln(Pretty.str (goalstring^reconstr));
   1.208 +                                                                      Pretty.writeln(Pretty.str  (oct_char "361"));
   1.209 +                                                                      if (!goals_being_watched = 0)
   1.210 +                                                                      then 
   1.211 +                                                                          (let val  outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "foo_reap_comp")));
   1.212 +                                                                               val _ = TextIO.output (outfile, ("Reaping a watcher, goals watched is: "^(string_of_int (!goals_being_watched))^"\n"))
   1.213 +                                                                               val _ =  TextIO.closeOut outfile
   1.214 +                                                                           in
   1.215 +                                                                              killWatcher (childpid); reapWatcher (childpid,childin, childout); ()
   1.216 +                                                                           end )
   1.217 +                                                                      else
   1.218 +                                                                         ()
   1.219 +                                                                ) 
   1.220 +						   (* print out a list of rules used from clasimpset*)
   1.221 +                                                    else if ((substring (reconstr, 0,5))= "Rules")
   1.222 +                                                         then
   1.223 +                                                                 (
   1.224 +                                                                     goals_being_watched := (!goals_being_watched) -1;
   1.225 +                                                                     Pretty.writeln(Pretty.str ( (concat[(oct_char "360"), (oct_char "377")])));
   1.226 +                                                                      Pretty.writeln(Pretty.str (goalstring^reconstr));
   1.227 +                                                                      Pretty.writeln(Pretty.str  (oct_char "361"));
   1.228 +                                                                      if (!goals_being_watched = 0)
   1.229 +                                                                      then 
   1.230 +                                                                          (let val  outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "foo_reap_comp")));
   1.231 +                                                                               val _ = TextIO.output (outfile, ("Reaping a watcher, goals watched is: "^(string_of_int (!goals_being_watched))^"\n"))
   1.232 +                                                                               val _ =  TextIO.closeOut outfile
   1.233 +                                                                           in
   1.234 +                                                                              killWatcher (childpid);  reapWatcher (childpid,childin, childout);()
   1.235 +                                                                           end )
   1.236 +                                                                      else
   1.237 +                                                                         ()
   1.238 +                                                                )
   1.239 +							
   1.240 +                                                          (* if proof translation failed *)
   1.241 +                                                          else if ((substring (reconstr, 0,5)) = "Proof")
   1.242 +                                                               then 
   1.243 +                                                                   (
   1.244 +                                                                     goals_being_watched := (!goals_being_watched) -1;
   1.245 +                                                                     Pretty.writeln(Pretty.str ( (concat[(oct_char "360"), (oct_char "377")])));
   1.246 +                                                                      Pretty.writeln(Pretty.str (goalstring^reconstr));
   1.247 +                                                                      Pretty.writeln(Pretty.str  (oct_char "361"));
   1.248 +                                                                      if (!goals_being_watched = 0)
   1.249 +                                                                      then 
   1.250 +                                                                          (let val  outfile = TextIO.openOut(File.sysify_path(File.tmp_path (Path.basic "foo_reap_comp")));
   1.251 +                                                                               val _ = TextIO.output (outfile, ("Reaping a watcher, goals watched is: "^(string_of_int (!goals_being_watched))^"\n"))
   1.252 +                                                                               val _ =  TextIO.closeOut outfile
   1.253 +                                                                           in
   1.254 +                                                                              killWatcher (childpid); reapWatcher (childpid,childin, childout); ()
   1.255 +                                                                           end )
   1.256 +                                                                      else
   1.257 +                                                                         ()
   1.258 +                                                                )
   1.259  
   1.260  
   1.261 -   
   1.262 -  in IsaSignal.signal (IsaSignal.usr1, IsaSignal.SIG_HANDLE vampire_proofHandler);
   1.263 -     IsaSignal.signal (IsaSignal.usr2, IsaSignal.SIG_HANDLE spass_proofHandler);
   1.264 -     (childin, childout, childpid)
   1.265 +                                                                else  (* add something here ?*)
   1.266 +                                                                   ()
   1.267 +                                                             
   1.268 +                                       end)
   1.269 +
   1.270 +
   1.271 +                        
   1.272 +                       in IsaSignal.signal (IsaSignal.usr1, IsaSignal.SIG_HANDLE vampire_proofHandler);
   1.273 +                          IsaSignal.signal (IsaSignal.usr2, IsaSignal.SIG_HANDLE spass_proofHandler);
   1.274 +                          (childin, childout, childpid)
   1.275 +
   1.276  
   1.277    end
   1.278