Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

15 create a complete pyprojecttoml and poetrylock #16

Closed
wants to merge 15 commits into from
26 changes: 26 additions & 0 deletions .github/workflows/basic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: "basic"

on:
push:

jobs:
pre-commit:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: pre-commit/[email protected]
with:
extra_args: '--verbose --all-files'

test:
runs-on: ubuntu-latest

steps:
- uses: cvxgrp/.github/actions/test@main
with:
source-folder: "dsp"

#- name: Coveralls GitHub Action
# uses: coverallsapp/github-action@v2

15 changes: 1 addition & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.8
uses: actions/setup-python@v4
with:
python-version: '3.8'
- name: Install pre-commit
run: |
pip install pre-commit
- name: Setup pre-commit hooks
run: |
pre-commit install
- name: Run pre-commit hooks
run: |
pre-commit run --all-files
- uses: pre-commit/[email protected]

build:
runs-on: ubuntu-latest
Expand All @@ -37,7 +25,6 @@ jobs:
3.11
3.10
3.9
3.8
- uses: actions/checkout@v3
with:
fetch-depth: 0 # For sonar
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: "ci"

on:
push

jobs:
test:
# The type of runner that the job will run on
runs-on: ${{ matrix.os }}

strategy:
matrix:
# mosek is not yet ready for '3.11'
os: [ ubuntu-latest, windows-latest, macos-latest ]
python-version: ['3.9', '3.10', '3.11' ]

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- uses: cvxgrp/.github/actions/test@main
with:
python-version: ${{ matrix.python-version }}
source-folder: "dsp"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea
.ruff_cache

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
15 changes: 15 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,18 @@ repos:
language_version: python3
args:
- --line-length=100

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.26.2
hooks:
- id: check-dependabot
args: [ "--verbose" ]

- id: check-github-workflows
args: ["--verbose"]

- repo: https://github.com/python-poetry/poetry
rev: '1.6.1' # add version here
hooks:
- id: poetry-check
- id: poetry-lock
38 changes: 38 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.DEFAULT_GOAL := help

SHELL=/bin/bash

UNAME=$(shell uname -s)

.PHONY: install
install: ## Install a virtual environment
@poetry install -vv

.PHONY: fmt
fmt: ## Run autoformatting and linting
@poetry run pip install pre-commit
@poetry run pre-commit install
@poetry run pre-commit run --all-files

.PHONY: clean
clean: ## Clean up caches and build artifacts
@git clean -X -d -f


.PHONY: help
help: ## Display this help screen
@echo
@echo -e "\033[1mAvailable commands:\033[0m"
@echo
@grep -E '^[a-z.A-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-18s\033[0m %s\n", $$1, $$2}' | sort
@echo

.PHONY: test
test: install ## Run tests
@poetry run pytest


.PHONY: jupyter
jupyter: install ## Start jupyter lab
@poetry run pip install jupyterlab
@poetry run jupyter lab
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# DSP - Disciplined Saddle Programming

[![build](https://github.com/cvxgrp/dsp/actions/workflows/build.yml/badge.svg)](https://github.com/cvxgrp/dsp/actions/workflows/build.yml)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=dsp&metric=coverage)](https://sonarcloud.io/summary/new_code?id=dsp)
[![Apache 2.0 License](https://img.shields.io/badge/License-APACHEv2-brightgreen.svg)](https://github.com/cvxgrp/dsp/blob/master/LICENSE)

A CVXPY extension for Disciplined Saddle Programming.
DSP allows solving convex-concave saddle point problems, and more generally
Expand All @@ -13,9 +15,11 @@ A detailed description of the underlying method is given in our [accompanying pa
## Installation

The DSP package can be installed using pip as follows

```bash
pip install dsp-cvxpy
```

The DSP package requires CVXPY 1.3 or later.

## Minimal example
Expand Down Expand Up @@ -48,6 +52,7 @@ y.value # array([0.33333333, 0.66666667])
```

## New atoms

In DSP, saddle functions are created from atoms. Each atom represents a saddle function, with the convention being
that the first argument is the convex argument and the second argument is the concave argument.

Expand All @@ -74,6 +79,7 @@ $$
The quadratic form $x^TYx$, where $Y$ a positive semindefinite matrix.

## Calculus rules

Saddle functions can be scaled and composed by addition. DCP convex expressions are treated as saddle functions with
no concave arguments, and DCP concave expressions are treated as saddle functions with no convex arguments.
When adding two saddle functions, a variable may not appear as a convex variable in one expression and as a concave
Expand All @@ -88,17 +94,22 @@ $$
$$

## Saddle point problems

To create a saddle point problem, a `MinimizeMaximize` object is created first, which represents the objective function,
using

```python
obj = dsp.MinimizeMaximize(f)
```

where `f` is a DSP-compliant expression.

The syntax for specifying saddle point problems is

```python
problem = dsp.SaddlePointProblem(obj, constraints, cvx_vars, ccv_vars)
```

where `obj` is the `MinimizeMaximize` object, `constraints` is a list of constraints, and `cvx_vars` and `ccv_vars` are
lists of variables to be minimized and maximized over, respectively.

Expand All @@ -114,6 +125,7 @@ To solve the problem, call `problem.solve()`. This returns the optimal saddle va
problem's `value` attribute. Further all `value` attribute of the variables are populated with their optimal values.

## Saddle extremum functions

A saddle extremum function has one of the forms

$$
Expand All @@ -125,15 +137,18 @@ where $f$ is a saddle function, and $\mathcal{X}$ and $\mathcal{Y}$ are convex.
Since the functions only depend on $x$ or $y$, respectively, the other variables have to be declared as
`LocalVariable`s. Any `LocalVariable` can only be used in one saddle extremum function. The syntax for
creating a saddle extremum function is

```python
dsp.saddle_max(f, constraints)
dsp.saddle_min(f, constraints)
```

where `f` is a DSP-compliant scalar saddle function, and `constraints` is a list of constraints, which can
only involve `LocalVariable`s. DSP-compliant saddle extremum functions are DCP-convex or DCP-concave, respectively,
and as such can be used in DCP optimization problems.

An example of a saddle extremum function is

```python
# Creating variables
x = cp.Variable(2)
Expand All @@ -149,9 +164,11 @@ G = dsp.saddle_max(f, [y_loc >= 0, cp.sum(y_loc) == 1])
```

## Saddle problems

A saddle problem is a convex optimization problem that involves saddle extremum functions. Any DCP convex optimization
can include saddle extremum functions when they are DSP-compliant. Using the saddle extremum function `G` from above,
we can solve the following problem:

```python
prob = cp.Problem(cp.Minimize(G), [x >= 0, cp.sum(x) == 1])
prob.solve() # solving the problem
Expand All @@ -161,6 +178,7 @@ x.value # array([0.66666667, 0.33333333])
```

## Citation

If you want to reference DSP in your research, please consider citing us by using the following BibTeX:

```BibTeX
Expand Down
Loading