##
#  Copyright : Copyright (c) MOSEK ApS, Denmark. All rights reserved.
#
#  File :      test_mosekapi.py
#
#  Purpose :   Demonstrates how to submit an optimization problem
#              to the MOSEK OptServer in the simplest way using
#              the MOSEK Python API.
#
#  See the manual for your API for a similar example.
##
import mosek, sys, argparse

if __name__ == '__main__':
    # Arguments
    parser = argparse.ArgumentParser()
    parser.add_argument("--url", help="URL of the remote server", type=str, required=True)
    parser.add_argument("--infile", help="Input file to optimize", type=str, required=True)
    parser.add_argument("--cert", help="TLS certificate file (HTTPS only)", type=str, default="")
    args = parser.parse_args()
    URL = args.url
    infile = args.infile
    cert = args.cert

    # Create task and read example data
    task = mosek.Task()
    task.readdata(infile)
    task.set_Stream(mosek.streamtype.log, sys.stdout.write)

    # Specify the OptServer coordinates
    task.putoptserverhost(URL)

    # Only relevant if using HTTPS, otherwise ignore
    task.putstrparam(mosek.sparam.remote_tls_cert_path, cert)

    # Solve (remotely)
    task.optimize()

    # Print some sample results (adjust to your task type)
    print(f"Solution status {task.getsolsta(mosek.soltype.itr)}")
    print(f"Objective value {task.getprimalobj(mosek.soltype.itr)}")
