author | Philipp Meyer |
Tue, 01 Sep 2009 11:19:49 +0200 | |
changeset 32542 | e37c0ddf257e |
parent 32362 | c0c640d86b4e |
permissions | -rwxr-xr-x |
32268
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
Philipp Meyer
parents:
diff
changeset
|
1 |
#!/usr/bin/env python |
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
Philipp Meyer
parents:
diff
changeset
|
2 |
import sys |
32362 | 3 |
import signal |
32268
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
Philipp Meyer
parents:
diff
changeset
|
4 |
import xmlrpclib |
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
Philipp Meyer
parents:
diff
changeset
|
5 |
import time |
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
Philipp Meyer
parents:
diff
changeset
|
6 |
import re |
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
Philipp Meyer
parents:
diff
changeset
|
7 |
|
32332 | 8 |
# Neos server config |
9 |
NEOS_HOST="neos.mcs.anl.gov" |
|
10 |
NEOS_PORT=3332 |
|
32268
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
Philipp Meyer
parents:
diff
changeset
|
11 |
|
32542 | 12 |
neos=xmlrpclib.Server("http://%s:%d" % (NEOS_HOST, NEOS_PORT)) |
13 |
||
32362 | 14 |
jobNumber = 0 |
15 |
password = "" |
|
16 |
inputfile = None |
|
17 |
outputfile = None |
|
18 |
# interrupt handler |
|
19 |
def cleanup(signal, frame): |
|
20 |
sys.stdout.write("Caught interrupt, cleaning up\n") |
|
21 |
if jobNumber != 0: |
|
22 |
neos.killJob(jobNumber, password) |
|
23 |
if inputfile != None: |
|
24 |
inputfile.close() |
|
25 |
if outputfile != None: |
|
26 |
outputfile.close() |
|
27 |
sys.exit(21) |
|
28 |
||
29 |
signal.signal(signal.SIGHUP, cleanup) |
|
30 |
signal.signal(signal.SIGINT, cleanup) |
|
31 |
signal.signal(signal.SIGQUIT, cleanup) |
|
32 |
signal.signal(signal.SIGTERM, cleanup) |
|
33 |
||
34 |
if len(sys.argv) <> 3: |
|
35 |
sys.stderr.write("Usage: neos_csdp_client <input_filename> <output_filename>\n") |
|
36 |
sys.exit(19) |
|
32268
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
Philipp Meyer
parents:
diff
changeset
|
37 |
|
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
Philipp Meyer
parents:
diff
changeset
|
38 |
xml_pre = "<document>\n<category>sdp</category>\n<solver>csdp</solver>\n<inputMethod>SPARSE_SDPA</inputMethod>\n<dat><![CDATA[" |
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
Philipp Meyer
parents:
diff
changeset
|
39 |
xml_post = "]]></dat>\n</document>\n" |
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
Philipp Meyer
parents:
diff
changeset
|
40 |
xml = xml_pre |
32362 | 41 |
inputfile = open(sys.argv[1],"r") |
32268
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
Philipp Meyer
parents:
diff
changeset
|
42 |
buffer = 1 |
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
Philipp Meyer
parents:
diff
changeset
|
43 |
while buffer: |
32332 | 44 |
buffer = inputfile.read() |
32268
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
Philipp Meyer
parents:
diff
changeset
|
45 |
xml += buffer |
32332 | 46 |
inputfile.close() |
32268
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
Philipp Meyer
parents:
diff
changeset
|
47 |
xml += xml_post |
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
Philipp Meyer
parents:
diff
changeset
|
48 |
|
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
Philipp Meyer
parents:
diff
changeset
|
49 |
(jobNumber,password) = neos.submitJob(xml) |
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
Philipp Meyer
parents:
diff
changeset
|
50 |
|
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
Philipp Meyer
parents:
diff
changeset
|
51 |
if jobNumber == 0: |
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
Philipp Meyer
parents:
diff
changeset
|
52 |
sys.stdout.write("error submitting job: %s" % password) |
32332 | 53 |
sys.exit(20) |
32268
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
Philipp Meyer
parents:
diff
changeset
|
54 |
else: |
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
Philipp Meyer
parents:
diff
changeset
|
55 |
sys.stdout.write("jobNumber = %d\tpassword = %s\n" % (jobNumber,password)) |
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
Philipp Meyer
parents:
diff
changeset
|
56 |
|
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
Philipp Meyer
parents:
diff
changeset
|
57 |
offset=0 |
32332 | 58 |
messages = "" |
32268
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
Philipp Meyer
parents:
diff
changeset
|
59 |
status="Waiting" |
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
Philipp Meyer
parents:
diff
changeset
|
60 |
while status == "Running" or status=="Waiting": |
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
Philipp Meyer
parents:
diff
changeset
|
61 |
time.sleep(1) |
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
Philipp Meyer
parents:
diff
changeset
|
62 |
(msg,offset) = neos.getIntermediateResults(jobNumber,password,offset) |
32332 | 63 |
messages += msg.data |
32268
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
Philipp Meyer
parents:
diff
changeset
|
64 |
sys.stdout.write(msg.data) |
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
Philipp Meyer
parents:
diff
changeset
|
65 |
status = neos.getJobStatus(jobNumber, password) |
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
Philipp Meyer
parents:
diff
changeset
|
66 |
|
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
Philipp Meyer
parents:
diff
changeset
|
67 |
msg = neos.getFinalResults(jobNumber, password).data |
32332 | 68 |
sys.stdout.write("---------- Begin CSDP Output -------------\n"); |
69 |
sys.stdout.write(msg) |
|
32268
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
Philipp Meyer
parents:
diff
changeset
|
70 |
|
32332 | 71 |
# extract solution |
72 |
result = msg.split("Solution:") |
|
32268
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
Philipp Meyer
parents:
diff
changeset
|
73 |
if len(result) > 1: |
32362 | 74 |
solution = result[1].strip() |
75 |
if solution != "": |
|
32542 | 76 |
outputfile = open(sys.argv[2],"w") |
77 |
outputfile.write(solution) |
|
78 |
outputfile.close() |
|
32268
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
Philipp Meyer
parents:
diff
changeset
|
79 |
|
32332 | 80 |
# extract return code |
81 |
p = re.compile(r"^Error: Command exited with non-zero status (\d+)$", re.MULTILINE) |
|
82 |
m = p.search(messages) |
|
83 |
if m: |
|
84 |
sys.exit(int(m.group(1))) |
|
85 |
else: |
|
86 |
sys.exit(0) |
|
32268
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
Philipp Meyer
parents:
diff
changeset
|
87 |