Middle-End Reductions¶

The reductions listed here are not specific to a type of solver. They can be applied regardless of whether you wish to target, for example, a quadratic program solver or a conic solver.

Please see our disclaimer about the Reductions API before using these directly in your code.

Complex2Real¶

class cvxpy.reductions.complex2real.complex2real.Complex2Real(problem=None)[source]¶

Bases: Reduction

Lifts complex numbers to a real representation.

accepts(problem) None[source]¶

States whether the reduction accepts a problem.

Parameters:¶
problem : Problem¶

The problem to check.

Returns:¶

True if the reduction can be applied, False otherwise.

Return type:¶

bool

apply(problem)[source]¶

Applies the reduction to a problem and returns an equivalent problem.

Parameters:¶
problem : Problem¶

The problem to which the reduction will be applied.

Returns:¶

  • Problem or dict – An equivalent problem, encoded either as a Problem or a dict.

  • InverseData, list or dict – Data needed by the reduction in order to invert this particular application.

invert(solution, inverse_data)[source]¶

Returns a solution to the original problem given the inverse_data.

Parameters:¶
solution : Solution¶

A solution to a problem that generated the inverse_data.

inverse_data¶

The data encoding the original problem.

Returns:¶

A solution to the original problem.

Return type:¶

Solution

CvxAttr2Constr¶

class cvxpy.reductions.cvx_attr2constr.CvxAttr2Constr(problem=None, reduce_bounds: bool = False)[source]¶

Bases: Reduction

Expand convex variable attributes into constraints.

accepts(problem) bool[source]¶

States whether the reduction accepts a problem.

Parameters:¶
problem : Problem¶

The problem to check.

Returns:¶

True if the reduction can be applied, False otherwise.

Return type:¶

bool

apply(problem)[source]¶

Applies the reduction to a problem and returns an equivalent problem.

Parameters:¶
problem : Problem¶

The problem to which the reduction will be applied.

Returns:¶

  • Problem or dict – An equivalent problem, encoded either as a Problem or a dict.

  • InverseData, list or dict – Data needed by the reduction in order to invert this particular application.

invert(solution, inverse_data) Solution[source]¶

Returns a solution to the original problem given the inverse_data.

Parameters:¶
solution : Solution¶

A solution to a problem that generated the inverse_data.

inverse_data¶

The data encoding the original problem.

Returns:¶

A solution to the original problem.

Return type:¶

Solution

reduction_attributes() list[str][source]¶

Returns the attributes that will be reduced.

Dgp2Dcp¶

class cvxpy.reductions.dgp2dcp.dgp2dcp.Dgp2Dcp(problem=None)[source]¶

Bases: Canonicalization

Reduce DGP problems to DCP problems.

This reduction takes as input a DGP problem and returns an equivalent DCP problem. Because every (generalized) geometric program is a DGP problem, this reduction can be used to convert geometric programs into convex form.

Example

>>> import cvxpy as cp
>>>
>>> x1 = cp.Variable(pos=True)
>>> x2 = cp.Variable(pos=True)
>>> x3 = cp.Variable(pos=True)
>>>
>>> monomial = 3.0 * x_1**0.4 * x_2 ** 0.2 * x_3 ** -1.4
>>> posynomial = monomial + 2.0 * x_1 * x_2
>>> dgp_problem = cp.Problem(cp.Minimize(posynomial), [monomial == 4.0])
>>>
>>> dcp2cone = cvxpy.reductions.Dcp2Cone()
>>> assert not dcp2cone.accepts(dgp_problem)
>>>
>>> gp2dcp = cvxpy.reductions.Dgp2Dcp(dgp_problem)
>>> dcp_problem = gp2dcp.reduce()
>>>
>>> assert dcp2cone.accepts(dcp_problem)
>>> dcp_problem.solve()
>>>
>>> dgp_problem.unpack(gp2dcp.retrieve(dcp_problem.solution))
>>> print(dgp_problem.value)
>>> print(dgp_problem.variables())
accepts(problem)[source]¶

A problem is accepted if it is DGP.

apply(problem)[source]¶

Converts a DGP problem to a DCP problem.

canonicalize_expr(expr: Expression, args: list, canonicalize_params: bool = True)[source]¶

Canonicalize an expression, w.r.t. canonicalized arguments.

Parameters:¶
expr: Expression¶

Expression to canonicalize.

args: list¶

Arguments to the expression.

canonicalize_params: bool = True¶

Should constant subtrees containing parameters be canonicalized?

Returns:¶

canonicalized expression, constraints

invert(solution, inverse_data)[source]¶

Returns a solution to the original problem given the inverse_data.

Parameters:¶
solution : Solution¶

A solution to a problem that generated the inverse_data.

inverse_data¶

The data encoding the original problem.

Returns:¶

A solution to the original problem.

Return type:¶

Solution

EvalParams¶

class cvxpy.reductions.eval_params.EvalParams(problem=None)[source]¶

Bases: Reduction

Replaces symbolic parameters with their constant values.

accepts(problem) bool[source]¶

States whether the reduction accepts a problem.

Parameters:¶
problem : Problem¶

The problem to check.

Returns:¶

True if the reduction can be applied, False otherwise.

Return type:¶

bool

apply(problem)[source]¶

Replace parameters with constant values.

Parameters:¶
problem : Problem¶

The problem whose parameters should be evaluated.

Returns:¶

A new problem where the parameters have been converted to constants.

Return type:¶

Problem

Raises:¶

ParameterError – If the problem has unspecified parameters (i.e., a parameter whose value is None).

invert(solution, inverse_data)[source]¶

Returns a solution to the original problem given the inverse_data.

FlipObjective¶

class cvxpy.reductions.flip_objective.FlipObjective(problem=None)[source]¶

Bases: Reduction

Flip a minimization objective to a maximization and vice versa.

accepts(problem) bool[source]¶

States whether the reduction accepts a problem.

Parameters:¶
problem : Problem¶

The problem to check.

Returns:¶

True if the reduction can be applied, False otherwise.

Return type:¶

bool

apply(problem)[source]¶

\(\max(f(x)) = -\min(-f(x))\)

Parameters:¶
problem : Problem¶

The problem whose objective is to be flipped.

Returns:¶

  • Problem – A problem with a flipped objective.

  • list – The inverse data.

invert(solution, inverse_data)[source]¶

Map the solution of the flipped problem to that of the original.

Parameters:¶
solution : Solution¶

A solution object.

inverse_data : list¶

The inverse data returned by an invocation to apply.

Returns:¶

A solution to the original problem.

Return type:¶

Solution