GithubHelp home page GithubHelp logo

wuyou33 / convex_symbolic Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jonnyhyman/convex_symbolic

1.0 2.0 0.0 1.44 MB

Python symbolic canonicalizer and C code generator for embedding convex optimization problems.

License: GNU General Public License v3.0

Python 93.63% HTML 6.37%

convex_symbolic's Introduction

Convex Symbolic

A Python symbolic canonicalizer and C code generator for embedding convex optimization problems.

It follows the same problem definition syntax, function naming, and internal nomenclature as the leading Python convex optimization package, cvxpy.

For example, the same constrained least-squares problem cvxpy exhibits can be converted into C code like so :

from cvx_sym import *

# Problem size.
m = 30
n = 20

# Construct the problem.
A = Parameter((m, n), name = 'A')
b = Parameter((m),    name = 'b')
x = Variable((n),     name = 'x')

objective = Minimize(sum_squares(A*x - b))
constraints = [0 <= x, x <= 1]
problem  = Problem(objective, constraints)

gen = Generate(
                problem,
                name = 'readme_example',
                folder = 'examples',
                verbose = True  # show each stage of the process
              )

Code from: testing/integrations/readme_example.py

Which will save into a folder called examples/readme_example all the C code required to solve this problem. The canonical problem matrices are explicitly written to a file called problem.c. Parameters are handled symbolically, meaning that upon running the C code

Alternatively, instead of calling Generate we can assign parameters, canonicalize, and run with ecos-python :

import numpy
numpy.random.seed(1)

canon = Canonicalize(problem)
canon.assign_values({ # Set values of parameters
                      'A' : numpy.random.randn(m, n),
                      'B' : numpy.random.randn(m)
                    })

solution = solve(canon, verbose = True)  # returns what ecos.solve(...) returns
print(solution['x'])

Requires

  • Python 3.6+,

    • Takes advantage of ordered dicts, new feature in 3.6
  • jinja2, template engine

  • numpy, for parameter assignment tests

  • ECOS, solver source code

    • Place the contents in folder named __solvers__/ecos
  • To obtain solutions and run all tests

Methods

The canonicalization methods used are mostly defined in this paper by Chu, Parikh, Domahidi, and Boyd.

Limitations

  • No DCP Compliance Checking. The canonicalizer assumes the problem is well formed and DCP-compliant.
  • Only SOCPs (and therefore also QPs, and LPs) are supported. There is no support yet for SDPs, CPs, or GFPs.
  • Only ECOS is supported as a solver
  • Only C99 is supported as a code generation language
  • Not all functions are implemented yet (ie. vstack, hstack, tv, etc...).
    • For the complete list of implemented functions, see the files in cvx_sym/operations/functions

Recommendations

It is suggested to build and test your problem first in cvxpy, then modify it to be canonicalized or code generated by cvx_sym.

Examples

In the tests/integrations folder and tests/test_ecos_solution.py file, there are a bunch of tests which can be used as examples, and are great starting points in understanding module usage.

License: GNU-GPLv3
Version: 0.0 (Alpha)

convex_symbolic's People

Contributors

jonnyhyman avatar

Stargazers

 avatar

Watchers

 avatar  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.