You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
-
5
-
This is a **fork of CVXPY** that adds **Disciplined Nonlinear Programming (DNLP)** support, enabling non-convex optimization with automatic differentiation via SparseDiffPy.
-`is_incr(idx)` / `is_decr(idx)` - Monotonicity per argument
106
+
107
+
### DGP (Disciplined Geometric Programming)
108
+
DGP problems use log-log curvature instead of standard curvature. Transformed to DCP via `dgp2dcp` reduction.
109
+
110
+
### DQCP (Disciplined Quasiconvex Programming)
111
+
DQCP extends DCP to quasiconvex functions. Solved via bisection on a parameter. Transformed via `dqcp2dcp` reduction.
81
112
82
113
### DPP (Disciplined Parametrized Programming)
83
-
Parameters are treated as affine (not constant) for curvature analysis. `param * param` is NOT DPP; `param * variable` is DPP. Check with `problem.is_dpp()`. See `cvxpy/utilities/scopes.py`.
114
+
DPP enables efficient re-solving when only `Parameter` values change. CVXPY caches the canonicalization and reuses it.
84
115
85
-
## DNLP Architecture
116
+
**How it works**: Parameters are treated as affine (not constant) for curvature analysis. This means:
117
+
-`param * param` → NOT DPP (quadratic in params)
118
+
-`param * variable` → DPP (affine in params, params only in one factor)
119
+
-`cp.norm(param)` in constraint → NOT DPP (nonlinear in params)
`Dnlp2Smooth` converts DNLP expressions to smooth forms. Canonicalizers in `dnlp2smooth/canonicalizers/`handle atoms like log, exp, sin, power, geo_mean, etc. Registered in `SMOOTH_CANON_METHODS` dict.
- Parameter updates flow through `Oracles.update_params()` → `C_problem.update_params()`
132
+
classmy_atom(Atom):
133
+
def__init__(self, x) -> None:
134
+
super().__init__(x)
113
135
114
-
### Parameter support
115
-
Parameters are passed as param nodes to the diff engine at construction. On re-solve, `update_params()` updates values without rebuilding the expression graph. The solver cache (`_solver_cache['NLP']`) stores `Oracles` between solves.
136
+
defshape_from_args(self) -> Tuple[int, ...]:
137
+
returnself.args[0].shape
116
138
117
-
## Implementing New Atoms
139
+
defsign_from_args(self) -> Tuple[bool, bool]:
140
+
return (False, False) # (is_nonneg, is_nonpos)
118
141
119
-
### 1. Create atom class in `cvxpy/atoms/` or `cvxpy/atoms/elementwise/`
Backends handle matrix construction during `ConeMatrixStuffing`. Located in `cvxpy/lin_ops/backends/`.
143
-
-`CPP` (default) - C++ implementation, fastest for large expression trees
144
-
-`SCIPY` - Pure Python with SciPy sparse matrices
226
+
Backends are critical to performance. They handle matrix construction during `ConeMatrixStuffing`. Located in `cvxpy/lin_ops/backends/`.
227
+
228
+
**Backends:**
229
+
-`CPP` (default) - C++ implementation, fastest for problems with large expression trees
230
+
-`SCIPY` - Pure Python with SciPy sparse matrices, good for large problems
145
231
-`COO` - 3D COO tensor, better for large DPP problems with many parameters
146
232
147
233
Select via `CVXPY_DEFAULT_CANON_BACKEND=CPP` (default), `SCIPY`, or `COO`.
148
234
149
235
## Pull Requests
150
236
151
-
Always use the PR template in `.github/`. **Never check an item in the Contribution Checklist that has not actually been done.**
237
+
Always use the PR template in `.github/` when opening PRs. Fill out all sections. **Never check an item in the Contribution Checklist that has not actually been done.**
152
238
153
239
## Common Mistakes to Avoid
154
240
155
-
1.**Forgetting to register canonicalizers** in `canonicalizers/__init__.py` (both DCP and smooth)
241
+
1.**Forgetting to register canonicalizers** in `canonicalizers/__init__.py`
156
242
2.**Forgetting to export atoms** in `cvxpy/atoms/__init__.py`
157
243
3. Missing `is_incr`/`is_decr` methods in atoms (breaks DCP analysis)
158
244
4. Not testing with `Parameter` objects (DPP compliance)
159
245
5. Missing license headers on new files
160
-
6.Not adding a diff engine converter for new atoms (breaks NLP support)
246
+
6.**Forgetting to update documentation** - new features need docs at [cvxpy.org](https://www.cvxpy.org/) (see `doc/` folder)
0 commit comments