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
Add cp.nlp submodule namespace for NLP atoms (cvxpy#3222)
* Add cp.nlp submodule namespace for NLP atoms
Closescvxpy#3198
Creates a dedicated cvxpy.nlp namespace for atoms that require
an NLP solver (nlp=True). Users can now write:
import cvxpy as cp
x = cp.Variable()
prob = cp.Problem(cp.Minimize(cp.nlp.sin(x)), [x >= 0])
prob.solve(nlp=True)
Atoms available under cp.nlp:
- Trigonometric: sin, cos, tan
- Hyperbolic: sinh, tanh, asinh, atanh
Note: cp.sin etc. still work as before via cp.atoms import.
cp.nlp provides a dedicated namespace making it clear these
atoms require NLP solvers.
AI assistance was used for codebase exploration, as per
CVXPY's AI disclosure policy.
* Remove NLP atoms from top-level cp namespace, keep only under cp.nlp
Per PTNobel's review: NLP atoms (sin, cos, tan, sinh, tanh, asinh, atanh)
should not be in the top-level cp namespace since they require nlp=True.
They are now only accessible via cp.nlp.sin etc.
Also update tests to reflect new design:
- Remove test_atoms_same_as_direct (cp.sin no longer exists)
- Add test_atoms_not_in_top_level to enforce the new policy
- Add test_atoms_same_class_as_direct_import to verify cp.nlp points
to the correct classes
* Update NLP tests to use cp.nlp namespace
NLP atoms (sin, cos, tan, sinh, tanh, asinh, atanh) are no longer
exported at the top-level cp namespace. Update all nlp_tests to use
cp.nlp.sin, cp.nlp.cos etc. consistently.
* Fix ruff linting: remove unused imports and sort import block in test_nlp_namespace.py
* update dnlp docs
---------
Co-authored-by: Steven Diamond <diamond@cs.stanford.edu>
0 commit comments