Wrappers

CVXPY

class PEPit.wrappers.CvxpyWrapper(verbose=1)[source]

Bases: Wrapper

A Cvxpy_wrapper object interfaces PEPit with the CVXPY modelling language.

This class overwrites the Wrapper for CVXPY. In particular, it implements the methods: send_constraint_to_solver, send_lmi_constraint_to_solver, generate_problem, get_dual_variables, get_primal_variables, eval_constraint_dual_values, solve, prepare_heuristic, and heuristic.

Attributes:
  • _list_of_constraints_sent_to_solver (list) – list of Constraint and PSDMatrix objects associated to the PEP. This list does not contain constraints due to internal representation of the problem by the solver.

  • optimal_F (numpy.array) – Elements of F after solving.

  • optimal_G (numpy.array) – Gram matrix of the PEP after solving.

  • objective (Expression) – The objective expression that must be maximized. This is an additional Expression created by the PEP to deal with cases where the user wants to maximize a minimum of several expressions.

  • dual_values (list) – Optimal dual variables after solving (same ordering as that of _list_of_constraints_sent_to_solver).

  • residual (Iterable of Iterables of floats) – The residual of the problem, i.e. the dual variable of the Gram.

  • prob – instance of the problem (whose type depends on the solver).

  • solver_name (str) – The name of the solver the wrapper interact with.

  • verbose (int) – Level of information details to print (Override the solver verbose parameter).

    • 0: No verbose at all

    • 1: PEPit information is printed but not solver’s

    • 2: Both PEPit and solver details are printed

  • F (cvxpy.Variable) – a 1D cvxpy.Variable that represents PEPit’s Expressions.

  • G (cvxpy.Variable) – a 2D cvxpy.Variable that represents PEPit’s Gram matrix.

  • _list_of_solver_constraints (list of cvxpy.Constraint) – the list of constraints of the problem in CVXPY format.

This function initialize all internal variables of the class.

Parameters:

verbose (int) –

Level of information details to print (Override the solver verbose parameter).

  • 0: No verbose at all

  • 1: PEPit information is printed but not solver’s

  • 2: Both PEPit and solver details are printed

check_license()[source]

Check that there is a valid available license for CVXPY.

Returns:

license presence (bool) – no license needed: True

generate_problem(objective)[source]

Instantiate an optimization model using the cvxpy format, whose objective corresponds to a PEPit Expression object.

Parameters:

objective (Expression) – the objective function of the PEP (to be maximized).

Returns:

prob (cvxpy.Problem) – the PEP in cvxpy format.

heuristic(weight)[source]

Change the objective of the PEP, specifically for finding low-dimensional examples. We specify a matrix \(W\) (weight), which will allow minimizing \(\mathrm{Tr}(G\,W)\).

Parameters:

weight (np.array) – weights that will be used in the heuristic.

prepare_heuristic(wc_value, tol_dimension_reduction)[source]

Add the constraint that the objective stay close to its actual value before using dimension-reduction heuristics. That is, we constrain

\[\tau \leqslant \text{wc value} + \text{tol dimension reduction}\]
Parameters:
  • wc_value (float) – the optimal value of the original PEP.

  • tol_dimension_reduction (float) – tolerance on the objective for finding low-dimensional examples.

send_constraint_to_solver(constraint)[source]

Transform a PEPit Constraint into a CVXPY one and add the 2 formats of the constraints into the tracking lists.

Parameters:

constraint (Constraint) – a Constraint object to be sent to CVXPY.

:raises ValueError if the attribute equality_or_inequality of the Constraint: :raises is neither equality, nor inequality.:

send_lmi_constraint_to_solver(psd_counter, psd_matrix)[source]

Transform a PEPit PSDMatrix into a CVXPY symmetric PSD matrix and add the 2 formats of the constraints into the tracking lists.

Parameters:
  • psd_counter (int) – a counter useful for the verbose mode.

  • psd_matrix (PSDMatrix) – a matrix of expressions that is constrained to be PSD.

set_main_variables()[source]

Create base cvxpy variables and main cvxpy constraint: G >> 0.

solve(**kwargs)[source]

Solve the PEP.

Parameters:

kwargs (keywords, optional) – solver specific arguments.

Returns:
  • status (string) – status of the solution / problem.

  • name (string) – name of the solver.

  • value (float) – value of the performance metric after solving.

  • problem (cvxpy Problem) – solver-specific model of the PEP.

MOSEK

class PEPit.wrappers.MosekWrapper(verbose=1)[source]

Bases: Wrapper

A MosekWrapper object interfaces PEPit with the SDP solver MOSEK.

This class overwrites the Wrapper for MOSEK. In particular, it implements the methods: send_constraint_to_solver, send_lmi_constraint_to_solver, generate_problem, get_dual_variables, get_primal_variables, eval_constraint_dual_values, solve, prepare_heuristic, and heuristic.

Attributes:
  • _list_of_constraints_sent_to_solver (list) – list of Constraint and PSDMatrix objects associated to the PEP. This list does not contain constraints due to internal representation of the problem by the solver.

  • optimal_F (numpy.array) – Elements of F after solving.

  • optimal_G (numpy.array) – Gram matrix of the PEP after solving.

  • objective (Expression) – The objective expression that must be maximized. This is an additional Expression created by the PEP to deal with cases where the user wants to maximize a minimum of several expressions.

  • dual_values (list) – Optimal dual variables after solving (same ordering as that of _list_of_constraints_sent_to_solver).

  • residual (Iterable of Iterables of floats) – The residual of the problem, i.e. the dual variable of the Gram.

  • prob – instance of the problem (whose type depends on the solver).

  • solver_name (str) – The name of the solver the wrapper interact with.

  • verbose (int) – Level of information details to print (Override the solver verbose parameter).

    • 0: No verbose at all

    • 1: PEPit information is printed but not solver’s

    • 2: Both PEPit and solver details are printed

  • _constraint_index_in_mosek (list of integer) – indices corresponding to the list of constraints sent to MOSEK.

  • _nb_pep_constraints_in_mosek (int) – total number of scalar constraints sent to MOSEK.

  • _list_of_psd_constraints_sent_to_solver (list) – list of PSD constraints sent to MOSEK.

  • _nb_pep_SDPconstraints_in_mosek (int) – total number of PSD constraints sent to MOSEK.

  • env – MOSEK environment

  • task – Mosek task

This function initializes all internal variables of the class.

Parameters:

verbose (int) –

Level of information details to print (Override the solver verbose parameter).

  • 0: No verbose at all

  • 1: PEPit information is printed but not solver’s

  • 2: Both PEPit and solver details are printed

check_license()[source]

Check that there is a valid available license for MOSEK.

Returns:

license (bool) – is there a valid license?

generate_problem(objective)[source]

Instantiate an optimization model using the mosek format, whose objective corresponds to a PEPit Expression object.

Parameters:

objective (Expression) – the objective function of the PEP (to be maximized).

Returns:

prob (mosek.task) – the PEP in mosek’s format.

heuristic(weight)[source]

Change the objective of the PEP, specifically for finding low-dimensional examples. We specify a matrix \(W\) (weight), which will allow minimizing \(\mathrm{Tr}(G\,W)\).

Parameters:

weight (np.array) – weights that will be used in the heuristic.

prepare_heuristic(wc_value, tol_dimension_reduction)[source]

Add the constraint that the objective stay close to its actual value before using dimension-reduction heuristics. That is, we constrain

\[\tau \leqslant \text{wc value} + \text{tol dimension reduction}\]
Parameters:
  • wc_value (float) – the optimal value of the original PEP.

  • tol_dimension_reduction (float) – tolerance on the objective for finding low-dimensional examples.

send_constraint_to_solver(constraint, track=True)[source]

Add a PEPit Constraint in a Mosek task and add it to the tracking list.

Parameters:
  • constraint (Constraint) – a Constraint object to be sent to MOSEK.

  • track (bool, optional) – do we track the constraint (saving dual variable, etc.)?

:raises ValueError if the attribute equality_or_inequality of the Constraint: :raises is neither equality, nor inequality.:

send_lmi_constraint_to_solver(psd_counter, psd_matrix)[source]

Transfer a PEPit PSDMatrix (LMI constraint) to MOSEK and add it the tracking lists.

Parameters:
  • psd_counter (int) – a counter useful for the verbose mode.

  • psd_matrix (PSDMatrix) – a matrix of expressions that is constrained to be PSD.

set_main_variables()[source]

Initialize the main variables of the optimization problem and set the main constraint G >> 0.

solve(**kwargs)[source]

Solve the PEP.

Parameters:

kwargs (keywords, optional) – solver specific arguments.

Returns:
  • status (string) – status of the solution / problem.

  • name (string) – name of the solver.

  • value (float) – value of the performance metric after solving.

  • problem (mosek task) – solver-specific model of the PEP.