API Reference¶
This page provides comprehensive API documentation for the DCCP package, automatically generated from numpy-style docstrings.
Main Functions¶
The main DCCP interface provides these core functions:
- dccp.convexify_constr(constr: Constraint) ConvexConstraint | None [source]¶
Convexify a constraint for DCCP problems.
For DCP constraints, returns the constraint unchanged. For non-DCP constraints, linearizes the appropriate sides and returns a convexified constraint along with any domain constraints.
- Parameters:¶
- constr : cp.Constraint¶
The constraint to convexify.
- Returns:¶
ConvexConstraint or None – A ConvexConstraint object containing the convexified constraint and domain constraints, or None if linearization fails.
Notes
The function handles constraints by: - If the constraint is already DCP, return it unchanged - If the left side is concave, linearize it - If the right side is convex, linearize it - Collect domain constraints from linearization
- dccp.convexify_obj(obj: Minimize | Maximize) Minimize | None [source]¶
Convexify an objective function for DCCP problems.
Linearize non-DCP objectives. If the objective is already DCP, returns it unchanged. If the objective is a maximization problem, it is negated to convert it into a minimization problem.
- dccp.is_dccp(problem: Problem) bool [source]¶
Check if a CVXPY problem is DCCP compliant.
This function verifies whether a convex optimization problem satisfies the Disciplined Convex-Concave Programming (DCCP) rules, which allow for the solution of certain non-convex problems.
- Parameters:¶
- problem : cp.Problem¶
A CVXPY Problem object to check for DCCP compliance.
- Returns:¶
bool – True if the problem is DCCP compliant, False otherwise.
Notes
A problem is DCCP compliant if: 1. The objective function is DCCP compliant 2. All constraint arguments have known curvature (not “UNKNOWN”)
- dccp.linearize(expr: Expression) Expression | None [source]¶
Return the tangent approximation to the expression.
Linearize non-convex CVXPY expressions using first-order Taylor expansion around given points. The linearization approximates a function by:
\[f(x) ≈ f(x_0) + ∇f(x_0)^T(x - x_0)\]Where \(x_0\) is the point of linearization, \(f(x_0)\) is the function value at that point, and \(∇f(x_0)\) is the gradient at that point.
Problem Solving¶
-
class dccp.problem.DCCP(prob: Problem, *, settings: DCCPSettings | None =
None
, **kwargs: Any)[source]¶ Bases:
object
Implementation of the DCCP (Disciplined Convex-Concave Programming) algorithm.
The DCCP class provides a systematic approach to solving nonconvex optimization problems that satisfy the DCCP rules. It uses an iterative convex-concave procedure (CCP) to find approximate solutions.
- Parameters:¶
- Raises:¶
NonDCCPError – If the problem is DCP compliant (should use standard solvers) or if the problem doesn’t satisfy DCCP rules.
- class dccp.problem.DCCPIter(prob: ~cvxpy.problems.problem.Problem, tau: ~cvxpy.expressions.constants.parameter.Parameter = <factory>, vars_slack: list[~cvxpy.expressions.variable.Variable] = <factory>, k: int = 0, cost: float = inf)[source]¶
Bases:
object
Store results of a DCCP iteration.
- prob : Problem¶
- tau : Parameter¶
- vars_slack : list[Variable]¶
-
k : int =
0
¶
-
cost : float =
inf
¶
- property slack : float¶
Get the maximum slack variable value.
- property slack_sum : float¶
Sum of all slack elements.
- property cost_no_slack : float¶
Objective value minus τ * sum(slack).
-
dccp.problem.dccp(prob: Problem, *, max_iter: int =
100
, tau_ini: float =0.005
, mu: float =1.2
, tau_max: float =100000000.0
, k_ccp: int =1
, max_slack: float =0.001
, ep: float =1e-05
, seed: int | None =None
, verify_dccp: bool =True
, **kwargs: Any) float [source]¶ Run the DCCP algorithm on the given problem.
This is the main entry point for solving DCCP problems. It creates a DCCP solver instance with the specified settings and solves the problem.
- Parameters:¶
- prob : cp.Problem¶
A CVXPY Problem that satisfies DCCP rules.
- max_iter : int, default=100¶
Maximum number of iterations in the CCP algorithm.
- tau_ini : float, default=0.005¶
Initial value for tau parameter (trades off constraints vs objective).
- mu : float, default=1.2¶
Rate at which tau increases during the algorithm.
- tau_max : float, default=1e8¶
Upper bound for tau parameter.
- k_ccp : int, default=1¶
Number of random restarts for the CCP algorithm.
- max_slack : float, default=1e-3¶
Maximum slack variable value for convergence.
- ep : float, default=1e-5¶
Convergence tolerance for objective value changes.
- seed : int, optional¶
Random seed for reproducible results.
- verify_dccp : bool, default=True¶
Whether to verify DCCP compliance before solving.
- **kwargs: Any¶
Additional keyword arguments passed to the underlying solver.
- Returns:¶
float – The optimal objective value (or best found value if not converged).
- Raises:¶
NonDCCPError – If the problem doesn’t satisfy DCCP rules or is already DCP compliant.
See also
DCCP
The main DCCP solver class for more advanced usage.
DCCPSettings
Configuration object for algorithm parameters.
Examples
>>> import cvxpy as cp >>> import dccp >>> x = cp.Variable(2) >>> problem = cp.Problem(cp.Maximize(cp.norm(x, 2)), [cp.norm(x, 1) <= 1]) >>> result = dccp.dccp(problem, max_iter=50, k_ccp=3)
Utilities and Settings¶
-
class dccp.utils.DCCPSettings(*, max_iter: int =
100
, max_iter_damp: int =10
, tau_ini: float =0.005
, mu: float =1.2
, tau_max: float =100000000.0
, k_ini: int =1
, k_ccp: int =1
, max_slack: float =0.001
, ep: float =1e-05
, std: float =10.0
, seed: int | None =None
, verify_dccp: bool =True
)[source] Bases:
object
Settings for the DCCP algorithm.
This dataclass contains all configurable parameters for the DCCP algorithm, controlling convergence criteria, algorithm behavior, and initialization.
- max_iter
Maximum number of iterations in the CCP algorithm.
- Type:¶
int, default=100
- max_iter_damp
Maximum number of damping iterations when convergence fails.
- Type:¶
int, default=10
- tau_ini
Initial value for tau parameter (trades off constraints vs objective).
- Type:¶
float, default=0.005
- mu
Rate at which tau increases during the algorithm.
- Type:¶
float, default=1.2
- tau_max
Upper bound for tau parameter.
- Type:¶
float, default=1e8
- k_ini
Number of random projections for variable initialization.
- Type:¶
int, default=1
- k_ccp
Number of random restarts for the CCP algorithm.
- Type:¶
int, default=1
- max_slack
Maximum slack variable value for convergence.
- Type:¶
float, default=1e-3
- ep
Convergence tolerance for objective value changes.
- Type:¶
float, default=1e-5
- std
Standard deviation for random variable initialization.
- Type:¶
float, default=10.0
- seed
Random seed for reproducible results.
- Type:¶
int, optional
- verify_dccp
Whether to verify DCCP compliance before solving.
- Type:¶
bool, default=True
-
max_iter : int =
100
-
max_iter_damp : int =
10
-
tau_ini : float =
0.005
-
mu : float =
1.2
-
tau_max : float =
100000000.0
-
k_ini : int =
1
-
k_ccp : int =
1
-
max_slack : float =
0.001
-
ep : float =
1e-05
-
std : float =
10.0
-
seed : int | None =
None
-
verify_dccp : bool =
True
-
class dccp.utils.NonDCCPError(message: str =
'Problem is not DCCP compliant.'
)[source]¶ Bases:
Exception
Exception raised when a problem is not DCCP compliant.
This exception is raised when: - A problem is already DCP compliant (should use standard solvers) - A problem doesn’t satisfy DCCP rules (has unknown curvature) - Linearization fails during the algorithm
- dccp.utils.is_dccp(problem: Problem) bool [source]¶
Check if a CVXPY problem is DCCP compliant.
This function verifies whether a convex optimization problem satisfies the Disciplined Convex-Concave Programming (DCCP) rules, which allow for the solution of certain non-convex problems.
- Parameters:¶
- problem : cp.Problem¶
A CVXPY Problem object to check for DCCP compliance.
- Returns:¶
bool – True if the problem is DCCP compliant, False otherwise.
Notes
A problem is DCCP compliant if: 1. The objective function is DCCP compliant 2. All constraint arguments have known curvature (not “UNKNOWN”)
Linearization¶
- dccp.linearize.linearize(expr: Expression) Expression | None [source]¶
Return the tangent approximation to the expression.
Linearize non-convex CVXPY expressions using first-order Taylor expansion around given points. The linearization approximates a function by:
\[f(x) ≈ f(x_0) + ∇f(x_0)^T(x - x_0)\]Where \(x_0\) is the point of linearization, \(f(x_0)\) is the function value at that point, and \(∇f(x_0)\) is the gradient at that point.
Objective Convexification¶
- dccp.objective.convexify_obj(obj: Minimize | Maximize) Minimize | None [source]¶
Convexify an objective function for DCCP problems.
Linearize non-DCP objectives. If the objective is already DCP, returns it unchanged. If the objective is a maximization problem, it is negated to convert it into a minimization problem.
Constraint Convexification¶
- class dccp.constraint.ConvexConstraint(constr: Constraint, domain: list[Constraint])[source]
Bases:
object
A class to represent a convex constraint with domain constraints.
- constr
The convexified constraint.
- Type:¶
cp.Constraint
- domain
Additional domain constraints from linearization.
- Type:¶
list[cp.Constraint]
- constr : Constraint
- domain : list[Constraint]
- dccp.constraint.convexify_constr(constr: Constraint) ConvexConstraint | None [source]¶
Convexify a constraint for DCCP problems.
For DCP constraints, returns the constraint unchanged. For non-DCP constraints, linearizes the appropriate sides and returns a convexified constraint along with any domain constraints.
- Parameters:¶
- constr : cp.Constraint¶
The constraint to convexify.
- Returns:¶
ConvexConstraint or None – A ConvexConstraint object containing the convexified constraint and domain constraints, or None if linearization fails.
Notes
The function handles constraints by: - If the constraint is already DCP, return it unchanged - If the left side is concave, linearize it - If the right side is convex, linearize it - Collect domain constraints from linearization
Variable Initialization¶
-
dccp.initialization.initialize(prob: Problem, k_ini: int =
1
, seed: int | None =None
, solver: str | None =None
, std: float =10.0
, mean: float =0.0
, *, random: bool =False
) None [source]¶ Set initial values for DCCP problem variables.
This function initializes variables in a DCCP problem by solving auxiliary optimization problems. It can perform multiple random projections and average the results to obtain better initial values.
- Parameters:¶
- prob : Problem¶
The CVXPY Problem instance to initialize.
- k_ini : int, default=1¶
Number of random projections for each variable. Higher values may lead to better initialization but increase computation time.
- random : bool, default=False¶
If True, forces random initial values for all variables, overriding any user-provided initial values.
- seed : int or None, default=None¶
Random seed for reproducible initialization. If None, uses system entropy for random number generation.
- solver : str or None, default=None¶
Solver to use for the initialization subproblems. If None, uses CVXPY’s default solver selection.
- std : float, default=10.0¶
Standard deviation for the random initialization. This scales the random values generated for the variables.
- mean : float, default=0.0¶
Mean for the random initialization. This shifts the random values generated for the variables.
- Returns:¶
None – This function modifies the problem variables in-place by setting their .value attributes.