Giter Club home page Giter Club logo

pysdpt3glue's Introduction

sdpt3glue

Code Climate Build Status MIT License PyPi

The sdpt3glue package serves as glue code to allow Cvxpy semidefinite programming (SDP) problems to be solved using the SDPT3 solver for Matlab.

##Installation: This project is listed under PyPI as sdpt3glue, which means that you should be able to install it using

pip install sdpt3glue

##Documentation: Documentation is hosted here, courtesy of the Python Software Foundation.

##Quick usage guide:

Problem set up

We assume that the problem to be solved is a Cvxpy problem object representing a semidefinite program. For example, to use sdpt3glue to solve the problem

    min y s.t.
    -0.2 <= x <= -0.1
    0.4 <= z <=  0.5
    [1  x  y]
    |x  1  z| is PSD
    [y  z  1]

the following script lays the ground work by modeling the problem with Cvxpy and defining the file targets for the .mat file and the output log:

import os

from cvxpy import *
import sdpt3glue.solve as slv

# Declare variables:
X = Variable((3,3), PSD=3)

# Define objective:
obj = Minimize(X[0, 2])

# Define constraints
constraints = [-0.2 <= X[0, 1], X[0, 1] <= -0.1, 0.4 <= X[1, 2], X[1, 2] <= 0.5]
constraints += [X[i, i] == 1 for i in range(3)]

# Construct the Cvxpy problem
problem = Problem(obj, constraints)

# Generate filenames
matfile_target = os.path.join(folder, 'matfile.mat')  # Where to save the .mat file to
output_target = os.path.join(folder, 'output.txt')    # Where to save the output log

###Problem solution four ways

1. With Matlab installed

Make sure SDPT3 is installed for Matlab and the folder containing SDPT3 is added to your MATLABPATH. Solve the problem by executing the following command:

result = sdpt3glue.sdpt3_solve_problem(P, sdpt3glue.MATLAB, matfile_target,
                                       output_target=output_target)

where matfile_target is the filepath that the problem's .mat file will be saved to and output_target is the filepath that the SDPT3 solve log will be saved to.

2. With Octave installed

Make sure SDPT3 is installed for Octave and is visible in Octave when the working folder is the folder where matfile_target is.

result = sdpt3glue.sdpt3_solve_problem(P, sdpt3glue.OCTAVE, matfile_target,
                                       output_target=output_target)

3. Using Docker

Without a locally installed copy of Matlab or Octave, but with Docker, a problem can be solved in the following way:

OCTAVE_CMD = ("docker run --rm -it -v {workdir}:/data "
              "jkawamoto/octave-sdpt3 octave").format(workdir=os.path.abspath("."))

result = sdpt3glue.sdpt3_solve_problem(P, sdpt3glue.OCTAVE, matfile_target,
                                       output_target=output_target, cmd=OCTAVE_CMD)

This makes use of a docker image created by Junpei Kawamoto for this purpose.

4. With the NEOS server

With either Firefox or phantomjs installed and for small to medium sized problems (those with .mat files of size less than about 20-25MB), the NEOS server can be used.

Disclaimer: In addition to the disclaimer provided by the MIT license, we make special note that we make no guarantees about service provided by the NEOS server, as we are not responsible for its operation. If your problem data is sensitive, take appropriate precautions.

result = sdpt3glue.sdpt3_solve_problem(P, sdpt3glue.NEOS, matfile_target,
                                       output_target=output_target)

pysdpt3glue's People

Contributors

trishgillett avatar jkawamoto avatar tk-21st avatar ipa-lth avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.