| author | nipkow | 
| Sun, 26 May 2013 11:56:55 +0200 | |
| changeset 52149 | 32b1dbda331c | 
| parent 41947 | 0b8a13b145e9 | 
| 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 | 
| 41475 
fe4f0d9f9dbb
updated NEOS_SERVER, which is now provided via settings;
 wenzelm parents: 
41474diff
changeset | 7 | import os | 
| 32268 
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
 Philipp Meyer parents: diff
changeset | 8 | |
| 32332 | 9 | # Neos server config | 
| 41947 | 10 | neos = xmlrpclib.Server(os.getenv("ISABELLE_NEOS_SERVER"))
 | 
| 32542 | 11 | |
| 32362 | 12 | jobNumber = 0 | 
| 13 | password = "" | |
| 14 | inputfile = None | |
| 15 | outputfile = None | |
| 16 | # interrupt handler | |
| 17 | def cleanup(signal, frame): | |
| 18 |   sys.stdout.write("Caught interrupt, cleaning up\n")
 | |
| 19 | if jobNumber != 0: | |
| 20 | neos.killJob(jobNumber, password) | |
| 21 | if inputfile != None: | |
| 22 | inputfile.close() | |
| 23 | if outputfile != None: | |
| 24 | outputfile.close() | |
| 25 | sys.exit(21) | |
| 26 | ||
| 27 | signal.signal(signal.SIGHUP, cleanup) | |
| 28 | signal.signal(signal.SIGINT, cleanup) | |
| 29 | signal.signal(signal.SIGQUIT, cleanup) | |
| 30 | signal.signal(signal.SIGTERM, cleanup) | |
| 31 | ||
| 32 | if len(sys.argv) <> 3: | |
| 33 |   sys.stderr.write("Usage: neos_csdp_client <input_filename> <output_filename>\n")
 | |
| 34 | sys.exit(19) | |
| 32268 
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
 Philipp Meyer parents: diff
changeset | 35 | |
| 
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
 Philipp Meyer parents: diff
changeset | 36 | 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 | 37 | xml_post = "]]></dat>\n</document>\n" | 
| 
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
 Philipp Meyer parents: diff
changeset | 38 | xml = xml_pre | 
| 32362 | 39 | inputfile = open(sys.argv[1],"r") | 
| 32268 
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
 Philipp Meyer parents: diff
changeset | 40 | buffer = 1 | 
| 
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
 Philipp Meyer parents: diff
changeset | 41 | while buffer: | 
| 32332 | 42 | buffer = inputfile.read() | 
| 32268 
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
 Philipp Meyer parents: diff
changeset | 43 | xml += buffer | 
| 32332 | 44 | inputfile.close() | 
| 32268 
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
 Philipp Meyer parents: diff
changeset | 45 | xml += xml_post | 
| 
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
 Philipp Meyer parents: diff
changeset | 46 | |
| 
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
 Philipp Meyer parents: diff
changeset | 47 | (jobNumber,password) = neos.submitJob(xml) | 
| 
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 | if jobNumber == 0: | 
| 
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
 Philipp Meyer parents: diff
changeset | 50 |   sys.stdout.write("error submitting job: %s" % password)
 | 
| 32332 | 51 | sys.exit(20) | 
| 32268 
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
 Philipp Meyer parents: diff
changeset | 52 | else: | 
| 
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
 Philipp Meyer parents: diff
changeset | 53 |   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 | 54 | |
| 
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
 Philipp Meyer parents: diff
changeset | 55 | offset=0 | 
| 32332 | 56 | messages = "" | 
| 32268 
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
 Philipp Meyer parents: diff
changeset | 57 | status="Waiting" | 
| 
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
 Philipp Meyer parents: diff
changeset | 58 | while status == "Running" or status=="Waiting": | 
| 
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
 Philipp Meyer parents: diff
changeset | 59 | time.sleep(1) | 
| 
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
 Philipp Meyer parents: diff
changeset | 60 | (msg,offset) = neos.getIntermediateResults(jobNumber,password,offset) | 
| 32332 | 61 | messages += msg.data | 
| 32268 
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
 Philipp Meyer parents: diff
changeset | 62 | sys.stdout.write(msg.data) | 
| 
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
 Philipp Meyer parents: diff
changeset | 63 | status = neos.getJobStatus(jobNumber, password) | 
| 
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
 Philipp Meyer parents: diff
changeset | 64 | |
| 
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
 Philipp Meyer parents: diff
changeset | 65 | msg = neos.getFinalResults(jobNumber, password).data | 
| 32332 | 66 | sys.stdout.write("---------- Begin CSDP Output -------------\n");
 | 
| 67 | sys.stdout.write(msg) | |
| 32268 
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
 Philipp Meyer parents: diff
changeset | 68 | |
| 32332 | 69 | # extract solution | 
| 70 | result = msg.split("Solution:")
 | |
| 32268 
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
 Philipp Meyer parents: diff
changeset | 71 | if len(result) > 1: | 
| 32362 | 72 | solution = result[1].strip() | 
| 73 | if solution != "": | |
| 32542 | 74 | outputfile = open(sys.argv[2],"w") | 
| 75 | outputfile.write(solution) | |
| 76 | outputfile.close() | |
| 32268 
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
 Philipp Meyer parents: diff
changeset | 77 | |
| 32332 | 78 | # extract return code | 
| 79 | p = re.compile(r"^Error: Command exited with non-zero status (\d+)$", re.MULTILINE) | |
| 80 | m = p.search(messages) | |
| 81 | if m: | |
| 82 | sys.exit(int(m.group(1))) | |
| 83 | else: | |
| 84 | sys.exit(0) | |
| 32268 
d50f0cb67578
Functionality for sum of squares to call a remote csdp prover
 Philipp Meyer parents: diff
changeset | 85 |