sdpt3glue package

Submodules

sdpt3glue.result module

sdpt3glue.result.can_use_msg(msg)[source]

Checks to see if a message is non-trivial and contains the phrase “SDPT3: Infeasible path-following algorithms”, which should appear in the output log just before the result properties are listed. While it’s probably possible for this function to return True in a case where there’s something wrong with the message, this is a good preliminary check to do.

sdpt3glue.result.extract_X(msg)[source]

Given the output message from running SDPT3solve.m, reconstruct the X matrix from the printed output and return it.

sdpt3glue.result.extract_prop_dict(msg)[source]

Given the output message from running SDPT3solve.m, this function constructs and returns a dictionary of basic solve result information.

sdpt3glue.result.get_verb_status(status_num)[source]

A function that takes an SDPT3 numerical termination code as input and returns a phrase (string) explaining the implications of the termination code.

sdpt3glue.result.handle_msg_item(x)[source]

A function that takes a string x and returns it’s interpretation as an int, float, or string in that order of preference. If x is None, None is returned.

sdpt3glue.result.make_result_dict(msg)[source]

Extracts some solve information from the log message and constructs a dict. This function will error if the message is empty or does not include the phrase “SDPT3: Infeasible path-following algorithms”, which is an indicator that the solver at least started okay. If the log passes that basic test, we just retrieve what information we can. If the dict doesn’t at least contain a status_num and status_verb, you should check the log manually and see what went wrong.

sdpt3glue.result.make_result_summary(result)[source]

Prints a basic summary of information about an SDPT3 solve result.

sdpt3glue.result.print_summary(result)[source]

Prints out the summary produced by make_result_summary.

sdpt3glue.sedumi_writer module

Functions which express problems in Sedumi format and export them as .mat files for Matlab

sdpt3glue.sedumi_writer.check_eliminatibility(g, h, n_elig=None, allow_nonzero_b=False)[source]

Tests if constraint \(gx = h\) fits either pattern \(ax_i = d\) or pattern \(ax_i + bx_j = d\), with the requirement that the \(x_i\) variable be one of the first n_elig variables.

Returns:

i, None such that the constraint has the form \(ax_i = d\) for some \(a, d\).

i, j such that the constraint has the form \(ax_i + bx_j = d\) for some \(a, b, d\).

None, None if neither pattern applies.

sdpt3glue.sedumi_writer.clean_K_dims(K)[source]

Matlab requires the dimensions to be given in floating point numbers, this checker ensures that they are.

sdpt3glue.sedumi_writer.make_sedumi_format_problem(problem_data, simplify=True)[source]
Input:
problem_data: As produced by applying get_problem_data[‘CVXOPT’] to a cvxpy problem.
Returns:
A, b, c, K: Data defining an equivalent problem in Sedumi format.
sdpt3glue.sedumi_writer.problem_data_prep(problem_data)[source]
‘Touch up’ the problem data in the following ways:
  • Make sure the matrix elements aren’t integers
  • Make sure they’re dense matrices rather than sparse ones, otherwise there seem to be difficulties constructing block matrices
  • Transpose c to be a row vector, which matches the organization of A, b, G, h (rows are for constraints, columns are for variables)
sdpt3glue.sedumi_writer.simplify_sedumi_model(A, b, c, K, allow_nonzero_b=False)[source]

Tries to eliminate variables using a few simple strategies:

1. If a constraint is expressing \(A_{ki}x_i = b_k\) where variable \(x_i\) is a free variable, we can eliminate \(x_i\).

2. If a constraint is expressing \(A_{ki}x_i + A_{kj}x_j = b_k\) where variable \(x_i\) is a free variable, we can eliminate \(x_i\).

Args:
A, b, c, K: for a problem in Sedumi format allow_nonzero_b: If False, only eliminate if bk = 0 is zero
Returns:
A, b, c, K: for the simplified problem. offset: A constant which must be added to the optimal value of the simplified problem in order to make it equivalent. With allow_nonzero_b, offset will be 0.
sdpt3glue.sedumi_writer.sparsify_tall_mat(M, block_height=1000)[source]

Returns a sparse matrix in scipy.sparse.coo_matrix form which is equivalent to M

sdpt3glue.sedumi_writer.symmetrize_sedumi_model(A, b, c, K)[source]

Symmetrize sedumi model.

sdpt3glue.sedumi_writer.write_cvxpy_to_mat(problem_data, target, simplify=True)[source]
Args:
problem_data: As produced by applying get_problem_data[‘CVXOPT’] to a cvxpy problem.

Returns: (None)

Effect:
Saves a .mat file containing the A, b, c, K that define the problem in Sedumi format to target (see http://plato.asu.edu/ftp/usrguide.pdf)
sdpt3glue.sedumi_writer.write_sedumi_to_mat(A, b, c, K, target)[source]
Args:
A, b, c, K for Sedumi format target: the path where we will save the .mat
Effect:
Saves a .mat file containing A, b, c, K to target

sdpt3glue.solve module

sdpt3glue.solve.check_output_target(mode, output_target)[source]
checks if the value of output_target is appropriate:
  • output_target can’t be None if using Matlab or Octave
  • output_target can’t be a file that already exists
sdpt3glue.solve.sdpt3_solve_mat(matfile_path, mode, output_target=None, discard_matfile=True, **kwargs)[source]

A wrapper function that takes the path of a .mat file, solves the Sedumi problem it contains with NEOS or a local Matlab/SDPT3 installation, then constructs the result, prints it, and returns it.

sdpt3glue.solve.sdpt3_solve_problem(problem, mode, matfile_target, output_target=None, discard_matfile=True, **kwargs)[source]

A wrapper function that takes a cvxpy problem, makes the .mat file, solves it by NEOS or a local Matlab/SDPT3 installation, then constructs the result, prints it, and returns it.

sdpt3glue.solve_locally module

Methods that run code on a copy of Matlab or Octave installed on the user’s machine.

exception sdpt3glue.solve_locally.MatlabCallError[source]

Bases: exceptions.Exception

This error is raised when an error occurs during a subprocess call to Matlab.

exception sdpt3glue.solve_locally.OctaveCallError[source]

Bases: exceptions.Exception

This error is raised when an error occurs during a subprocess call to Octave.

exception sdpt3glue.solve_locally.SubprocessCallError[source]

Bases: exceptions.Exception

This error is raised when an error occurs during a subprocess call.

sdpt3glue.solve_locally.matlab_solve(matfile_target, discard_matfile=True)[source]

The .mat is loaded into matlab and the problem is solved with SDPT3.

Args:
matfile_target: the path to the .mat file containing the Sedumi format problem data. discard_matfile: if True, deletes the .mat file after the solve finishes.
Returns:
A dictionary with solve result information.
sdpt3glue.solve_locally.octave_solve(matfile_target, discard_matfile=True, cmd='octave')[source]

The .mat is loaded into octave and the problem is solved with SDPT3.

Args:
matfile_target: the path to the .mat file containing the Sedumi format problem data. discard_matfile: if True, deletes the .mat file after the solve finishes. cmd: command name for octave, which will be used for alternative command.
Returns:
A dictionary with solve result information.
sdpt3glue.solve_locally.run_command_get_output(run_command)[source]

Runs the command run_command, saves the output to output_target, and returns the output log.

sdpt3glue.solve_neos module

Basic scraper/webdriver to submit an sdpt3 problem on the NEOS webpage. This version uses selenium because difficulties were encountered using XML-RPC for problems of this type.

exception sdpt3glue.solve_neos.NeosError[source]

Bases: exceptions.Exception

Error caused by Neos server.

This error is raised when an error occurs during calling Neos.

class sdpt3glue.solve_neos.NeosInterface(neos_host=None, neos_port=None)[source]

Bases: object

An abstract class for connections with the remote NEOS Server for Optimization. NeosInterface objects communicate with the NEOS Server via XML-RPC. This class wraps the server’s services into a few convenient methods which, for the time being, are designed with the solution of AMPL models in mind.

get_final_results(jobid, pwd)[source]

This funtion is ‘stubborn’, meaning that if it’s unable to get the results it will wait a few seconds and try again. Stubborn functionality is intended to smooth over lost internet connections or computers that may fall asleep and then wake up and resume running code.

track_and_return(jobid, pwd)[source]

Takes a jobid and password for a solve already in progress, waits for its status to change to ‘Done’, and returns the message, jobid, and password.

sdpt3glue.solve_neos.WEBDRIVERS = {'Firefox': <class 'selenium.webdriver.firefox.webdriver.WebDriver'>, 'PhantomJS': <class 'selenium.webdriver.phantomjs.webdriver.WebDriver'>}

Webdrivers to try using.

sdpt3glue.solve_neos.ask_user_to_submit(matfilepath)[source]

Instructs the user to manually submit their problem and then feed the ID and password back into the program.

Raises:
EOFError: When a user sends EOF.
sdpt3glue.solve_neos.extract_id_pwd(source)[source]

Given a snippet of the form

Job#     : xxxxxxx
Password : yyyyyyyy

extracts and returns the strings for job ID and password

sdpt3glue.solve_neos.neos_solve(matfile_target, discard_matfile=True, no_prompt=False)[source]

Submits the Sedumi format .mat file to be solved on NEOS with SDPT3. Returns the solve result message from NEOS. If write_output_to, has the side effect of writing the message to this file.

If no_prompt is True, it doesn’t ask id and password manually and raise NeosError when some errors occur during connection to neos server.

Raises:
NeosError: When an error occurs by using Neos server.