author | blanchet |
Mon, 29 Mar 2010 12:01:00 +0200 | |
changeset 36058 | 8256d5a185bd |
parent 35969 | c9565298df9e |
child 36059 | ab3dfdeb9603 |
permissions | -rw-r--r-- |
32327
0971cc0b6a57
src/HOL/Tools/ATP_Manager as separate component, with (almost) everything in one place;
wenzelm
parents:
31793
diff
changeset
|
1 |
(* Title: HOL/Tools/ATP_Manager/atp_manager.ML |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
2 |
Author: Fabian Immler, TU Muenchen |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
3 |
Author: Makarius |
35969 | 4 |
Author: Jasmin Blanchette, TU Muenchen |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
5 |
|
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
6 |
Central manager component for ATP threads. |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
7 |
*) |
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
8 |
|
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
9 |
signature ATP_MANAGER = |
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
10 |
sig |
35969 | 11 |
type relevance_override = Sledgehammer_Fact_Filter.relevance_override |
12 |
type params = |
|
13 |
{debug: bool, |
|
14 |
verbose: bool, |
|
15 |
atps: string list, |
|
16 |
full_types: bool, |
|
36058
8256d5a185bd
added "respect_no_atp" and "convergence" options to Sledgehammer;
blanchet
parents:
35969
diff
changeset
|
17 |
respect_no_atp: bool, |
35969 | 18 |
relevance_threshold: real, |
36058
8256d5a185bd
added "respect_no_atp" and "convergence" options to Sledgehammer;
blanchet
parents:
35969
diff
changeset
|
19 |
convergence: real, |
35969 | 20 |
higher_order: bool option, |
21 |
follow_defs: bool, |
|
22 |
isar_proof: bool, |
|
23 |
timeout: Time.time, |
|
24 |
minimize_timeout: Time.time} |
|
35867 | 25 |
type problem = |
35969 | 26 |
{subgoal: int, |
27 |
goal: Proof.context * (thm list * thm), |
|
28 |
relevance_override: relevance_override, |
|
29 |
axiom_clauses: (thm * (string * int)) list option, |
|
30 |
filtered_clauses: (thm * (string * int)) list option} |
|
35867 | 31 |
type prover_result = |
35969 | 32 |
{success: bool, |
33 |
message: string, |
|
34 |
relevant_thm_names: string list, |
|
35 |
atp_run_time_in_msecs: int, |
|
36 |
proof: string, |
|
37 |
internal_thm_names: string Vector.vector, |
|
38 |
filtered_clauses: (thm * (string * int)) list} |
|
39 |
type prover = params -> Time.time -> problem -> prover_result |
|
35867 | 40 |
|
32937
34f66c9dd8a2
structure ATP_Manager: eliminated slightly odd get/set operations in favour of Unsynchronized.ref;
wenzelm
parents:
32936
diff
changeset
|
41 |
val atps: string Unsynchronized.ref |
34f66c9dd8a2
structure ATP_Manager: eliminated slightly odd get/set operations in favour of Unsynchronized.ref;
wenzelm
parents:
32936
diff
changeset
|
42 |
val timeout: int Unsynchronized.ref |
34f66c9dd8a2
structure ATP_Manager: eliminated slightly odd get/set operations in favour of Unsynchronized.ref;
wenzelm
parents:
32936
diff
changeset
|
43 |
val full_types: bool Unsynchronized.ref |
35969 | 44 |
val kill_atps: unit -> unit |
45 |
val running_atps: unit -> unit |
|
29112
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
46 |
val messages: int option -> unit |
35867 | 47 |
val add_prover: string * prover -> theory -> theory |
48 |
val get_prover: theory -> string -> prover option |
|
35969 | 49 |
val available_atps: theory -> unit |
50 |
val sledgehammer: params -> int -> relevance_override -> Proof.state -> unit |
|
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
51 |
end; |
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
52 |
|
35865 | 53 |
structure ATP_Manager : ATP_MANAGER = |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
54 |
struct |
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
55 |
|
35969 | 56 |
type relevance_override = Sledgehammer_Fact_Filter.relevance_override |
57 |
||
58 |
(** parameters, problems, results, and provers **) |
|
59 |
||
36058
8256d5a185bd
added "respect_no_atp" and "convergence" options to Sledgehammer;
blanchet
parents:
35969
diff
changeset
|
60 |
(* TODO: "theory_const" *) |
35969 | 61 |
type params = |
62 |
{debug: bool, |
|
63 |
verbose: bool, |
|
64 |
atps: string list, |
|
65 |
full_types: bool, |
|
36058
8256d5a185bd
added "respect_no_atp" and "convergence" options to Sledgehammer;
blanchet
parents:
35969
diff
changeset
|
66 |
respect_no_atp: bool, |
35969 | 67 |
relevance_threshold: real, |
36058
8256d5a185bd
added "respect_no_atp" and "convergence" options to Sledgehammer;
blanchet
parents:
35969
diff
changeset
|
68 |
convergence: real, |
35969 | 69 |
higher_order: bool option, |
70 |
follow_defs: bool, |
|
71 |
isar_proof: bool, |
|
72 |
timeout: Time.time, |
|
73 |
minimize_timeout: Time.time} |
|
35867 | 74 |
|
75 |
type problem = |
|
35969 | 76 |
{subgoal: int, |
77 |
goal: Proof.context * (thm list * thm), |
|
78 |
relevance_override: relevance_override, |
|
79 |
axiom_clauses: (thm * (string * int)) list option, |
|
80 |
filtered_clauses: (thm * (string * int)) list option}; |
|
35867 | 81 |
|
82 |
type prover_result = |
|
35969 | 83 |
{success: bool, |
84 |
message: string, |
|
85 |
relevant_thm_names: string list, |
|
86 |
atp_run_time_in_msecs: int, |
|
87 |
proof: string, |
|
88 |
internal_thm_names: string Vector.vector, |
|
89 |
filtered_clauses: (thm * (string * int)) list}; |
|
35867 | 90 |
|
35969 | 91 |
type prover = params -> Time.time -> problem -> prover_result; |
35867 | 92 |
|
93 |
||
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
94 |
(** preferences **) |
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
95 |
|
29112
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
96 |
val message_store_limit = 20; |
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
97 |
val message_display_limit = 5; |
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
98 |
|
32937
34f66c9dd8a2
structure ATP_Manager: eliminated slightly odd get/set operations in favour of Unsynchronized.ref;
wenzelm
parents:
32936
diff
changeset
|
99 |
val atps = Unsynchronized.ref "e spass remote_vampire"; |
32740 | 100 |
val timeout = Unsynchronized.ref 60; |
101 |
val full_types = Unsynchronized.ref false; |
|
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
102 |
|
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
103 |
val _ = |
30982 | 104 |
ProofGeneralPgip.add_preference Preferences.category_proof |
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
105 |
(Preferences.string_pref atps |
28589
581b2ab9827a
adding preferences is now permissive, no error handling here;
wenzelm
parents:
28586
diff
changeset
|
106 |
"ATP: provers" "Default automatic provers (separated by whitespace)"); |
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
107 |
|
30982 | 108 |
val _ = |
109 |
ProofGeneralPgip.add_preference Preferences.category_proof |
|
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
110 |
(Preferences.int_pref timeout |
28589
581b2ab9827a
adding preferences is now permissive, no error handling here;
wenzelm
parents:
28586
diff
changeset
|
111 |
"ATP: timeout" "ATPs will be interrupted after this time (in seconds)"); |
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
112 |
|
31791 | 113 |
val _ = |
114 |
ProofGeneralPgip.add_preference Preferences.category_proof |
|
115 |
(Preferences.bool_pref full_types |
|
116 |
"ATP: full types" "ATPs will use full type information"); |
|
117 |
||
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
118 |
|
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
119 |
|
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
120 |
(** thread management **) |
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
121 |
|
28582 | 122 |
(* data structures over threads *) |
123 |
||
32939 | 124 |
structure Thread_Heap = Heap |
28582 | 125 |
( |
126 |
type elem = Time.time * Thread.thread; |
|
127 |
fun ord ((a, _), (b, _)) = Time.compare (a, b); |
|
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
128 |
); |
28582 | 129 |
|
31368 | 130 |
fun lookup_thread xs = AList.lookup Thread.equal xs; |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
131 |
fun delete_thread xs = AList.delete Thread.equal xs; |
31368 | 132 |
fun update_thread xs = AList.update Thread.equal xs; |
28582 | 133 |
|
134 |
||
135 |
(* state of thread manager *) |
|
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
136 |
|
32938 | 137 |
type state = |
138 |
{manager: Thread.thread option, |
|
139 |
timeout_heap: Thread_Heap.T, |
|
28582 | 140 |
active: (Thread.thread * (Time.time * Time.time * string)) list, |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
141 |
cancelling: (Thread.thread * (Time.time * string)) list, |
29620 | 142 |
messages: string list, |
143 |
store: string list}; |
|
28582 | 144 |
|
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
145 |
fun make_state manager timeout_heap active cancelling messages store : state = |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
146 |
{manager = manager, timeout_heap = timeout_heap, active = active, |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
147 |
cancelling = cancelling, messages = messages, store = store}; |
28582 | 148 |
|
32938 | 149 |
val global_state = Synchronized.var "atp_manager" |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
150 |
(make_state NONE Thread_Heap.empty [] [] [] []); |
28582 | 151 |
|
31368 | 152 |
|
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
153 |
(* unregister ATP thread *) |
28582 | 154 |
|
33312 | 155 |
fun unregister message thread = Synchronized.change global_state |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
156 |
(fn state as {manager, timeout_heap, active, cancelling, messages, store} => |
29150
8af5ee47f30c
unregister: refrain from cancelling self, which sometimes caused sledghammer to fail just before printing the result;
wenzelm
parents:
29116
diff
changeset
|
157 |
(case lookup_thread active thread of |
35569 | 158 |
SOME (_, _, description) => |
29150
8af5ee47f30c
unregister: refrain from cancelling self, which sometimes caused sledghammer to fail just before printing the result;
wenzelm
parents:
29116
diff
changeset
|
159 |
let |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
160 |
val active' = delete_thread thread active; |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
161 |
val cancelling' = (thread, (Time.now (), description)) :: cancelling; |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
162 |
val message' = description ^ "\n" ^ message; |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
163 |
val messages' = message' :: messages; |
29620 | 164 |
val store' = message' :: |
165 |
(if length store <= message_store_limit then store |
|
32938 | 166 |
else #1 (chop message_store_limit store)); |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
167 |
in make_state manager timeout_heap active' cancelling' messages' store' end |
30800 | 168 |
| NONE => state)); |
28582 | 169 |
|
170 |
||
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
171 |
(* main manager thread -- only one may exist *) |
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
172 |
|
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
173 |
val min_wait_time = Time.fromMilliseconds 300; |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
174 |
val max_wait_time = Time.fromSeconds 10; |
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
175 |
|
29620 | 176 |
fun print_new_messages () = |
32938 | 177 |
let val msgs = Synchronized.change_result global_state |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
178 |
(fn {manager, timeout_heap, active, cancelling, messages, store} => |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
179 |
(messages, make_state manager timeout_heap active cancelling [] store)) |
30800 | 180 |
in |
32938 | 181 |
if null msgs then () |
182 |
else priority ("Sledgehammer: " ^ space_implode "\n\n" msgs) |
|
30800 | 183 |
end; |
29620 | 184 |
|
32938 | 185 |
fun check_thread_manager () = Synchronized.change global_state |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
186 |
(fn state as {manager, timeout_heap, active, cancelling, messages, store} => |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
187 |
if (case manager of SOME thread => Thread.isActive thread | NONE => false) then state |
33604
d4220df6fde2
Toplevel.thread provides Isar-style exception output;
wenzelm
parents:
33522
diff
changeset
|
188 |
else let val manager = SOME (Toplevel.thread false (fn () => |
32938 | 189 |
let |
190 |
fun time_limit timeout_heap = |
|
191 |
(case try Thread_Heap.min timeout_heap of |
|
192 |
NONE => Time.+ (Time.now (), max_wait_time) |
|
193 |
| SOME (time, _) => time); |
|
28582 | 194 |
|
32938 | 195 |
(*action: find threads whose timeout is reached, and interrupt cancelling threads*) |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
196 |
fun action {manager, timeout_heap, active, cancelling, messages, store} = |
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
197 |
let val (timeout_threads, timeout_heap') = |
32938 | 198 |
Thread_Heap.upto (Time.now (), Thread.self ()) timeout_heap; |
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
199 |
in |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
200 |
if null timeout_threads andalso null cancelling |
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
201 |
then NONE |
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
202 |
else |
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
203 |
let |
32938 | 204 |
val _ = List.app (SimpleThread.interrupt o #1) cancelling; |
205 |
val cancelling' = filter (Thread.isActive o #1) cancelling; |
|
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
206 |
val state' = make_state manager timeout_heap' active cancelling' messages store; |
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
207 |
in SOME (map #2 timeout_threads, state') end |
32938 | 208 |
end; |
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
209 |
in |
32938 | 210 |
while Synchronized.change_result global_state |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
211 |
(fn state as {timeout_heap, active, cancelling, messages, store, ...} => |
32938 | 212 |
if null active andalso null cancelling andalso null messages |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
213 |
then (false, make_state NONE timeout_heap active cancelling messages store) |
32938 | 214 |
else (true, state)) |
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
215 |
do |
32938 | 216 |
(Synchronized.timed_access global_state (SOME o time_limit o #timeout_heap) action |
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
217 |
|> these |
33312 | 218 |
|> List.app (unregister "Interrupted (reached timeout)"); |
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
219 |
print_new_messages (); |
32938 | 220 |
(*give threads some time to respond to interrupt*) |
30830
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
221 |
OS.Process.sleep min_wait_time) |
263064c4d0c3
included managing_thread in state of AtpManager:
immler@in.tum.de
parents:
30800
diff
changeset
|
222 |
end)) |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
223 |
in make_state manager timeout_heap active cancelling messages store end); |
28582 | 224 |
|
225 |
||
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
226 |
(* register ATP thread *) |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
227 |
|
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
228 |
fun register birth_time death_time (thread, desc) = |
32938 | 229 |
(Synchronized.change global_state |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
230 |
(fn {manager, timeout_heap, active, cancelling, messages, store} => |
29112
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
231 |
let |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
232 |
val timeout_heap' = Thread_Heap.insert (death_time, thread) timeout_heap; |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
233 |
val active' = update_thread (thread, (birth_time, death_time, desc)) active; |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
234 |
val state' = make_state manager timeout_heap' active' cancelling messages store; |
32938 | 235 |
in state' end); |
30798 | 236 |
check_thread_manager ()); |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
237 |
|
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
238 |
|
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
239 |
|
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
240 |
(** user commands **) |
28582 | 241 |
|
35969 | 242 |
(* kill ATPs *) |
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
243 |
|
35969 | 244 |
fun kill_atps () = Synchronized.change global_state |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
245 |
(fn {manager, timeout_heap, active, cancelling, messages, store} => |
32938 | 246 |
let |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
247 |
val killing = map (fn (th, (_, _, desc)) => (th, (Time.now (), desc))) active; |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
248 |
val state' = make_state manager timeout_heap [] (killing @ cancelling) messages store; |
32938 | 249 |
in state' end); |
28582 | 250 |
|
251 |
||
35969 | 252 |
(* running_atps *) |
28582 | 253 |
|
32938 | 254 |
fun seconds time = string_of_int (Time.toSeconds time) ^ "s"; |
255 |
||
35969 | 256 |
fun running_atps () = |
28582 | 257 |
let |
32938 | 258 |
val {active, cancelling, ...} = Synchronized.value global_state; |
29112
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
259 |
|
32938 | 260 |
val now = Time.now (); |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
261 |
fun running_info (_, (birth_time, death_time, desc)) = |
32938 | 262 |
"Running: " ^ seconds (Time.- (now, birth_time)) ^ " -- " ^ |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
263 |
seconds (Time.- (death_time, now)) ^ " to live:\n" ^ desc; |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
264 |
fun cancelling_info (_, (deadth_time, desc)) = |
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
265 |
"Trying to interrupt thread since " ^ seconds (Time.- (now, deadth_time)) ^ ":\n" ^ desc; |
29112
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
266 |
|
28589
581b2ab9827a
adding preferences is now permissive, no error handling here;
wenzelm
parents:
28586
diff
changeset
|
267 |
val running = |
581b2ab9827a
adding preferences is now permissive, no error handling here;
wenzelm
parents:
28586
diff
changeset
|
268 |
if null active then "No ATPs running." |
32938 | 269 |
else space_implode "\n\n" ("Running ATPs:" :: map running_info active); |
28589
581b2ab9827a
adding preferences is now permissive, no error handling here;
wenzelm
parents:
28586
diff
changeset
|
270 |
val interrupting = |
581b2ab9827a
adding preferences is now permissive, no error handling here;
wenzelm
parents:
28586
diff
changeset
|
271 |
if null cancelling then "" |
32938 | 272 |
else |
273 |
space_implode "\n\n" |
|
274 |
("Trying to interrupt the following ATPs:" :: map cancelling_info cancelling); |
|
29112
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
275 |
|
28582 | 276 |
in writeln (running ^ "\n" ^ interrupting) end; |
277 |
||
29112
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
278 |
fun messages opt_limit = |
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
279 |
let |
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
280 |
val limit = the_default message_display_limit opt_limit; |
32938 | 281 |
val {store, ...} = Synchronized.value global_state; |
282 |
val header = |
|
283 |
"Recent ATP messages" ^ |
|
284 |
(if length store <= limit then ":" else " (" ^ string_of_int limit ^ " displayed):"); |
|
285 |
in writeln (space_implode "\n\n" (header :: #1 (chop limit store))) end; |
|
29112
f2b45eea6dac
added 'atp_messages' command, which displays recent messages synchronously;
wenzelm
parents:
28835
diff
changeset
|
286 |
|
28582 | 287 |
|
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
288 |
|
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
289 |
(** The Sledgehammer **) |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
290 |
|
28582 | 291 |
(* named provers *) |
28484 | 292 |
|
28582 | 293 |
fun err_dup_prover name = error ("Duplicate prover: " ^ quote name); |
28477
9339d4dcec8b
version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents:
diff
changeset
|
294 |
|
33522 | 295 |
structure Provers = Theory_Data |
28582 | 296 |
( |
35867 | 297 |
type T = (prover * stamp) Symtab.table; |
32938 | 298 |
val empty = Symtab.empty; |
299 |
val extend = I; |
|
33522 | 300 |
fun merge data : T = Symtab.merge (eq_snd op =) data |
32938 | 301 |
handle Symtab.DUP dup => err_dup_prover dup; |
28582 | 302 |
); |
28484 | 303 |
|
32864
a226f29d4bdc
re-organized signature of AtpWrapper structure: records instead of unnamed parameters and return values,
boehmes
parents:
32824
diff
changeset
|
304 |
fun add_prover (name, prover) thy = |
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
305 |
Provers.map (Symtab.update_new (name, (prover, stamp ()))) thy |
28582 | 306 |
handle Symtab.DUP dup => err_dup_prover dup; |
307 |
||
32995 | 308 |
fun get_prover thy name = |
309 |
Option.map #1 (Symtab.lookup (Provers.get thy) name); |
|
310 |
||
35969 | 311 |
fun available_atps thy = Pretty.writeln |
312 |
(Pretty.strs ("ATPs:" :: sort_strings (Symtab.keys (Provers.get thy)))); |
|
28571 | 313 |
|
28586
d238b83ba3fc
renamed kill_all to kill, in conformance with atp_kill command;
wenzelm
parents:
28582
diff
changeset
|
314 |
|
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
315 |
(* start prover thread *) |
28484 | 316 |
|
35969 | 317 |
fun start_prover (params as {timeout, ...}) birth_time death_time i |
318 |
relevance_override proof_state name = |
|
32947
3c19b98a35cd
ATP_Manager.get_prover: canonical argument order;
wenzelm
parents:
32941
diff
changeset
|
319 |
(case get_prover (Proof.theory_of proof_state) name of |
35969 | 320 |
NONE => warning ("Unknown ATP: " ^ quote name) |
31037
ac8669134e7a
added Philipp Meyer's implementation of AtpMinimal
immler@in.tum.de
parents:
30982
diff
changeset
|
321 |
| SOME prover => |
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
322 |
let |
35592
768d17f54125
use regular Proof.goal (which is what methods usually see) and prevent sledgehammer from crashing;
wenzelm
parents:
35569
diff
changeset
|
323 |
val {context = ctxt, facts, goal} = Proof.goal proof_state; |
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
324 |
val desc = |
35969 | 325 |
"ATP " ^ quote name ^ " for subgoal " ^ string_of_int i ^ ":\n" ^ |
32938 | 326 |
Syntax.string_of_term ctxt (Thm.term_of (Thm.cprem_of goal i)); |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
327 |
|
33604
d4220df6fde2
Toplevel.thread provides Isar-style exception output;
wenzelm
parents:
33522
diff
changeset
|
328 |
val _ = Toplevel.thread true (fn () => |
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
329 |
let |
32996
d2e48879e65a
removed disjunctive group cancellation -- provers run independently;
wenzelm
parents:
32995
diff
changeset
|
330 |
val _ = register birth_time death_time (Thread.self (), desc); |
35969 | 331 |
val problem = |
332 |
{subgoal = i, goal = (ctxt, (facts, goal)), |
|
333 |
relevance_override = relevance_override, axiom_clauses = NONE, |
|
334 |
filtered_clauses = NONE} |
|
335 |
val message = #message (prover params timeout problem) |
|
35865 | 336 |
handle Sledgehammer_HOL_Clause.TRIVIAL => (* FIXME !? *) |
35969 | 337 |
"Try this command: " ^ |
338 |
Markup.markup Markup.sendback "by metis" ^ "." |
|
33312 | 339 |
| ERROR msg => ("Error: " ^ msg); |
340 |
val _ = unregister message (Thread.self ()); |
|
35569 | 341 |
in () end); |
28595
67e3945b53f1
add_prover: plain prover function, without thread;
wenzelm
parents:
28589
diff
changeset
|
342 |
in () end); |
28582 | 343 |
|
344 |
||
35969 | 345 |
(* Sledgehammer the given subgoal *) |
28582 | 346 |
|
35969 | 347 |
fun sledgehammer (params as {atps, timeout, ...}) i relevance_override |
348 |
proof_state = |
|
28582 | 349 |
let |
35969 | 350 |
val birth_time = Time.now () |
351 |
val death_time = Time.+ (birth_time, timeout) |
|
352 |
val _ = kill_atps () (* RACE w.r.t. other invocations of Sledgehammer *) |
|
353 |
val _ = priority "Sledgehammering..." |
|
354 |
val _ = List.app (start_prover params birth_time death_time i |
|
355 |
relevance_override proof_state) atps |
|
356 |
in () end |
|
28582 | 357 |
|
358 |
end; |