{"id":19874671,"url":"https://github.com/jonnyhyman/convex_symbolic","last_synced_at":"2025-05-02T10:31:30.571Z","repository":{"id":165437281,"uuid":"133713574","full_name":"jonnyhyman/Convex_Symbolic","owner":"jonnyhyman","description":"Python symbolic canonicalizer and C code generator for embedding convex optimization problems.","archived":false,"fork":false,"pushed_at":"2018-05-27T23:35:41.000Z","size":1475,"stargazers_count":7,"open_issues_count":10,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-07T01:05:44.674Z","etag":null,"topics":["algebra","c","c99","canon","canonicalize","code","codegen","convex","cvxpy","generation","optimization","python","symbolic"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonnyhyman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-05-16T19:25:33.000Z","updated_at":"2024-05-02T21:41:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"93a13e88-0732-409e-b88f-e6d4a3850732","html_url":"https://github.com/jonnyhyman/Convex_Symbolic","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonnyhyman%2FConvex_Symbolic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonnyhyman%2FConvex_Symbolic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonnyhyman%2FConvex_Symbolic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonnyhyman%2FConvex_Symbolic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonnyhyman","download_url":"https://codeload.github.com/jonnyhyman/Convex_Symbolic/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252023280,"owners_count":21682156,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algebra","c","c99","canon","canonicalize","code","codegen","convex","cvxpy","generation","optimization","python","symbolic"],"created_at":"2024-11-12T16:24:54.985Z","updated_at":"2025-05-02T10:31:30.563Z","avatar_url":"https://github.com/jonnyhyman.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Convex Symbolic\n\n##### A Python symbolic canonicalizer and C code generator for embedding convex optimization problems.\n\nIt follows the same problem definition syntax, function naming, and internal nomenclature as the leading Python convex optimization package, [cvxpy](https://github.com/cvxgrp/cvxpy/tree/1.0).\n\nFor example, the same constrained least-squares problem [cvxpy](https://github.com/cvxgrp/cvxpy/tree/1.0) exhibits can be converted into C code like so :\n\n```python\nfrom cvx_sym import *\n\n# Problem size.\nm = 30\nn = 20\n\n# Construct the problem.\nA = Parameter((m, n), name = 'A')\nb = Parameter((m),    name = 'b')\nx = Variable((n),     name = 'x')\n\nobjective = Minimize(sum_squares(A*x - b))\nconstraints = [0 \u003c= x, x \u003c= 1]\nproblem  = Problem(objective, constraints)\n\ngen = Generate(\n                problem,\n                name = 'readme_example',\n                folder = 'examples',\n                verbose = True  # show each stage of the process\n              )\n```\n*Code from:* `testing/integrations/readme_example.py`\n\nWhich 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\n\nAlternatively, instead of calling `Generate` we can assign parameters, canonicalize, and run with ecos-python :\n\n```python\nimport numpy\nnumpy.random.seed(1)\n\ncanon = Canonicalize(problem)\ncanon.assign_values({ # Set values of parameters\n                      'A' : numpy.random.randn(m, n),\n                      'B' : numpy.random.randn(m)\n                    })\n\nsolution = solve(canon, verbose = True)  # returns what ecos.solve(...) returns\nprint(solution['x'])\n```\n\n#### Requires\n\n- [Python 3.6+](https://www.python.org/),\n  - Takes advantage of ordered dicts, new feature in 3.6\n\n\n- [jinja2](http://jinja.pocoo.org/docs/2.10/), template engine\n- [numpy](http://www.numpy.org/), for parameter assignment tests\n- [ECOS](https://github.com/embotech/ecos), solver source code\n  - **Place the contents in folder named `__solvers__/ecos`**\n\n\n- To obtain solutions and run *all* tests\n  - [ecos-python](https://github.com/embotech/ecos-python), for parameter assignment tests\n  - [scipy](https://www.scipy.org/), for ecos-python input\n\n\n#### Methods\nThe canonicalization methods used are mostly defined [in this paper](https://web.stanford.edu/~boyd/papers/pdf/ecos_codegen_ecc.pdf) by Chu, Parikh, Domahidi, and Boyd.\n\n#### Limitations\n- ***No DCP Compliance Checking***. The canonicalizer assumes the problem is well formed and [DCP-compliant](http://dcp.stanford.edu/rules).\n- ***Only SOCPs*** (and therefore also QPs, and LPs) are supported. There is no support yet for SDPs, CPs, or GFPs.\n- ***Only ECOS*** is supported as a solver\n- ***Only C99*** is supported as a code generation language\n- Not all functions are implemented yet (ie. vstack, hstack, tv, etc...).\n  - For the complete list of implemented functions, see the files in `cvx_sym/operations/functions`\n\n#### Recommendations\nIt is suggested to build and test your problem first in cvxpy, then modify it to be canonicalized or code generated by cvx_sym.\n\n#### Examples\nIn 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.\n\n##### License: *GNU-GPLv3*\n##### Version: *0.0 (Alpha)*\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonnyhyman%2Fconvex_symbolic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonnyhyman%2Fconvex_symbolic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonnyhyman%2Fconvex_symbolic/lists"}