author | paulson |
Tue, 20 Sep 2005 13:17:55 +0200 | |
changeset 17502 | 8836793df947 |
parent 17488 | 67376a311a2b |
child 17525 | ae5bb6001afb |
permissions | -rw-r--r-- |
15789
4cb16144c81b
added hearder lines and deleted some redundant material
paulson
parents:
15787
diff
changeset
|
1 |
(* Title: Watcher.ML |
4cb16144c81b
added hearder lines and deleted some redundant material
paulson
parents:
15787
diff
changeset
|
2 |
ID: $Id$ |
4cb16144c81b
added hearder lines and deleted some redundant material
paulson
parents:
15787
diff
changeset
|
3 |
Author: Claire Quigley |
4cb16144c81b
added hearder lines and deleted some redundant material
paulson
parents:
15787
diff
changeset
|
4 |
Copyright 2004 University of Cambridge |
15642 | 5 |
*) |
6 |
||
7 |
(***************************************************************************) |
|
8 |
(* The watcher process starts a resolution process when it receives a *) |
|
9 |
(* message from Isabelle *) |
|
10 |
(* Signals Isabelle, puts output of child into pipe to Isabelle, *) |
|
11 |
(* and removes dead processes. Also possible to kill all the resolution *) |
|
12 |
(* processes currently running. *) |
|
13 |
(* Hardwired version of where to pick up the tptp files for the moment *) |
|
14 |
(***************************************************************************) |
|
15 |
||
17305
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
16 |
signature WATCHER = |
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
17 |
sig |
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
18 |
|
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
19 |
(*****************************************************************************************) |
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
20 |
(* Send request to Watcher for multiple spasses to be called for filenames in arg *) |
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
21 |
(* callResProvers (outstreamtoWatcher, prover name,prover-command, (settings,file) list *) |
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
22 |
(*****************************************************************************************) |
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
23 |
|
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
24 |
val callResProvers : |
17422 | 25 |
TextIO.outstream * (string*string*string*string*string) list |
17305
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
26 |
-> unit |
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
27 |
|
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
28 |
(************************************************************************) |
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
29 |
(* Send message to watcher to kill currently running resolution provers *) |
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
30 |
(************************************************************************) |
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
31 |
|
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
32 |
val callSlayer : TextIO.outstream -> unit |
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
33 |
|
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
34 |
(**********************************************************) |
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
35 |
(* Start a watcher and set up signal handlers *) |
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
36 |
(**********************************************************) |
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
37 |
|
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
38 |
val createWatcher : |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
39 |
thm * (ResClause.clause * thm) Array.array -> |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
40 |
TextIO.instream * TextIO.outstream * Posix.Process.pid |
17305
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
41 |
|
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
42 |
(**********************************************************) |
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
43 |
(* Kill watcher process *) |
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
44 |
(**********************************************************) |
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
45 |
|
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
46 |
val killWatcher : Posix.Process.pid -> unit |
17488
67376a311a2b
further simplification of the Isabelle-ATP linkup
paulson
parents:
17484
diff
changeset
|
47 |
val killWatcher' : int -> unit |
17305
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
48 |
|
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
49 |
end |
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
50 |
|
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
51 |
|
15642 | 52 |
|
53 |
structure Watcher: WATCHER = |
|
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
54 |
struct |
15642 | 55 |
|
17488
67376a311a2b
further simplification of the Isabelle-ATP linkup
paulson
parents:
17484
diff
changeset
|
56 |
open Recon_Transfer |
16805 | 57 |
|
15642 | 58 |
val goals_being_watched = ref 0; |
59 |
||
16039
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
60 |
(*****************************************) |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
61 |
(* The result of calling createWatcher *) |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
62 |
(*****************************************) |
15642 | 63 |
|
16039
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
64 |
datatype proc = PROC of { |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
65 |
pid : Posix.Process.pid, |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
66 |
instr : TextIO.instream, |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
67 |
outstr : TextIO.outstream |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
68 |
}; |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
69 |
|
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
70 |
(*****************************************) |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
71 |
(* The result of calling executeToList *) |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
72 |
(*****************************************) |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
73 |
|
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
74 |
datatype cmdproc = CMDPROC of { |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
75 |
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:
15919
diff
changeset
|
76 |
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:
15919
diff
changeset
|
77 |
goalstring: string, (* string representation of subgoal*) |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
78 |
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:
15919
diff
changeset
|
79 |
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:
15919
diff
changeset
|
80 |
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:
15919
diff
changeset
|
81 |
}; |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
82 |
|
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
83 |
type signal = Posix.Signal.signal |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
84 |
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:
15919
diff
changeset
|
85 |
|
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
86 |
val fromStatus = Posix.Process.fromStatus |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
87 |
|
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
88 |
|
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
89 |
fun reap(pid, instr, outstr) = |
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
90 |
let val u = TextIO.closeIn instr; |
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
91 |
val u = TextIO.closeOut outstr; |
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
92 |
val (_, status) = Posix.Process.waitpid(Posix.Process.W_CHILD pid, []) |
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
93 |
in |
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
94 |
status |
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
95 |
end |
16039
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
96 |
|
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
97 |
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:
15919
diff
changeset
|
98 |
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:
15919
diff
changeset
|
99 |
|
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
100 |
fun fdWriter (name, fd) = |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
101 |
Posix.IO.mkTextWriter { |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
102 |
appendMode = false, |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
103 |
initBlkMode = true, |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
104 |
name = name, |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
105 |
chunkSize=4096, |
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
106 |
fd = fd}; |
16039
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
107 |
|
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
108 |
fun openOutFD (name, fd) = |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
109 |
TextIO.mkOutstream ( |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
110 |
TextIO.StreamIO.mkOutstream ( |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
111 |
fdWriter (name, fd), IO.BLOCK_BUF)); |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
112 |
|
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
113 |
fun openInFD (name, fd) = |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
114 |
TextIO.mkInstream ( |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
115 |
TextIO.StreamIO.mkInstream ( |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
116 |
fdReader (name, fd), "")); |
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
117 |
|
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
118 |
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:
15919
diff
changeset
|
119 |
|
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
120 |
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:
15919
diff
changeset
|
121 |
|
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
122 |
fun cmdInStream (CMDPROC{instr,outstr,...}) = instr; |
16039
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
123 |
|
17422 | 124 |
fun cmdchildInfo (CMDPROC{prover,cmd,proc_handle,goalstring,instr,outstr}) = |
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
125 |
(prover,(cmd, (instr,outstr))); |
16039
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
126 |
|
17422 | 127 |
fun cmdchildHandle (CMDPROC{prover,cmd,goalstring,proc_handle,instr,outstr}) = |
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
128 |
proc_handle; |
16039
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
129 |
|
17422 | 130 |
fun cmdProver (CMDPROC{prover,cmd,goalstring,proc_handle,instr,outstr}) = |
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
131 |
prover; |
15642 | 132 |
|
17422 | 133 |
fun cmdGoal (CMDPROC{prover,cmd,goalstring,proc_handle,instr,outstr}) = |
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
134 |
goalstring; |
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
135 |
|
15642 | 136 |
|
137 |
(********************************************************************************) |
|
138 |
(* gets individual args from instream and concatenates them into a list *) |
|
139 |
(********************************************************************************) |
|
140 |
||
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
141 |
fun getArgs (fromParentStr, toParentStr, ys) = |
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
142 |
let val thisLine = TextIO.input fromParentStr |
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
143 |
in ys@[thisLine] end |
15642 | 144 |
|
145 |
||
146 |
(********************************************************************************) |
|
147 |
(* Send request to Watcher for a vampire to be called for filename in arg *) |
|
148 |
(********************************************************************************) |
|
149 |
||
17231 | 150 |
fun callResProver (toWatcherStr, arg) = |
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
151 |
(TextIO.output (toWatcherStr, arg^"\n"); |
17231 | 152 |
TextIO.flushOut toWatcherStr) |
15642 | 153 |
|
154 |
(*****************************************************************************************) |
|
16357 | 155 |
(* Send request to Watcher for multiple provers to be called for filenames in arg *) |
156 |
(* need to do the dfg stuff in the watcher, not here! send over the clasimp and stuff files too*) |
|
15642 | 157 |
(*****************************************************************************************) |
158 |
||
16357 | 159 |
|
17305
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
160 |
(*Uses the $-character to separate items sent to watcher*) |
16475 | 161 |
fun callResProvers (toWatcherStr, []) = |
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
162 |
(TextIO.output (toWatcherStr, "End of calls\n"); TextIO.flushOut toWatcherStr) |
16475 | 163 |
| callResProvers (toWatcherStr, |
17422 | 164 |
(prover,goalstring, proverCmd,settings, |
165 |
probfile) :: args) = |
|
16475 | 166 |
let val _ = File.write (File.tmp_path (Path.basic "tog_comms")) |
17422 | 167 |
(prover^goalstring^proverCmd^settings^ |
168 |
probfile) |
|
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
169 |
in TextIO.output (toWatcherStr, |
17422 | 170 |
(prover^"$"^goalstring^"$"^proverCmd^"$"^ |
171 |
settings^"$"^probfile^"\n")); |
|
16475 | 172 |
goals_being_watched := (!goals_being_watched) + 1; |
173 |
TextIO.flushOut toWatcherStr; |
|
174 |
callResProvers (toWatcherStr,args) |
|
175 |
end |
|
16357 | 176 |
|
17305
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
177 |
|
15642 | 178 |
|
179 |
(**************************************************************) |
|
180 |
(* Send message to watcher to kill currently running vampires *) |
|
181 |
(**************************************************************) |
|
182 |
||
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
183 |
fun callSlayer toWatcherStr = (TextIO.output (toWatcherStr, "Kill vampires\n"); |
15642 | 184 |
TextIO.flushOut toWatcherStr) |
185 |
||
186 |
||
187 |
||
188 |
(**************************************************************) |
|
189 |
(* Remove \n token from a vampire goal filename and extract *) |
|
190 |
(* prover, proverCmd, settings and file from input string *) |
|
191 |
(**************************************************************) |
|
192 |
||
16475 | 193 |
fun separateFields str = |
17305
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
194 |
let val _ = File.append (File.tmp_path (Path.basic "sep_field")) |
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
195 |
("In separateFields, str is: " ^ str ^ "\n\n") |
17422 | 196 |
val [prover,goalstring,proverCmd,settingstr,probfile] = |
17305
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
197 |
String.tokens (fn c => c = #"$") str |
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
198 |
val settings = String.tokens (fn c => c = #"%") settingstr |
16475 | 199 |
val _ = File.append (File.tmp_path (Path.basic "sep_comms")) |
17305
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
200 |
("Sep comms are: "^ str ^"**"^ |
17422 | 201 |
prover^" goalstr: "^goalstring^ |
202 |
"\n provercmd: "^proverCmd^ |
|
203 |
"\n prob "^probfile^"\n\n") |
|
16475 | 204 |
in |
17422 | 205 |
(prover,goalstring, proverCmd, settings, probfile) |
16475 | 206 |
end |
207 |
||
17305
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
208 |
val remove_newlines = String.translate (fn c => if c = #"\n" then "" else str c); |
15642 | 209 |
|
17305
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
210 |
fun getCmd cmdStr = |
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
211 |
let val cmdStr' = remove_newlines cmdStr |
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
212 |
in |
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
213 |
File.write (File.tmp_path (Path.basic"sepfields_call")) |
17422 | 214 |
("about to call separateFields with " ^ cmdStr'); |
215 |
separateFields cmdStr' |
|
17305
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
216 |
end; |
15642 | 217 |
|
218 |
(**************************************************************) |
|
219 |
(* Get commands from Isabelle *) |
|
220 |
(**************************************************************) |
|
221 |
||
222 |
fun getCmds (toParentStr,fromParentStr, cmdList) = |
|
16475 | 223 |
let val thisLine = TextIO.inputLine fromParentStr |
224 |
val _ = File.append (File.tmp_path (Path.basic "parent_comms")) thisLine |
|
225 |
in |
|
17422 | 226 |
if thisLine = "End of calls\n" then cmdList |
227 |
else if thisLine = "Kill children\n" |
|
16475 | 228 |
then |
229 |
( TextIO.output (toParentStr,thisLine ); |
|
230 |
TextIO.flushOut toParentStr; |
|
17422 | 231 |
(("","","Kill children",[],"")::cmdList) |
16475 | 232 |
) |
17422 | 233 |
else let val thisCmd = getCmd thisLine |
16475 | 234 |
(*********************************************************) |
17422 | 235 |
(* thisCmd = (prover,proverCmd, settings, file)*) |
16475 | 236 |
(* i.e. put back into tuple format *) |
237 |
(*********************************************************) |
|
238 |
in |
|
239 |
(*TextIO.output (toParentStr, thisCmd); |
|
240 |
TextIO.flushOut toParentStr;*) |
|
17422 | 241 |
getCmds (toParentStr, fromParentStr, thisCmd::cmdList) |
16475 | 242 |
end |
243 |
end |
|
244 |
||
16357 | 245 |
|
15642 | 246 |
(**************************************************************) |
247 |
(* Get Io-descriptor for polling of an input stream *) |
|
248 |
(**************************************************************) |
|
249 |
||
250 |
fun getInIoDesc someInstr = |
|
251 |
let val (rd, buf) = TextIO.StreamIO.getReader(TextIO.getInstream someInstr) |
|
15702
2677db44c795
new signalling primmitives for sml/nj compatibility
paulson
parents:
15684
diff
changeset
|
252 |
val _ = TextIO.output (TextIO.stdOut, buf) |
15642 | 253 |
val ioDesc = |
254 |
case rd |
|
255 |
of TextPrimIO.RD{ioDesc = SOME iod, ...} =>SOME iod |
|
256 |
| _ => NONE |
|
257 |
in (* since getting the reader will have terminated the stream, we need |
|
258 |
* to build a new stream. *) |
|
259 |
TextIO.setInstream(someInstr, TextIO.StreamIO.mkInstream(rd, buf)); |
|
260 |
ioDesc |
|
261 |
end |
|
262 |
||
263 |
||
264 |
(*************************************) |
|
265 |
(* Set up a Watcher Process *) |
|
266 |
(*************************************) |
|
267 |
||
17422 | 268 |
fun getProofCmd (a,c,d,e,f) = d |
269 |
||
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
270 |
fun prems_string_of th = |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
271 |
Meson.concat_with_and (map (Sign.string_of_term (sign_of_thm th)) (prems_of th)) |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
272 |
|
17502 | 273 |
fun killChildren procs = List.app (ignore o Unix.reap) procs; |
274 |
||
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
275 |
fun setupWatcher (thm,clause_arr) = |
16061 | 276 |
let |
277 |
(** pipes for communication between parent and watcher **) |
|
278 |
val p1 = Posix.IO.pipe () |
|
279 |
val p2 = Posix.IO.pipe () |
|
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
280 |
fun closep () = |
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
281 |
(Posix.IO.close (#outfd p1); |
16061 | 282 |
Posix.IO.close (#infd p1); |
283 |
Posix.IO.close (#outfd p2); |
|
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
284 |
Posix.IO.close (#infd p2)) |
16061 | 285 |
(***********************************************************) |
286 |
(****** fork a watcher process and get it set up and going *) |
|
287 |
(***********************************************************) |
|
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
288 |
fun startWatcher procList = |
17234 | 289 |
(case Posix.Process.fork() (***************************************) |
290 |
of SOME pid => pid (* parent - i.e. main Isabelle process *) |
|
291 |
(***************************************) |
|
16061 | 292 |
|
17234 | 293 |
(*************************) |
294 |
| NONE => let (* child - i.e. watcher *) |
|
295 |
val oldchildin = #infd p1 (*************************) |
|
296 |
val fromParent = Posix.FileSys.wordToFD 0w0 |
|
297 |
val oldchildout = #outfd p2 |
|
298 |
val toParent = Posix.FileSys.wordToFD 0w1 |
|
299 |
val fromParentIOD = Posix.FileSys.fdToIOD fromParent |
|
300 |
val fromParentStr = openInFD ("_exec_in_parent", fromParent) |
|
301 |
val toParentStr = openOutFD ("_exec_out_parent", toParent) |
|
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
302 |
val _ = debug ("subgoals forked to startWatcher: "^ prems_string_of thm); |
15642 | 303 |
|
17234 | 304 |
(*************************************************************) |
305 |
(* take an instream and poll its underlying reader for input *) |
|
306 |
(*************************************************************) |
|
15642 | 307 |
|
17234 | 308 |
fun pollParentInput () = |
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
309 |
let val pd = OS.IO.pollDesc fromParentIOD |
17306 | 310 |
in |
311 |
if isSome pd then |
|
312 |
let val pd' = OS.IO.pollIn (valOf pd) |
|
313 |
val pdl = OS.IO.poll ([pd'], SOME (Time.fromMilliseconds 2000)) |
|
314 |
val _ = File.append (File.tmp_path (Path.basic "parent_poll")) |
|
315 |
("In parent_poll\n") |
|
316 |
in |
|
317 |
if null pdl |
|
318 |
then |
|
319 |
NONE |
|
320 |
else if (OS.IO.isIn (hd pdl)) |
|
321 |
then SOME (getCmds (toParentStr, fromParentStr, [])) |
|
322 |
else NONE |
|
323 |
end |
|
324 |
else NONE |
|
325 |
end |
|
17234 | 326 |
|
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
327 |
fun pollChildInput fromStr = |
17306 | 328 |
let val _ = File.append (File.tmp_path (Path.basic "child_poll")) |
329 |
("In child_poll\n") |
|
330 |
val iod = getInIoDesc fromStr |
|
331 |
in |
|
332 |
if isSome iod |
|
333 |
then |
|
334 |
let val pd = OS.IO.pollDesc (valOf iod) |
|
335 |
in |
|
336 |
if isSome pd then |
|
337 |
let val pd' = OS.IO.pollIn (valOf pd) |
|
338 |
val pdl = OS.IO.poll ([pd'], SOME (Time.fromMilliseconds 2000)) |
|
339 |
in |
|
340 |
if null pdl |
|
341 |
then |
|
342 |
(File.append (File.tmp_path (Path.basic"child_poll_res")) "Null pdl\n"; |
|
343 |
NONE) |
|
344 |
else if OS.IO.isIn (hd pdl) |
|
345 |
then |
|
346 |
let val inval = (TextIO.inputLine fromStr) |
|
347 |
val _ = File.append (File.tmp_path (Path.basic "child_poll_res")) (inval^"\n") |
|
348 |
in SOME inval end |
|
349 |
else |
|
350 |
(File.append (File.tmp_path (Path.basic"child_poll_res")) "Null pdl \n"; |
|
351 |
NONE) |
|
352 |
end |
|
353 |
else NONE |
|
354 |
end |
|
355 |
else NONE |
|
17234 | 356 |
end |
15642 | 357 |
|
358 |
||
17234 | 359 |
(****************************************************************************) |
360 |
(* Check all vampire processes currently running for output *) |
|
361 |
(****************************************************************************) |
|
362 |
(*********************************) |
|
363 |
fun checkChildren ([], toParentStr) = [] (*** no children to check ********) |
|
364 |
(*********************************) |
|
365 |
| checkChildren ((childProc::otherChildren), toParentStr) = |
|
366 |
let val _ = File.append (File.tmp_path (Path.basic "child_check")) |
|
17305
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
367 |
("In check child, length of queue:"^ |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
368 |
string_of_int (length (childProc::otherChildren))) |
17234 | 369 |
val (childInput,childOutput) = cmdstreamsOf childProc |
370 |
val child_handle= cmdchildHandle childProc |
|
371 |
(* childCmd is the .dfg file that the problem is in *) |
|
372 |
val childCmd = fst(snd (cmdchildInfo childProc)) |
|
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
373 |
val _ = File.append (File.tmp_path (Path.basic "child_check")) |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
374 |
("\nchildCmd = " ^ childCmd) |
17234 | 375 |
(* now get the number of the subgoal from the filename *) |
17305
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
376 |
val path_parts = String.tokens(fn c => c = #"/") childCmd |
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
377 |
val digits = String.translate |
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
378 |
(fn c => if Char.isDigit c then str c else "") |
6cef3aedd661
axioms now included in tptp files, no /bin/cat and various tidying
paulson
parents:
17235
diff
changeset
|
379 |
(List.last path_parts); |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
380 |
val sg_num = |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
381 |
(case Int.fromString digits of SOME n => n |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
382 |
| NONE => (File.append (File.tmp_path (Path.basic "child_check")) |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
383 |
"\nWatcher could not read subgoal nunber!!"; |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
384 |
raise ERROR)); |
17234 | 385 |
val childIncoming = pollChildInput childInput |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
386 |
val _ = File.append (File.tmp_path (Path.basic "child_check")) |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
387 |
"\nfinished polling child" |
17234 | 388 |
val parentID = Posix.ProcEnv.getppid() |
389 |
val prover = cmdProver childProc |
|
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
390 |
val prems_string = prems_string_of thm |
17234 | 391 |
val goalstring = cmdGoal childProc |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
392 |
val _ = File.append (File.tmp_path (Path.basic "child_check")) |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
393 |
("\nsubgoals forked to checkChildren: " ^ |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
394 |
space_implode "\n" [prems_string,prover,goalstring]) |
17234 | 395 |
in |
17306 | 396 |
if isSome childIncoming |
17234 | 397 |
then |
17306 | 398 |
(* check here for prover label on child*) |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
399 |
let val _ = File.append (File.tmp_path (Path.basic "child_check")) |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
400 |
"\nInput available from childIncoming" |
17306 | 401 |
val childDone = (case prover of |
17488
67376a311a2b
further simplification of the Isabelle-ATP linkup
paulson
parents:
17484
diff
changeset
|
402 |
"vampire" => AtpCommunication.checkVampProofFound(childInput, toParentStr, parentID,goalstring, childCmd, clause_arr) |
67376a311a2b
further simplification of the Isabelle-ATP linkup
paulson
parents:
17484
diff
changeset
|
403 |
| "E" => AtpCommunication.checkEProofFound(childInput, toParentStr, parentID,goalstring, childCmd, clause_arr) |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
404 |
|"spass" => AtpCommunication.checkSpassProofFound(childInput, toParentStr, parentID,goalstring, childCmd, thm, sg_num,clause_arr) ) |
17306 | 405 |
in |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
406 |
if childDone |
17306 | 407 |
then (* child has found a proof and transferred it *) |
408 |
(* Remove this child and go on to check others*) |
|
409 |
(**********************************************) |
|
410 |
(Unix.reap child_handle; |
|
411 |
checkChildren(otherChildren, toParentStr)) |
|
412 |
else |
|
413 |
(**********************************************) |
|
414 |
(* Keep this child and go on to check others *) |
|
415 |
(**********************************************) |
|
416 |
(childProc::(checkChildren (otherChildren, toParentStr))) |
|
417 |
end |
|
418 |
else |
|
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
419 |
(File.append (File.tmp_path (Path.basic "child_check")) |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
420 |
"No child output"; |
17306 | 421 |
childProc::(checkChildren (otherChildren, toParentStr))) |
17234 | 422 |
end |
15642 | 423 |
|
17234 | 424 |
|
425 |
(********************************************************************) |
|
426 |
(* call resolution processes *) |
|
427 |
(* settings should be a list of strings *) |
|
428 |
(* e.g. ["-t 300", "-m 100000"] (TextIO.input instr)^ *) |
|
429 |
(* takes list of (string, string, string list, string)list proclist *) |
|
430 |
(********************************************************************) |
|
15642 | 431 |
|
16039
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
432 |
|
16061 | 433 |
(*** add subgoal id num to this *) |
17234 | 434 |
fun execCmds [] procList = procList |
17422 | 435 |
| execCmds ((prover, goalstring,proverCmd,settings,file)::cmds) procList = |
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
436 |
let val _ = File.write (File.tmp_path (Path.basic "exec_child")) |
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
437 |
(space_implode "\n" |
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
438 |
(["About to execute command for goal:", |
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
439 |
goalstring, proverCmd] @ settings @ |
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
440 |
[file, Date.toString(Date.fromTimeLocal(Time.now()))])) |
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
441 |
val childhandle:(TextIO.instream,TextIO.outstream) Unix.proc = |
17234 | 442 |
(Unix.execute(proverCmd, (settings@[file]))) |
443 |
val (instr, outstr) = Unix.streamsOf childhandle |
|
444 |
||
445 |
val newProcList = (CMDPROC{ |
|
446 |
prover = prover, |
|
447 |
cmd = file, |
|
448 |
goalstring = goalstring, |
|
449 |
proc_handle = childhandle, |
|
450 |
instr = instr, |
|
451 |
outstr = outstr }) :: procList |
|
452 |
||
453 |
val _ = File.append (File.tmp_path (Path.basic "exec_child")) |
|
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
454 |
("\nFinished at " ^ |
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
455 |
Date.toString(Date.fromTimeLocal(Time.now()))) |
17234 | 456 |
in |
457 |
Posix.Process.sleep (Time.fromSeconds 1); |
|
458 |
execCmds cmds newProcList |
|
459 |
end |
|
15642 | 460 |
|
16039
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
461 |
|
17234 | 462 |
(****************************************) |
463 |
(* call resolution processes remotely *) |
|
464 |
(* settings should be a list of strings *) |
|
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
465 |
(* e.g. ["-t300", "-m100000"] *) |
17234 | 466 |
(****************************************) |
16061 | 467 |
|
17234 | 468 |
(* fun execRemoteCmds [] procList = procList |
17422 | 469 |
| execRemoteCmds ((prover, goalstring,proverCmd ,settings,file)::cmds) procList = |
470 |
let val newProcList = mySshExecuteToList ("/usr/bin/ssh",([prover,goalstring,"-t", "shep"]@[proverCmd]@settings@[file]), procList) |
|
471 |
in |
|
472 |
execRemoteCmds cmds newProcList |
|
473 |
end |
|
16039
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
474 |
*) |
15642 | 475 |
|
17234 | 476 |
(**********************************************) |
477 |
(* Watcher Loop *) |
|
478 |
(**********************************************) |
|
17306 | 479 |
val iterations_left = ref 1000; (*200 seconds, 5 iterations per sec*) |
16061 | 480 |
|
17234 | 481 |
fun keepWatching (toParentStr, fromParentStr,procList) = |
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
482 |
let fun loop procList = |
17234 | 483 |
let val _ = Posix.Process.sleep (Time.fromMilliseconds 200) |
484 |
val cmdsFromIsa = pollParentInput () |
|
485 |
in |
|
17306 | 486 |
iterations_left := !iterations_left - 1; |
17502 | 487 |
if !iterations_left = 0 |
488 |
then (*Sadly, this code fails to terminate the watcher!*) |
|
489 |
(TextIO.output(toParentStr, "Timeout: Killing proof processes!\n"); |
|
490 |
TextIO.flushOut toParentStr; |
|
491 |
killChildren (map cmdchildHandle procList)) |
|
17306 | 492 |
else if isSome cmdsFromIsa |
17234 | 493 |
then (* deal with input from Isabelle *) |
17306 | 494 |
if getProofCmd(hd(valOf cmdsFromIsa)) = "Kill children" |
17234 | 495 |
then |
496 |
let val child_handles = map cmdchildHandle procList |
|
497 |
in |
|
498 |
killChildren child_handles; |
|
17306 | 499 |
loop [] |
17234 | 500 |
end |
501 |
else |
|
17306 | 502 |
if length procList < 5 (********************) |
17234 | 503 |
then (* Execute locally *) |
504 |
let |
|
505 |
val newProcList = execCmds (valOf cmdsFromIsa) procList |
|
506 |
val parentID = Posix.ProcEnv.getppid() |
|
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
507 |
val _ = File.append (File.tmp_path (Path.basic "prekeep_watch")) |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
508 |
"Just execed a child\n" |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
509 |
val newProcList' = checkChildren (newProcList, toParentStr) |
17234 | 510 |
in |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
511 |
File.append (File.tmp_path (Path.basic "keep_watch")) |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
512 |
"Off to keep watching...\n"; |
17306 | 513 |
loop newProcList' |
17234 | 514 |
end |
515 |
else (* Execute remotely *) |
|
516 |
(* (actually not remote for now )*) |
|
517 |
let |
|
518 |
val newProcList = execCmds (valOf cmdsFromIsa) procList |
|
519 |
val parentID = Posix.ProcEnv.getppid() |
|
520 |
val newProcList' =checkChildren (newProcList, toParentStr) |
|
521 |
in |
|
17306 | 522 |
loop newProcList' |
17234 | 523 |
end |
524 |
else (* No new input from Isabelle *) |
|
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
525 |
let val newProcList = checkChildren (procList, toParentStr) |
17234 | 526 |
in |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
527 |
(File.append (File.tmp_path (Path.basic "keep_watch")) "Off to keep watching...2\n "); |
17306 | 528 |
loop newProcList |
17234 | 529 |
end |
530 |
end |
|
531 |
in |
|
17306 | 532 |
loop procList |
17234 | 533 |
end |
534 |
||
15642 | 535 |
|
17234 | 536 |
in |
537 |
(***************************) |
|
538 |
(*** Sort out pipes ********) |
|
539 |
(***************************) |
|
15642 | 540 |
|
17234 | 541 |
Posix.IO.close (#outfd p1); |
542 |
Posix.IO.close (#infd p2); |
|
543 |
Posix.IO.dup2{old = oldchildin, new = fromParent}; |
|
544 |
Posix.IO.close oldchildin; |
|
545 |
Posix.IO.dup2{old = oldchildout, new = toParent}; |
|
546 |
Posix.IO.close oldchildout; |
|
547 |
||
548 |
(***************************) |
|
549 |
(* start the watcher loop *) |
|
550 |
(***************************) |
|
551 |
keepWatching (toParentStr, fromParentStr, procList); |
|
552 |
(****************************************************************************) |
|
553 |
(* fake return value - actually want the watcher to loop until killed *) |
|
554 |
(****************************************************************************) |
|
555 |
Posix.Process.wordToPid 0w0 |
|
556 |
end); |
|
557 |
(* end case *) |
|
15642 | 558 |
|
559 |
||
16061 | 560 |
val _ = TextIO.flushOut TextIO.stdOut |
15642 | 561 |
|
16061 | 562 |
(*******************************) |
563 |
(*** set watcher going ********) |
|
564 |
(*******************************) |
|
15642 | 565 |
|
16061 | 566 |
val procList = [] |
17317
3f12de2e2e6e
Isabelle-ATP link: sortable axiom names; no spaces in switches; general tidying
paulson
parents:
17315
diff
changeset
|
567 |
val pid = startWatcher procList |
16061 | 568 |
(**************************************************) |
569 |
(* communication streams to watcher *) |
|
570 |
(**************************************************) |
|
15642 | 571 |
|
16061 | 572 |
val instr = openInFD ("_exec_in", #infd p2) |
573 |
val outstr = openOutFD ("_exec_out", #outfd p1) |
|
574 |
||
575 |
in |
|
576 |
(*******************************) |
|
577 |
(* close the child-side fds *) |
|
578 |
(*******************************) |
|
579 |
Posix.IO.close (#outfd p2); |
|
580 |
Posix.IO.close (#infd p1); |
|
581 |
(* set the fds close on exec *) |
|
582 |
Posix.IO.setfd (#infd p2, Posix.IO.FD.flags [Posix.IO.FD.cloexec]); |
|
583 |
Posix.IO.setfd (#outfd p1, Posix.IO.FD.flags [Posix.IO.FD.cloexec]); |
|
584 |
||
585 |
(*******************************) |
|
586 |
(* return value *) |
|
587 |
(*******************************) |
|
588 |
PROC{pid = pid, |
|
589 |
instr = instr, |
|
590 |
outstr = outstr |
|
591 |
} |
|
592 |
end; |
|
15642 | 593 |
|
594 |
||
595 |
||
596 |
(**********************************************************) |
|
597 |
(* Start a watcher and set up signal handlers *) |
|
598 |
(**********************************************************) |
|
16039
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
599 |
|
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
600 |
fun killWatcher pid = Posix.Process.kill(Posix.Process.K_PROC pid, Posix.Signal.kill); |
16039
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
601 |
|
17488
67376a311a2b
further simplification of the Isabelle-ATP linkup
paulson
parents:
17484
diff
changeset
|
602 |
val killWatcher' = killWatcher o ResLib.pidOfInt; |
67376a311a2b
further simplification of the Isabelle-ATP linkup
paulson
parents:
17484
diff
changeset
|
603 |
|
16039
dfe264950511
Moved some of the clausify functions from ATP/res_clasimpset.ML to res_axioms.ML.
quigley
parents:
15919
diff
changeset
|
604 |
fun reapWatcher(pid, instr, outstr) = |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
605 |
(TextIO.closeIn instr; TextIO.closeOut outstr; |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
606 |
Posix.Process.waitpid(Posix.Process.W_CHILD pid, []); ()) |
15642 | 607 |
|
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
608 |
fun createWatcher (thm, clause_arr) = |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
609 |
let val (childpid,(childin,childout)) = childInfo (setupWatcher(thm,clause_arr)) |
17435 | 610 |
fun decr_watched() = |
17502 | 611 |
(goals_being_watched := !goals_being_watched - 1; |
17435 | 612 |
if !goals_being_watched = 0 |
613 |
then |
|
614 |
(File.append (File.tmp_path (Path.basic "reap_found")) |
|
615 |
("Reaping a watcher, childpid = "^ |
|
616 |
LargeWord.toString (Posix.Process.pidToWord childpid)^"\n"); |
|
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
617 |
killWatcher childpid; reapWatcher (childpid,childin, childout)) |
17435 | 618 |
else ()) |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
619 |
val _ = debug ("subgoals forked to createWatcher: "^ prems_string_of thm); |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
620 |
fun proofHandler n = |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
621 |
let val outcome = TextIO.inputLine childin |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
622 |
val goalstring = TextIO.inputLine childin |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
623 |
val _ = debug ("In signal handler. outcome = \"" ^ outcome ^ |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
624 |
"\"\ngoalstring = " ^ goalstring ^ |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
625 |
"\ngoals_being_watched: "^ string_of_int (!goals_being_watched)) |
17502 | 626 |
in |
627 |
if String.isPrefix "[" outcome (*indicates a proof reconstruction*) |
|
17216 | 628 |
then (Pretty.writeln(Pretty.str ( (concat[(oct_char "360"), (oct_char "377")]))); |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
629 |
Recon_Transfer.apply_res_thm outcome goalstring; |
17216 | 630 |
Pretty.writeln(Pretty.str (oct_char "361")); |
17435 | 631 |
decr_watched()) |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
632 |
else if String.isPrefix "Invalid" outcome |
17435 | 633 |
then (Pretty.writeln(Pretty.str ( (concat[(oct_char "360"), (oct_char "377")]))); |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
634 |
Pretty.writeln(Pretty.str ((Recon_Transfer.restore_linebreaks goalstring) |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
635 |
^ "is not provable")); |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
636 |
Pretty.writeln(Pretty.str (oct_char "361")); |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
637 |
decr_watched()) |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
638 |
else if String.isPrefix "Failure" outcome |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
639 |
then (Pretty.writeln(Pretty.str ( (concat[(oct_char "360"), (oct_char "377")]))); |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
640 |
Pretty.writeln(Pretty.str ((Recon_Transfer.restore_linebreaks goalstring) |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
641 |
^ "proof attempt failed")); |
17216 | 642 |
Pretty.writeln(Pretty.str (oct_char "361")); |
17435 | 643 |
decr_watched()) |
17216 | 644 |
(* print out a list of rules used from clasimpset*) |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
645 |
else if String.isPrefix "Success" outcome |
17435 | 646 |
then (Pretty.writeln(Pretty.str ( (concat[(oct_char "360"), (oct_char "377")]))); |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
647 |
Pretty.writeln(Pretty.str (goalstring^outcome)); |
17216 | 648 |
Pretty.writeln(Pretty.str (oct_char "361")); |
17435 | 649 |
decr_watched()) |
17216 | 650 |
(* if proof translation failed *) |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
651 |
else if String.isPrefix "Translation failed" outcome |
17435 | 652 |
then (Pretty.writeln(Pretty.str ( (concat[(oct_char "360"), (oct_char "377")]))); |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
653 |
Pretty.writeln(Pretty.str (goalstring^(Recon_Transfer.restore_linebreaks outcome))); |
17216 | 654 |
Pretty.writeln(Pretty.str (oct_char "361")); |
17435 | 655 |
decr_watched()) |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
656 |
else |
17435 | 657 |
(Pretty.writeln(Pretty.str ( (concat[(oct_char "360"), (oct_char "377")]))); |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
658 |
Pretty.writeln(Pretty.str ("System error in proof handler")); |
17231 | 659 |
Pretty.writeln(Pretty.str (oct_char "361")); |
17435 | 660 |
decr_watched()) |
17484
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
661 |
end |
f6a225f97f0a
simplification of the Isabelle-ATP code; hooks for batch generation of problems
paulson
parents:
17435
diff
changeset
|
662 |
in IsaSignal.signal (IsaSignal.usr2, IsaSignal.SIG_HANDLE proofHandler); |
17216 | 663 |
(childin, childout, childpid) |
664 |
end |
|
15642 | 665 |
|
666 |
end (* structure Watcher *) |