6 Testing the installation

6.1 Test connection

A simple test to check that OptServer is up and running can be performed by opening the URL:

http://SERVER:PORT/api/v1/version

where http://SERVER:PORT (or https://SERVER:PORT if using SSL) are the coordinates of the server.

The correct response contains the version number of the OptServer and optionally of the MOSEK solver underneath and should be similar to:

11.0.1-light/11.0.1                     (for OptServerLight)
3.0.15                                  (for full OptServer)

6.2 Test optimization

Assuming the connection works fine a simple Hello World test of the optimization capabilities can be performed by running the following python script with the URL of the server as an argument.

python3 test_helloworld.py http://SERVER:PORT

The expected outcome is to obtain the solver’s log output, and a confirmation that the solution is correct. Any errors related to licensing or configuration issues should be detected at this point and can be corrected, possibly with the help of the server’s log file.

Listing 6.1 A HelloWorld test of the OptServer. Click here to download.
import requests, sys, json

URL = sys.argv[1]
PROBLEM = r"""
{"Task/data":{"var":{"bk":["lo","ra","lo","lo"],"bl":[0,0,0,0],"bu":[1e+30,10,1e+30,1e+30],"type":["cont","cont","cont","cont"]},
             "con":{"bk":["fx","lo","up"],"bl":[30,15,-1e+30],"bu":[30,1e+30,25]},
             "objective":{"sense":"max","c":{"subj":[0,1,2,3],"val":[3,1,5,1]},"cfix":0},
             "A":{"subi":[1,0,2,1,0,1,0,2,1],"subj":[0,0,1,1,1,2,2,3,3],"val":[2,3,2,1,1,3,2,3,1]}}}
"""
verify = False # Whether to verify SSL certificates

with requests.Session() as s:
    p = s.post(URL + "/api/v1/submit+solve", 
               data = PROBLEM,
               headers = { "Content-Type" : "application/x-mosek-jtask", "Accept": "application/x-mosek-jtask"},
               verify = verify )
    if p.status_code != 200:
        print(f"Status {p.status_code}")
        print(p.text)
        print(p.headers)
    else:
        token = p.headers['X-Mosek-Job-Token']
        sol = json.loads(p.text)

        l = s.get(URL + "/api/v1/log", 
                  headers = { "X-Mosek-Job-Token" : token },
                  verify = verify )
        print(l.text)

        print(f"Status {p.status_code}")
        print(f"MOSEK response {p.headers['X-Mosek-Res-Code']}")

        x = sol['Task/solutions']['interior']['xx']
        print(f"Received solution:", *(f"{xi:.2f}" for xi in x))
        print(f"Expected solution: 0.00 0.00 15.00 8.33")

6.3 Further tests and usage

  • If using the OptServer from a MOSEK API, consult the manual for your API for instructions on how to use remote optimization. They can be found in the section Solver interaction tutorials/MOSEK OptServer of your API manual. In most basic cases this amounts to providing the URL of the server when calling the API method which actually optimizes. See also Sec. 8 (MOSEK API tutorial).

  • If using MOSEK from a third-party or MOSEK API remote optimization can also be requested by setting the parameter MSK_SPAR_REMOTE_OPTSERVER_HOST.

  • If you plan to use the OptServer directly via REST API canns consult the tutorial in Sec. 9 (REST API tutorials) and the API reference in Sec. 10 (OptServer Reference).