| author | nipkow | 
| Thu, 07 Jul 2005 12:36:56 +0200 | |
| changeset 16732 | 1bbe526a552c | 
| parent 16675 | 96bdc59afc05 | 
| child 16767 | 2d4433759b8d | 
| permissions | -rw-r--r-- | 
| 15789 
4cb16144c81b
added hearder lines and deleted some redundant material
 paulson parents: 
15787diff
changeset | 1 | (* Title: Watcher.ML | 
| 16156 
2f6fc19aba1e
Fixed array containing clasimpset rules.  Added flags to turn on and off reconstruction and full spass
 quigley parents: 
16100diff
changeset | 2 | |
| 15789 
4cb16144c81b
added hearder lines and deleted some redundant material
 paulson parents: 
15787diff
changeset | 3 | ID: $Id$ | 
| 
4cb16144c81b
added hearder lines and deleted some redundant material
 paulson parents: 
15787diff
changeset | 4 | Author: Claire Quigley | 
| 
4cb16144c81b
added hearder lines and deleted some redundant material
 paulson parents: 
15787diff
changeset | 5 | Copyright 2004 University of Cambridge | 
| 15642 | 6 | *) | 
| 7 | ||
| 8 | (***************************************************************************) | |
| 9 | (* The watcher process starts a resolution process when it receives a *) | |
| 10 | (* message from Isabelle *) | |
| 11 | (* Signals Isabelle, puts output of child into pipe to Isabelle, *) | |
| 12 | (* and removes dead processes. Also possible to kill all the resolution *) | |
| 13 | (* processes currently running. *) | |
| 14 | (* Hardwired version of where to pick up the tptp files for the moment *) | |
| 15 | (***************************************************************************) | |
| 16 | ||
| 17 | (*use "Proof_Transfer"; | |
| 18 | use "VampireCommunication"; | |
| 16089 
9169bdf930f8
trying to set up portable calling sequences for SPASS and tptp2X
 paulson parents: 
16061diff
changeset | 19 | use "SpassCommunication";*) | 
| 15642 | 20 | (*use "/homes/clq20/Jia_Code/TransStartIsar";*) | 
| 21 | ||
| 22 | ||
| 23 | structure Watcher: WATCHER = | |
| 24 | struct | |
| 25 | ||
| 26 | val goals_being_watched = ref 0; | |
| 27 | ||
| 16039 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 28 | (*****************************************) | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 29 | (* The result of calling createWatcher *) | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 30 | (*****************************************) | 
| 15642 | 31 | |
| 16039 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 32 | datatype proc = PROC of {
 | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 33 | pid : Posix.Process.pid, | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 34 | instr : TextIO.instream, | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 35 | outstr : TextIO.outstream | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 36 | }; | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 37 | |
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 38 | (*****************************************) | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 39 | (* The result of calling executeToList *) | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 40 | (*****************************************) | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 41 | |
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 42 | datatype cmdproc = CMDPROC of {
 | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 43 | prover: string, (* Name of the resolution prover used, e.g. Vampire, SPASS *) | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 44 | cmd: string, (* The file containing the goal for res prover to prove *) | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 45 | thmstring: string, (* string representation of subgoal after negation, skolemization*) | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 46 | goalstring: string, (* string representation of subgoal*) | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 47 | proc_handle : (TextIO.instream,TextIO.outstream) Unix.proc, | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 48 | instr : TextIO.instream, (* Input stream to child process *) | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 49 | outstr : TextIO.outstream (* Output stream from child process *) | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 50 | }; | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 51 | |
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 52 | type signal = Posix.Signal.signal | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 53 | datatype exit_status = datatype Posix.Process.exit_status | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 54 | |
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 55 | val fromStatus = Posix.Process.fromStatus | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 56 | |
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 57 | |
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 58 | fun reap(pid, instr, outstr) = | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 59 | let | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 60 | val u = TextIO.closeIn instr; | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 61 | val u = TextIO.closeOut outstr; | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 62 | |
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 63 | val (_, status) = | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 64 | Posix.Process.waitpid(Posix.Process.W_CHILD pid, []) | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 65 | in | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 66 | status | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 67 | end | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 68 | |
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 69 | fun fdReader (name : string, fd : Posix.IO.file_desc) = | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 70 | 	  Posix.IO.mkTextReader {initBlkMode = true,name = name,fd = fd };
 | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 71 | |
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 72 | fun fdWriter (name, fd) = | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 73 |           Posix.IO.mkTextWriter {
 | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 74 | appendMode = false, | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 75 | initBlkMode = true, | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 76 | name = name, | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 77 | chunkSize=4096, | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 78 | fd = fd | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 79 | }; | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 80 | |
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 81 | fun openOutFD (name, fd) = | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 82 | TextIO.mkOutstream ( | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 83 | TextIO.StreamIO.mkOutstream ( | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 84 | fdWriter (name, fd), IO.BLOCK_BUF)); | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 85 | |
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 86 | fun openInFD (name, fd) = | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 87 | TextIO.mkInstream ( | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 88 | TextIO.StreamIO.mkInstream ( | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 89 | fdReader (name, fd), "")); | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 90 | |
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 91 | |
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 92 | |
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 93 | |
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 94 | |
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 95 | fun killChild child_handle = Unix.reap child_handle | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 96 | |
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 97 | fun childInfo (PROC{pid,instr,outstr }) = (pid,(instr,outstr));
 | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 98 | |
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 99 | fun cmdstreamsOf (CMDPROC{instr,outstr,...}) = (instr, outstr);
 | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 100 | |
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 101 | fun cmdInStream (CMDPROC{instr,outstr,...}) = (instr);
 | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 102 | |
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 103 | fun cmdchildInfo (CMDPROC{prover,cmd,thmstring,proc_handle,goalstring,instr,outstr}) = (prover,(cmd, (instr,outstr)));
 | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 104 | |
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 105 | fun cmdchildHandle (CMDPROC{prover,cmd,thmstring,goalstring,proc_handle,instr,outstr})  = proc_handle;
 | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 106 | |
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 107 | fun cmdProver (CMDPROC{prover,cmd,thmstring,goalstring,proc_handle,instr,outstr})  = (prover);
 | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 108 | |
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 109 | fun cmdThm (CMDPROC{prover,cmd,thmstring,goalstring,proc_handle,instr,outstr})  = (thmstring);
 | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 110 | |
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 111 | fun cmdGoal (CMDPROC{prover,cmd,thmstring,goalstring,proc_handle,instr,outstr})  = (goalstring);
 | 
| 15642 | 112 | |
| 113 | fun sendOutput (outstr,str) = (TextIO.outputSubstr (outstr, (Substring.all str));TextIO.flushOut outstr); | |
| 114 | ||
| 115 | (********************************************************************************************) | |
| 116 | (* takes a list of arguments and sends them individually to the watcher process by pipe *) | |
| 117 | (********************************************************************************************) | |
| 118 | ||
| 119 | fun outputArgs (toWatcherStr, []) = () | |
| 120 | | outputArgs (toWatcherStr, (x::xs)) = (TextIO.output (toWatcherStr, x); | |
| 121 | TextIO.flushOut toWatcherStr; | |
| 122 | outputArgs (toWatcherStr, xs)) | |
| 123 | ||
| 124 | (********************************************************************************) | |
| 125 | (* gets individual args from instream and concatenates them into a list *) | |
| 126 | (********************************************************************************) | |
| 127 | ||
| 128 | fun getArgs (fromParentStr, toParentStr,ys) = let | |
| 129 | val thisLine = TextIO.input fromParentStr | |
| 130 | in | |
| 131 | ((ys@[thisLine])) | |
| 132 | end | |
| 133 | ||
| 134 | (********************************************************************************) | |
| 135 | (* Remove the \n character from the end of each filename *) | |
| 136 | (********************************************************************************) | |
| 137 | ||
| 16478 | 138 | (*fun getCmd cmdStr = let val backList = ((rev(explode cmdStr))) | 
| 15642 | 139 | in | 
| 140 | if (String.isPrefix "\n" (implode backList )) | |
| 16089 
9169bdf930f8
trying to set up portable calling sequences for SPASS and tptp2X
 paulson parents: 
16061diff
changeset | 141 | then (implode (rev ((tl backList)))) | 
| 
9169bdf930f8
trying to set up portable calling sequences for SPASS and tptp2X
 paulson parents: 
16061diff
changeset | 142 | else cmdStr | 
| 16478 | 143 | end*) | 
| 15642 | 144 | |
| 145 | (********************************************************************************) | |
| 146 | (* Send request to Watcher for a vampire to be called for filename in arg *) | |
| 147 | (********************************************************************************) | |
| 148 | ||
| 149 | fun callResProver (toWatcherStr, arg) = (sendOutput (toWatcherStr, arg^"\n"); | |
| 16089 
9169bdf930f8
trying to set up portable calling sequences for SPASS and tptp2X
 paulson parents: 
16061diff
changeset | 150 | TextIO.flushOut toWatcherStr) | 
| 15642 | 151 | |
| 152 | (*****************************************************************************************) | |
| 16357 | 153 | (* Send request to Watcher for multiple provers to be called for filenames in arg *) | 
| 154 | (* need to do the dfg stuff in the watcher, not here! send over the clasimp and stuff files too*) | |
| 15642 | 155 | (*****************************************************************************************) | 
| 156 | ||
| 16357 | 157 | |
| 15642 | 158 | (* need to modify to send over hyps file too *) | 
| 16475 | 159 | fun callResProvers (toWatcherStr, []) = | 
| 160 | (sendOutput (toWatcherStr, "End of calls\n"); TextIO.flushOut toWatcherStr) | |
| 161 | | callResProvers (toWatcherStr, | |
| 162 | (prover,thmstring,goalstring, proverCmd,settings,clasimpfile, | |
| 163 | axfile, hypsfile,probfile) :: args) = | |
| 164 | let val _ = File.write (File.tmp_path (Path.basic "tog_comms")) | |
| 165 | (prover^thmstring^goalstring^proverCmd^settings^ | |
| 166 | clasimpfile^hypsfile^probfile) | |
| 167 | in sendOutput (toWatcherStr, | |
| 16675 | 168 | (prover^"$"^thmstring^"$"^goalstring^"$"^proverCmd^"$"^ | 
| 169 | settings^"$"^clasimpfile^"$"^hypsfile^"$"^probfile^"\n")); | |
| 16475 | 170 | goals_being_watched := (!goals_being_watched) + 1; | 
| 171 | TextIO.flushOut toWatcherStr; | |
| 172 | callResProvers (toWatcherStr,args) | |
| 173 | end | |
| 16357 | 174 | |
| 16156 
2f6fc19aba1e
Fixed array containing clasimpset rules.  Added flags to turn on and off reconstruction and full spass
 quigley parents: 
16100diff
changeset | 175 | |
| 15782 | 176 | (* | 
| 15642 | 177 | fun callResProversStr (toWatcherStr, []) = "End of calls\n" | 
| 178 | ||
| 15782 | 179 | | callResProversStr (toWatcherStr,(prover,thmstring,goalstring, proverCmd,settings,clasimpfile, axfile, hypsfile, probfile)::args) = | 
| 180 | ((prover^"*"^thmstring^"*"^goalstring^"*"^proverCmd^"*"^settings^"*"^clasimpfile^"*"^axfile^"*"^hypsfile^"*"^probfile^"\n") | |
| 15642 | 181 | |
| 15782 | 182 | *) | 
| 15642 | 183 | |
| 184 | (**************************************************************) | |
| 185 | (* Send message to watcher to kill currently running vampires *) | |
| 186 | (**************************************************************) | |
| 187 | ||
| 188 | fun callSlayer (toWatcherStr) = (sendOutput (toWatcherStr, "Kill vampires\n"); | |
| 189 | TextIO.flushOut toWatcherStr) | |
| 190 | ||
| 191 | ||
| 192 | ||
| 193 | (**************************************************************) | |
| 194 | (* Remove \n token from a vampire goal filename and extract *) | |
| 195 | (* prover, proverCmd, settings and file from input string *) | |
| 196 | (**************************************************************) | |
| 197 | ||
| 198 | ||
| 199 | fun takeUntil ch [] res = (res, []) | |
| 200 | | takeUntil ch (x::xs) res = if x = ch | |
| 201 | then | |
| 202 | (res, xs) | |
| 203 | else | |
| 204 | takeUntil ch xs (res@[x]) | |
| 205 | ||
| 206 | fun getSettings [] settings = settings | |
| 207 | | getSettings (xs) settings = let val (set, rest ) = takeUntil "%" xs [] | |
| 208 | in | |
| 209 | getSettings rest (settings@[(implode set)]) | |
| 210 | end | |
| 211 | ||
| 16475 | 212 | fun separateFields str = | 
| 213 |   let val  outfile = TextIO.openAppend(*("sep_field")*)(File.platform_path(File.tmp_path (Path.basic "sep_field")))                                                                         
 | |
| 214 |       val _ = TextIO.output (outfile,("In separateFields, str is: "^(implode str)^"\n\n") )
 | |
| 215 | val _ = TextIO.closeOut outfile | |
| 16675 | 216 | val (prover, rest) = takeUntil "$" str [] | 
| 16475 | 217 | val prover = implode prover | 
| 16357 | 218 | |
| 16675 | 219 | val (thmstring, rest) = takeUntil "$" rest [] | 
| 16475 | 220 | val thmstring = implode thmstring | 
| 16357 | 221 | |
| 16675 | 222 | val (goalstring, rest) = takeUntil "$" rest [] | 
| 16475 | 223 | val goalstring = implode goalstring | 
| 16357 | 224 | |
| 16675 | 225 | val (proverCmd, rest ) = takeUntil "$" rest [] | 
| 16475 | 226 | val proverCmd = implode proverCmd | 
| 227 | ||
| 16675 | 228 | val (settings, rest) = takeUntil "$" rest [] | 
| 16475 | 229 | val settings = getSettings settings [] | 
| 16357 | 230 | |
| 16675 | 231 | val (clasimpfile, rest ) = takeUntil "$" rest [] | 
| 16475 | 232 | val clasimpfile = implode clasimpfile | 
| 233 | ||
| 16675 | 234 | val (hypsfile, rest ) = takeUntil "$" rest [] | 
| 16475 | 235 | val hypsfile = implode hypsfile | 
| 15642 | 236 | |
| 16675 | 237 | val (file, rest) = takeUntil "$" rest [] | 
| 16475 | 238 | val file = implode file | 
| 239 | ||
| 240 | val _ = File.append (File.tmp_path (Path.basic "sep_comms")) | |
| 241 |                   ("Sep comms are: "^(implode str)^"**"^
 | |
| 16675 | 242 | prover^" thmstring: "^thmstring^"\n goalstr: "^goalstring^" \n provercmd: "^proverCmd^" \n clasimp "^clasimpfile^" \n hyps "^hypsfile^"\n prob "^file^"\n\n") | 
| 16475 | 243 | in | 
| 244 | (prover,thmstring,goalstring, proverCmd, settings, clasimpfile, hypsfile, file) | |
| 245 | end | |
| 246 | ||
| 16357 | 247 | |
| 248 | (***********************************************************************************) | |
| 249 | (* do tptp2x and cat to turn clasimpfile, hypsfile and probfile into one .dfg file *) | |
| 250 | (***********************************************************************************) | |
| 251 | ||
| 252 | fun formatCmd (prover,thmstring,goalstring, proverCmd, settings, clasimpfile, hypsfile ,probfile) = | |
| 16475 | 253 | let | 
| 254 | (*** want to cat clasimp ax hyps prob, then send the resulting file to tptp2x ***) | |
| 255 | val probID = List.last(explode probfile) | |
| 256 |     val wholefile = File.tmp_path (Path.basic ("ax_prob_" ^ probID))
 | |
| 257 | ||
| 258 | (*** only include problem and clasimp for the moment, not sure | |
| 259 | how to refer to hyps/local axioms just now ***) | |
| 260 |     val whole_prob_file = Unix.execute("/bin/cat", 
 | |
| 261 | [clasimpfile,(*axfile, hypsfile,*)probfile, ">", | |
| 262 | File.platform_path wholefile]) | |
| 263 | ||
| 264 | val dfg_dir = File.tmp_path (Path.basic "dfg"); | |
| 265 | val dfg_path = File.platform_path dfg_dir; | |
| 266 | ||
| 16515 
7896ea4f3a87
VAMPIRE_HOME, helper_path and various stylistic tweaks
 paulson parents: 
16478diff
changeset | 267 | val tptp2X = ResLib.helper_path "TPTP2X_HOME" "tptp2X" | 
| 16478 | 268 | |
| 16561 | 269 | (*** want to cat clasimp ax hyps prob, then send the resulting file to tptp2x ***) | 
| 270 | val probID = List.last(explode probfile) | |
| 271 |     val wholefile = File.tmp_path (Path.basic ("ax_prob_"^probID))
 | |
| 16478 | 272 | |
| 16561 | 273 | (*** only include problem and clasimp for the moment, not sure how to refer to ***) | 
| 274 | (*** hyps/local axioms just now ***) | |
| 275 |     val whole_prob_file = Unix.execute("/bin/cat", [clasimpfile,(*axfile, hypsfile,*)probfile,  ">", (File.platform_path wholefile)])
 | |
| 276 | (*** check if the directory exists and, if not, create it***) | |
| 277 | val _ = | |
| 278 | if !SpassComm.spass | |
| 279 | then | |
| 280 | 	    if File.exists dfg_dir then warning("dfg dir exists")
 | |
| 281 | else File.mkdir dfg_dir | |
| 282 | else | |
| 283 | 	    warning("not converting to dfg")
 | |
| 284 | ||
| 285 | val _ = if !SpassComm.spass then | |
| 286 | system (tptp2X ^ " -fdfg -d "^dfg_path^" "^ | |
| 287 | File.platform_path wholefile) | |
| 288 | else 7 | |
| 289 | val newfile = if !SpassComm.spass | |
| 290 | then | |
| 291 | dfg_path^"/ax_prob"^"_"^(probID)^".dfg" | |
| 16675 | 292 | |
| 16478 | 293 | else | 
| 16561 | 294 | (File.platform_path wholefile) | 
| 295 | val _ = File.append (File.tmp_path (Path.basic"thmstring_in_watcher")) | |
| 296 | (thmstring^"\n goals_watched"^(string_of_int(!goals_being_watched))^newfile^"\n") | |
| 297 | in | |
| 298 | (prover,thmstring,goalstring, proverCmd, settings,newfile) | |
| 299 | end; | |
| 16478 | 300 | |
| 16357 | 301 | |
| 302 | ||
| 303 | (* remove \n from end of command and put back into tuple format *) | |
| 304 | ||
| 305 | ||
| 16478 | 306 | (* val cmdStr = "spass*((ALL xa. (~ P x | P xa) & (~ P xa | P x)) & (P xa | (ALL x. P x)) & ((ALL x. ~ P x) | ~ P xb) [.])*(EX x. ALL y. P x = P y) --> (EX x. P x) = (ALL y. P y)*/homes/clq20/bin/SPASS*-DocProof*/local/scratch/clq20/27023/clasimp*/local/scratch/clq20/27023/hyps*/local/scratch/clq20/27023/prob_1\n" | 
| 307 | ||
| 308 | val cmdStr = "vampire*(length (rev xs) = length xs [.]) & (length (rev (a # xs)) ~= length (a # xs) [.])*length (rev []) = length []*/homes/jm318/Vampire8/vkernel*-t 300%-m 100000*/local/scratch/clq20/23523/clasimp*/local/scratch/clq20/23523/hyps*/local/scratch/clq20/23523/prob_1\n" | |
| 309 | *) | |
| 16357 | 310 | |
| 311 | (*FIX: are the two getCmd procs getting confused? Why do I have two anyway? *) | |
| 15642 | 312 | |
| 16475 | 313 | fun getCmd cmdStr = | 
| 314 | let val backList = rev(explode cmdStr) | |
| 315 | val _ = File.append (File.tmp_path (Path.basic"cmdStr")) cmdStr | |
| 316 | in | |
| 317 | if (String.isPrefix "\n" (implode backList )) | |
| 318 | then | |
| 319 | let val newCmdStr = (rev(tl backList)) | |
| 320 | in File.write (File.tmp_path (Path.basic"backlist")) | |
| 321 | 	                      ("about to call sepfields with "^(implode newCmdStr));
 | |
| 322 | formatCmd (separateFields newCmdStr) | |
| 323 | end | |
| 324 | else formatCmd (separateFields (explode cmdStr)) | |
| 325 | end | |
| 15642 | 326 | |
| 327 | ||
| 328 | fun getProofCmd (a,b,c,d,e,f) = d | |
| 329 | ||
| 16357 | 330 | |
| 15642 | 331 | (**************************************************************) | 
| 332 | (* Get commands from Isabelle *) | |
| 333 | (**************************************************************) | |
| 16357 | 334 | (* FIX: or perhaps do the tptp2x stuff here - so it's get commands and then format them, before passing them to spass *) | 
| 15642 | 335 | |
| 336 | fun getCmds (toParentStr,fromParentStr, cmdList) = | |
| 16475 | 337 | let val thisLine = TextIO.inputLine fromParentStr | 
| 338 | val _ = File.append (File.tmp_path (Path.basic "parent_comms")) thisLine | |
| 339 | in | |
| 340 | if (thisLine = "End of calls\n") | |
| 341 | then cmdList | |
| 342 | else if (thisLine = "Kill children\n") | |
| 343 | then | |
| 344 | ( TextIO.output (toParentStr,thisLine ); | |
| 345 | TextIO.flushOut toParentStr; | |
| 346 | 	   (("","","","Kill children",[],"")::cmdList)
 | |
| 347 | ) | |
| 348 | else let val thisCmd = getCmd (thisLine) | |
| 349 | (*********************************************************) | |
| 350 | (* thisCmd = (prover,thmstring,proverCmd, settings, file)*) | |
| 351 | (* i.e. put back into tuple format *) | |
| 352 | (*********************************************************) | |
| 353 | in | |
| 354 | (*TextIO.output (toParentStr, thisCmd); | |
| 355 | TextIO.flushOut toParentStr;*) | |
| 356 | getCmds (toParentStr,fromParentStr, (thisCmd::cmdList)) | |
| 357 | end | |
| 358 | end | |
| 359 | ||
| 16357 | 360 | |
| 15642 | 361 | (**************************************************************) | 
| 362 | (* Get Io-descriptor for polling of an input stream *) | |
| 363 | (**************************************************************) | |
| 364 | ||
| 365 | ||
| 366 | fun getInIoDesc someInstr = | |
| 367 | let val (rd, buf) = TextIO.StreamIO.getReader(TextIO.getInstream someInstr) | |
| 15702 
2677db44c795
new signalling primmitives for sml/nj compatibility
 paulson parents: 
15684diff
changeset | 368 | val _ = TextIO.output (TextIO.stdOut, buf) | 
| 15642 | 369 | val ioDesc = | 
| 370 | case rd | |
| 371 | 	      of TextPrimIO.RD{ioDesc = SOME iod, ...} =>SOME iod
 | |
| 372 | | _ => NONE | |
| 373 | in (* since getting the reader will have terminated the stream, we need | |
| 374 | * to build a new stream. *) | |
| 375 | TextIO.setInstream(someInstr, TextIO.StreamIO.mkInstream(rd, buf)); | |
| 376 | ioDesc | |
| 377 | end | |
| 378 | ||
| 379 | ||
| 380 | (*************************************) | |
| 381 | (* Set up a Watcher Process *) | |
| 382 | (*************************************) | |
| 383 | ||
| 384 | ||
| 385 | ||
| 16061 | 386 | fun setupWatcher (thm,clause_arr, num_of_clauses) = | 
| 387 | let | |
| 388 | (** pipes for communication between parent and watcher **) | |
| 389 | val p1 = Posix.IO.pipe () | |
| 390 | val p2 = Posix.IO.pipe () | |
| 391 | fun closep () = ( | |
| 392 | Posix.IO.close (#outfd p1); | |
| 393 | Posix.IO.close (#infd p1); | |
| 394 | Posix.IO.close (#outfd p2); | |
| 395 | Posix.IO.close (#infd p2) | |
| 396 | ) | |
| 397 | (***********************************************************) | |
| 398 | (****** fork a watcher process and get it set up and going *) | |
| 399 | (***********************************************************) | |
| 400 | fun startWatcher (procList) = | |
| 401 | (case Posix.Process.fork() (***************************************) | |
| 402 | of SOME pid => pid (* parent - i.e. main Isabelle process *) | |
| 403 | (***************************************) | |
| 404 | ||
| 405 | (*************************) | |
| 406 | | NONE => let (* child - i.e. watcher *) | |
| 407 | val oldchildin = #infd p1 (*************************) | |
| 408 | val fromParent = Posix.FileSys.wordToFD 0w0 | |
| 409 | val oldchildout = #outfd p2 | |
| 410 | val toParent = Posix.FileSys.wordToFD 0w1 | |
| 411 | val fromParentIOD = Posix.FileSys.fdToIOD fromParent | |
| 412 | 		val fromParentStr = openInFD ("_exec_in_parent", fromParent)
 | |
| 413 | 		val toParentStr = openOutFD ("_exec_out_parent", toParent)
 | |
| 414 | val sign = sign_of_thm thm | |
| 415 | val prems = prems_of thm | |
| 416 | val prems_string = Meson.concat_with_and (map (Sign.string_of_term sign) prems) | |
| 417 | 		val _ = (warning ("subgoals forked to startWatcher: "^prems_string));
 | |
| 418 | (* tracing *) | |
| 419 | (*val tenth_ax = fst( Array.sub(clause_arr, 1)) | |
| 420 | val tenth_ax_thms = memo_find_clause (tenth_ax, clause_tab) | |
| 421 | val clause_str = Meson.concat_with_and (map string_of_thm tenth_ax_thms) | |
| 422 | 		val _ = (warning ("tenth axiom in array in watcher is: "^tenth_ax))         
 | |
| 423 | 		val _ = (warning ("tenth axiom in table in watcher is: "^clause_str))         
 | |
| 424 | 		val _ = (warning ("num_of_clauses in watcher is: "^(string_of_int (num_of_clauses))) )       
 | |
| 425 | *) | |
| 426 | (*val goalstr = string_of_thm (the_goal) | |
| 16260 | 427 | val outfile = TextIO.openOut(File.platform_path(File.tmp_path (Path.basic "goal_in_watcher"))); | 
| 16061 | 428 | val _ = TextIO.output (outfile,goalstr ) | 
| 429 | val _ = TextIO.closeOut outfile*) | |
| 430 | fun killChildren [] = () | |
| 431 | | killChildren (child_handle::children) = (killChild child_handle; killChildren children) | |
| 15642 | 432 | |
| 16061 | 433 | |
| 434 | ||
| 435 | (*************************************************************) | |
| 436 | (* take an instream and poll its underlying reader for input *) | |
| 437 | (*************************************************************) | |
| 15642 | 438 | |
| 16061 | 439 | fun pollParentInput () = | 
| 16475 | 440 | let val pd = OS.IO.pollDesc (fromParentIOD) | 
| 441 | in | |
| 442 | if (isSome pd ) then | |
| 443 | let val pd' = OS.IO.pollIn (valOf pd) | |
| 444 | val pdl = OS.IO.poll ([pd'], SOME (Time.fromMilliseconds 2000)) | |
| 445 | val _ = File.append (File.tmp_path (Path.basic "parent_poll")) | |
| 446 | 			     ("In parent_poll\n")	
 | |
| 447 | in | |
| 448 | if null pdl | |
| 449 | then | |
| 450 | NONE | |
| 451 | else if (OS.IO.isIn (hd pdl)) | |
| 452 | then | |
| 453 | (SOME ( getCmds (toParentStr, fromParentStr, []))) | |
| 454 | else | |
| 16061 | 455 | NONE | 
| 16475 | 456 | end | 
| 457 | else | |
| 458 | NONE | |
| 459 | end | |
| 16061 | 460 | |
| 461 | fun pollChildInput (fromStr) = | |
| 16478 | 462 | |
| 463 | let val _ = File.append (File.tmp_path (Path.basic "child_poll")) | |
| 464 | 			           ("In child_poll\n")
 | |
| 465 | val iod = getInIoDesc fromStr | |
| 466 | in | |
| 467 | ||
| 468 | ||
| 469 | ||
| 16061 | 470 | if isSome iod | 
| 471 | then | |
| 472 | let val pd = OS.IO.pollDesc (valOf iod) | |
| 473 | in | |
| 474 | if (isSome pd ) then | |
| 475 | let val pd' = OS.IO.pollIn (valOf pd) | |
| 16156 
2f6fc19aba1e
Fixed array containing clasimpset rules.  Added flags to turn on and off reconstruction and full spass
 quigley parents: 
16100diff
changeset | 476 | val pdl = OS.IO.poll ([pd'], SOME (Time.fromMilliseconds 2000)) | 
| 16478 | 477 | |
| 16061 | 478 | in | 
| 479 | if null pdl | |
| 480 | then | |
| 16478 | 481 | ( File.append (File.tmp_path (Path.basic "child_poll_res")) | 
| 482 | 			           ("Null pdl \n");NONE)
 | |
| 16061 | 483 | else if (OS.IO.isIn (hd pdl)) | 
| 484 | then | |
| 16478 | 485 | (let val inval = (TextIO.inputLine fromStr) | 
| 486 | val _ = File.append (File.tmp_path (Path.basic "child_poll_res")) (inval^"\n") | |
| 487 | in | |
| 488 | SOME inval | |
| 489 | end) | |
| 16061 | 490 | else | 
| 16478 | 491 | ( File.append (File.tmp_path (Path.basic "child_poll_res")) | 
| 492 | 			           ("Null pdl \n");NONE)
 | |
| 16061 | 493 | end | 
| 494 | else | |
| 495 | NONE | |
| 496 | end | |
| 497 | else | |
| 498 | NONE | |
| 16475 | 499 | end | 
| 15642 | 500 | |
| 501 | ||
| 16061 | 502 | (****************************************************************************) | 
| 503 | (* Check all vampire processes currently running for output *) | |
| 504 | (****************************************************************************) | |
| 505 | (*********************************) | |
| 506 | fun checkChildren ([], toParentStr) = [] (*** no children to check ********) | |
| 507 | (*********************************) | |
| 508 | | checkChildren ((childProc::otherChildren), toParentStr) = | |
| 16357 | 509 | let val _ = File.append (File.tmp_path (Path.basic "child_check")) | 
| 510 | 			           ("In check child, length of queue:"^(string_of_int (length (childProc::otherChildren)))^"\n")
 | |
| 511 | val (childInput,childOutput) = cmdstreamsOf childProc | |
| 16061 | 512 | val child_handle= cmdchildHandle childProc | 
| 513 | (* childCmd is the .dfg file that the problem is in *) | |
| 514 | val childCmd = fst(snd (cmdchildInfo childProc)) | |
| 16357 | 515 | val _ = File.append (File.tmp_path (Path.basic "child_command")) | 
| 516 | (childCmd^"\n") | |
| 16061 | 517 | (* now get the number of the subgoal from the filename *) | 
| 16520 | 518 | val sg_num = if (!SpassComm.spass ) | 
| 519 | then | |
| 520 | int_of_string(ReconOrderClauses.get_nth 5 (rev(explode childCmd))) | |
| 521 | else | |
| 522 | int_of_string(hd (rev(explode childCmd))) | |
| 523 | ||
| 16061 | 524 | val childIncoming = pollChildInput childInput | 
| 16357 | 525 | val _ = File.append (File.tmp_path (Path.basic "child_check_polled")) | 
| 526 | 			           ("finished polling child \n")
 | |
| 16061 | 527 | val parentID = Posix.ProcEnv.getppid() | 
| 528 | val prover = cmdProver childProc | |
| 529 | val thmstring = cmdThm childProc | |
| 530 | val sign = sign_of_thm thm | |
| 531 | val prems = prems_of thm | |
| 532 | val prems_string = Meson.concat_with_and (map (Sign.string_of_term sign) prems) | |
| 16100 | 533 | 			val _ = warning("subgoals forked to checkChildren: "^prems_string)
 | 
| 534 | val goalstring = cmdGoal childProc | |
| 16357 | 535 | val _ = File.append (File.tmp_path (Path.basic "child_comms")) | 
| 536 | (prover^thmstring^goalstring^childCmd^"\n") | |
| 16061 | 537 | in | 
| 538 | if (isSome childIncoming) | |
| 539 | then | |
| 540 | (* check here for prover label on child*) | |
| 16100 | 541 | 			  let val _ = File.write (File.tmp_path (Path.basic "child_incoming"))  ("subgoals forked to checkChildren: "^prems_string^prover^thmstring^goalstring^childCmd) 
 | 
| 16478 | 542 | val childDone = (case prover of | 
| 543 | "vampire" => (VampComm.checkVampProofFound(childInput, toParentStr, parentID,thmstring,goalstring, childCmd, thm, sg_num,clause_arr, num_of_clauses) ) | |
| 544 | |"spass" => (SpassComm.checkSpassProofFound(childInput, toParentStr, parentID,thmstring,goalstring, childCmd, thm, sg_num,clause_arr, num_of_clauses) ) ) | |
| 16061 | 545 | in | 
| 546 | if childDone (**********************************************) | |
| 547 | then (* child has found a proof and transferred it *) | |
| 548 | (**********************************************) | |
| 15642 | 549 | |
| 16061 | 550 | (**********************************************) | 
| 551 | (* Remove this child and go on to check others*) | |
| 552 | (**********************************************) | |
| 553 | ( Unix.reap child_handle; | |
| 554 | checkChildren(otherChildren, toParentStr)) | |
| 555 | else | |
| 556 | (**********************************************) | |
| 557 | (* Keep this child and go on to check others *) | |
| 558 | (**********************************************) | |
| 15642 | 559 | |
| 16061 | 560 | (childProc::(checkChildren (otherChildren, toParentStr))) | 
| 561 | end | |
| 562 | else | |
| 16100 | 563 | (File.append (File.tmp_path (Path.basic "child_incoming")) "No child output "; | 
| 564 | childProc::(checkChildren (otherChildren, toParentStr))) | |
| 16061 | 565 | end | 
| 15642 | 566 | |
| 16061 | 567 | |
| 568 | (********************************************************************) | |
| 569 | (* call resolution processes *) | |
| 570 | (* settings should be a list of strings *) | |
| 16520 | 571 | (* e.g. ["-t 300", "-m 100000"] (TextIO.input instr)^ *) | 
| 16061 | 572 | (* takes list of (string, string, string list, string)list proclist *) | 
| 573 | (********************************************************************) | |
| 15642 | 574 | |
| 16039 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 575 | |
| 16061 | 576 | (*** add subgoal id num to this *) | 
| 577 | fun execCmds [] procList = procList | |
| 16561 | 578 | 	     |   execCmds  ((prover, thmstring,goalstring,proverCmd,settings,file)::cmds) procList  =             let val _ = File.append (File.tmp_path (Path.basic "pre_exec_child"))  ("\nAbout to execute command for goal:\n"^goalstring^proverCmd^(concat settings)^file^" at "^(Date.toString(Date.fromTimeLocal(Time.now()))))
 | 
| 16357 | 579 | in | 
| 580 | if (prover = "spass") | |
| 16561 | 581 | then | 
| 582 | let val childhandle:(TextIO.instream,TextIO.outstream) Unix.proc = | |
| 583 | (Unix.execute(proverCmd, (["-FullRed=0"]@settings@[file]))) | |
| 584 | val (instr, outstr) = Unix.streamsOf childhandle | |
| 585 | 		       val newProcList =    (((CMDPROC{
 | |
| 586 | prover = prover, | |
| 587 | cmd = file, | |
| 588 | thmstring = thmstring, | |
| 589 | goalstring = goalstring, | |
| 590 | proc_handle = childhandle, | |
| 591 | instr = instr, | |
| 592 | outstr = outstr })::procList)) | |
| 593 | val _ = File.append (File.tmp_path (Path.basic "exec_child")) | |
| 594 | 			     ("\nexecuting command for goal:\n"^
 | |
| 595 | goalstring^proverCmd^(concat settings)^file^" at "^(Date.toString(Date.fromTimeLocal(Time.now())))) | |
| 596 | in | |
| 597 | Posix.Process.sleep (Time.fromSeconds 1);execCmds cmds newProcList | |
| 598 | end | |
| 599 | else | |
| 600 | let val childhandle:(TextIO.instream,TextIO.outstream) Unix.proc = | |
| 601 | (Unix.execute(proverCmd, (settings@[file]))) | |
| 602 | val (instr, outstr) = Unix.streamsOf childhandle | |
| 603 | ||
| 604 | 		       val newProcList =    (((CMDPROC{
 | |
| 605 | prover = prover, | |
| 606 | cmd = file, | |
| 607 | thmstring = thmstring, | |
| 608 | goalstring = goalstring, | |
| 609 | proc_handle = childhandle, | |
| 610 | instr = instr, | |
| 611 | outstr = outstr })::procList)) | |
| 612 | ||
| 613 | 		       val _ = File.append (File.tmp_path (Path.basic "exec_child"))  ("executing command for goal:\n"^goalstring^proverCmd^(concat settings)^file^" at "^(Date.toString(Date.fromTimeLocal(Time.now()))))
 | |
| 614 | in | |
| 615 | Posix.Process.sleep (Time.fromSeconds 1); execCmds cmds newProcList | |
| 616 | end | |
| 16357 | 617 | end | 
| 15642 | 618 | |
| 16039 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 619 | |
| 16061 | 620 | (****************************************) | 
| 621 | (* call resolution processes remotely *) | |
| 622 | (* settings should be a list of strings *) | |
| 623 | (* e.g. ["-t 300", "-m 100000"] *) | |
| 624 | (****************************************) | |
| 625 | ||
| 626 | (* fun execRemoteCmds [] procList = procList | |
| 627 | | execRemoteCmds ((prover, thmstring,goalstring,proverCmd ,settings,file)::cmds) procList = | |
| 628 | 				       let val  newProcList =  mySshExecuteToList ("/usr/bin/ssh",([prover,thmstring,goalstring,"-t", "shep"]@[proverCmd]@settings@[file]), procList)
 | |
| 629 | in | |
| 630 | execRemoteCmds cmds newProcList | |
| 631 | end | |
| 16039 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 632 | *) | 
| 15642 | 633 | |
| 16061 | 634 | fun printList (outStr, []) = () | 
| 635 | | printList (outStr, (x::xs)) = (TextIO.output (outStr, x);TextIO.flushOut outStr; printList (outStr,xs)) | |
| 15642 | 636 | |
| 637 | ||
| 16061 | 638 | (**********************************************) | 
| 639 | (* Watcher Loop *) | |
| 640 | (**********************************************) | |
| 641 | ||
| 15642 | 642 | |
| 643 | ||
| 644 | ||
| 16061 | 645 | fun keepWatching (toParentStr, fromParentStr,procList) = | 
| 646 | let fun loop (procList) = | |
| 647 | ( | |
| 648 | let val cmdsFromIsa = pollParentInput () | |
| 649 | fun killchildHandler (n:int) = (TextIO.output(toParentStr, "Killing child proof processes!\n"); | |
| 650 | TextIO.flushOut toParentStr; | |
| 651 | killChildren (map (cmdchildHandle) procList); | |
| 652 | ()) | |
| 653 | ||
| 654 | in | |
| 655 | (*Signal.signal (Posix.Signal.usr2, Signal.SIG_HANDLE killchildHandler);*) | |
| 656 | (**********************************) | |
| 657 | if (isSome cmdsFromIsa) then (* deal with input from Isabelle *) | |
| 658 | ( (**********************************) | |
| 659 | if (getProofCmd(hd(valOf cmdsFromIsa)) = "Kill children" ) | |
| 660 | then | |
| 661 | ( | |
| 662 | let val child_handles = map cmdchildHandle procList | |
| 663 | in | |
| 664 | killChildren child_handles; | |
| 665 | (*Posix.Process.kill(Posix.Process.K_PROC (Posix.ProcEnv.getppid()), Posix.Signal.usr2);*) loop ([]) | |
| 666 | end | |
| 667 | ||
| 668 | ) | |
| 669 | else | |
| 670 | ( | |
| 671 | if ((length procList)<10) (********************) | |
| 672 | then (* Execute locally *) | |
| 673 | ( (********************) | |
| 674 | let | |
| 675 | val newProcList = execCmds (valOf cmdsFromIsa) procList | |
| 676 | val parentID = Posix.ProcEnv.getppid() | |
| 16357 | 677 | val _ = (File.append (File.tmp_path (Path.basic "prekeep_watch")) "Just execed a child\n ") | 
| 16061 | 678 | val newProcList' =checkChildren (newProcList, toParentStr) | 
| 16357 | 679 | |
| 680 | 					      val _ = warning("off to keep watching...")
 | |
| 681 | val _ = (File.append (File.tmp_path (Path.basic "keep_watch")) "Off to keep watching...\n ") | |
| 16061 | 682 | in | 
| 683 | (*Posix.Process.sleep (Time.fromSeconds 1);*) | |
| 684 | loop (newProcList') | |
| 685 | end | |
| 686 | ) | |
| 687 | else (*********************************) | |
| 688 | (* Execute remotely *) | |
| 689 | (* (actually not remote for now )*) | |
| 690 | ( (*********************************) | |
| 691 | let | |
| 692 | val newProcList = execCmds (valOf cmdsFromIsa) procList | |
| 693 | val parentID = Posix.ProcEnv.getppid() | |
| 694 | val newProcList' =checkChildren (newProcList, toParentStr) | |
| 695 | in | |
| 696 | (*Posix.Process.sleep (Time.fromSeconds 1);*) | |
| 697 | loop (newProcList') | |
| 698 | end | |
| 699 | ) | |
| 15642 | 700 | |
| 701 | ||
| 702 | ||
| 16061 | 703 | ) | 
| 704 | ) (******************************) | |
| 705 | else (* No new input from Isabelle *) | |
| 706 | (******************************) | |
| 707 | ( let val newProcList = checkChildren ((procList), toParentStr) | |
| 708 | in | |
| 16357 | 709 | (*Posix.Process.sleep (Time.fromSeconds 1);*) | 
| 710 | (File.append (File.tmp_path (Path.basic "keep_watch")) "Off to keep watching.2..\n "); | |
| 16061 | 711 | loop (newProcList) | 
| 712 | end | |
| 713 | ||
| 714 | ) | |
| 715 | end) | |
| 716 | in | |
| 717 | loop (procList) | |
| 718 | end | |
| 719 | ||
| 720 | ||
| 721 | in | |
| 722 | (***************************) | |
| 723 | (*** Sort out pipes ********) | |
| 724 | (***************************) | |
| 15642 | 725 | |
| 16061 | 726 | Posix.IO.close (#outfd p1); | 
| 727 | Posix.IO.close (#infd p2); | |
| 728 | 		  Posix.IO.dup2{old = oldchildin, new = fromParent};
 | |
| 729 | Posix.IO.close oldchildin; | |
| 730 | 		  Posix.IO.dup2{old = oldchildout, new = toParent};
 | |
| 731 | Posix.IO.close oldchildout; | |
| 15642 | 732 | |
| 16061 | 733 | (***************************) | 
| 734 | (* start the watcher loop *) | |
| 735 | (***************************) | |
| 736 | keepWatching (toParentStr, fromParentStr, procList); | |
| 15642 | 737 | |
| 738 | ||
| 16061 | 739 | (****************************************************************************) | 
| 740 | (* fake return value - actually want the watcher to loop until killed *) | |
| 741 | (****************************************************************************) | |
| 742 | Posix.Process.wordToPid 0w0 | |
| 743 | ||
| 744 | end); | |
| 745 | (* end case *) | |
| 15642 | 746 | |
| 747 | ||
| 16061 | 748 | val _ = TextIO.flushOut TextIO.stdOut | 
| 15642 | 749 | |
| 16061 | 750 | (*******************************) | 
| 751 | (*** set watcher going ********) | |
| 752 | (*******************************) | |
| 15642 | 753 | |
| 16061 | 754 | val procList = [] | 
| 755 | val pid = startWatcher (procList) | |
| 756 | (**************************************************) | |
| 757 | (* communication streams to watcher *) | |
| 758 | (**************************************************) | |
| 15642 | 759 | |
| 16061 | 760 |     val instr = openInFD ("_exec_in", #infd p2)
 | 
| 761 |     val outstr = openOutFD ("_exec_out", #outfd p1)
 | |
| 762 | ||
| 763 | in | |
| 764 | (*******************************) | |
| 765 | (* close the child-side fds *) | |
| 766 | (*******************************) | |
| 767 | Posix.IO.close (#outfd p2); | |
| 768 | Posix.IO.close (#infd p1); | |
| 769 | (* set the fds close on exec *) | |
| 770 | Posix.IO.setfd (#infd p2, Posix.IO.FD.flags [Posix.IO.FD.cloexec]); | |
| 771 | Posix.IO.setfd (#outfd p1, Posix.IO.FD.flags [Posix.IO.FD.cloexec]); | |
| 772 | ||
| 773 | (*******************************) | |
| 774 | (* return value *) | |
| 775 | (*******************************) | |
| 776 |       PROC{pid = pid,
 | |
| 777 | instr = instr, | |
| 778 | outstr = outstr | |
| 779 | } | |
| 780 | end; | |
| 15642 | 781 | |
| 782 | ||
| 783 | ||
| 784 | (**********************************************************) | |
| 785 | (* Start a watcher and set up signal handlers *) | |
| 786 | (**********************************************************) | |
| 16039 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 787 | |
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 788 | fun killWatcher pid= Posix.Process.kill(Posix.Process.K_PROC pid, Posix.Signal.kill); | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 789 | |
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 790 | fun reapWatcher(pid, instr, outstr) = | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 791 | let | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 792 | val u = TextIO.closeIn instr; | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 793 | val u = TextIO.closeOut outstr; | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 794 | |
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 795 | val (_, status) = | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 796 | Posix.Process.waitpid(Posix.Process.W_CHILD pid, []) | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 797 | in | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 798 | status | 
| 
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
 quigley parents: 
15919diff
changeset | 799 | end | 
| 15642 | 800 | |
| 16156 
2f6fc19aba1e
Fixed array containing clasimpset rules.  Added flags to turn on and off reconstruction and full spass
 quigley parents: 
16100diff
changeset | 801 | |
| 16520 | 802 | |
| 803 | fun createWatcher (thm,clause_arr, ( num_of_clauses:int)) = let val mychild = childInfo (setupWatcher(thm,clause_arr, num_of_clauses)) | |
| 804 | val streams =snd mychild | |
| 805 | val childin = fst streams | |
| 806 | val childout = snd streams | |
| 807 | val childpid = fst mychild | |
| 808 | val sign = sign_of_thm thm | |
| 809 | val prems = prems_of thm | |
| 810 | val prems_string = Meson.concat_with_and (map (Sign.string_of_term sign) prems) | |
| 811 |                            val _ = (warning ("subgoals forked to createWatcher: "^prems_string));
 | |
| 812 | fun vampire_proofHandler (n) = | |
| 813 | (Pretty.writeln(Pretty.str ( (concat[(oct_char "360"), (oct_char "377")]))); | |
| 814 | VampComm.getVampInput childin; Pretty.writeln(Pretty.str (oct_char "361"));() ) | |
| 815 | ||
| 816 | ||
| 16675 | 817 | |
| 818 | ||
| 16520 | 819 | fun spass_proofHandler (n) = ( | 
| 16548 
aa36ae6b955e
Temporarily removed Rewrite from the translation code so that parsing with work on lists of numbers.
 quigley parents: 
16520diff
changeset | 820 | let val outfile = TextIO.openAppend(File.platform_path(File.tmp_path (Path.basic "foo_signal1"))); | 
| 16520 | 821 |                                       val _ = TextIO.output (outfile, ("In signal handler now\n"))
 | 
| 822 | val _ = TextIO.closeOut outfile | |
| 823 | val (reconstr, goalstring, thmstring) = SpassComm.getSpassInput childin | |
| 824 | val outfile = TextIO.openAppend(File.platform_path(File.tmp_path (Path.basic "foo_signal"))); | |
| 825 | ||
| 826 |                                       val _ = TextIO.output (outfile, ("In signal handler  "^reconstr^thmstring^goalstring^"goals_being_watched is: "^(string_of_int (!goals_being_watched))))
 | |
| 827 | val _ = TextIO.closeOut outfile | |
| 828 | in (* if a proof has been found and sent back as a reconstruction proof *) | |
| 829 | if ( (substring (reconstr, 0,1))= "[") | |
| 830 | then | |
| 15642 | 831 | |
| 16520 | 832 | ( | 
| 833 | Pretty.writeln(Pretty.str ( (concat[(oct_char "360"), (oct_char "377")]))); | |
| 834 | Recon_Transfer.apply_res_thm reconstr goalstring; | |
| 835 | Pretty.writeln(Pretty.str (oct_char "361")); | |
| 836 | ||
| 837 | goals_being_watched := ((!goals_being_watched) - 1); | |
| 838 | ||
| 839 | if ((!goals_being_watched) = 0) | |
| 840 | then | |
| 841 | (let val outfile = TextIO.openOut(File.platform_path(File.tmp_path (Path.basic "foo_reap_found"))); | |
| 842 |                                                                          val _ = TextIO.output (outfile, ("Reaping a watcher, goals watched is: "^(string_of_int (!goals_being_watched))^"\n"))
 | |
| 843 | val _ = TextIO.closeOut outfile | |
| 844 | in | |
| 845 | killWatcher (childpid); reapWatcher (childpid,childin, childout); () | |
| 846 | end) | |
| 847 | else | |
| 848 | () | |
| 849 | ) | |
| 16675 | 850 | (* if there's no proof, but a some sort of message from Spass *) | 
| 851 | else | |
| 16520 | 852 | ( | 
| 853 | goals_being_watched := (!goals_being_watched) -1; | |
| 854 | Pretty.writeln(Pretty.str ( (concat[(oct_char "360"), (oct_char "377")]))); | |
| 855 | Pretty.writeln(Pretty.str ((Recon_Transfer.restore_linebreaks goalstring)^reconstr)); | |
| 856 | Pretty.writeln(Pretty.str (oct_char "361")); | |
| 857 | if (!goals_being_watched = 0) | |
| 858 | then | |
| 859 | (let val outfile = TextIO.openOut(File.platform_path(File.tmp_path (Path.basic "foo_reap_comp"))); | |
| 860 |                                                                                val _ = TextIO.output (outfile, ("Reaping a watcher, goals watched is: "^(string_of_int (!goals_being_watched))^"\n"))
 | |
| 861 | val _ = TextIO.closeOut outfile | |
| 862 | in | |
| 863 | killWatcher (childpid); reapWatcher (childpid,childin, childout); () | |
| 864 | end ) | |
| 865 | else | |
| 866 | () | |
| 16675 | 867 | ) | 
| 16520 | 868 | |
| 869 | end) | |
| 870 | ||
| 871 | ||
| 872 | ||
| 873 | in IsaSignal.signal (IsaSignal.usr1, IsaSignal.SIG_HANDLE vampire_proofHandler); | |
| 874 | IsaSignal.signal (IsaSignal.usr2, IsaSignal.SIG_HANDLE spass_proofHandler); | |
| 875 | (childin, childout, childpid) | |
| 876 | ||
| 16156 
2f6fc19aba1e
Fixed array containing clasimpset rules.  Added flags to turn on and off reconstruction and full spass
 quigley parents: 
16100diff
changeset | 877 | |
| 15642 | 878 | |
| 16100 | 879 | end | 
| 15642 | 880 | |
| 881 | ||
| 882 | ||
| 883 | ||
| 884 | ||
| 885 | end (* structure Watcher *) |