From d78cefe4d43aecf89c643115063d841794963383 Mon Sep 17 00:00:00 2001 From: AdrienTaylor <10559960+AdrienTaylor@users.noreply.github.com> Date: Fri, 28 Nov 2025 18:23:46 +0100 Subject: [PATCH 1/2] safe mode --- PEPit/pep.py | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/PEPit/pep.py b/PEPit/pep.py index ea932618..82653f09 100644 --- a/PEPit/pep.py +++ b/PEPit/pep.py @@ -281,8 +281,9 @@ def set_performance_metric(self, expression, name=None): # Store performance metric in the appropriate list self.list_of_performance_metrics.append(expression) - def solve(self, wrapper="cvxpy", return_primal_or_dual="dual", verbose=1, - dimension_reduction_heuristic=None, eig_regularization=1e-3, tol_dimension_reduction=1e-4, **kwargs): + def solve(self, wrapper="cvxpy", return_primal_or_dual="dual", safe_mode=True, verbose=1, + dimension_reduction_heuristic=None, eig_regularization=1e-3, tol_dimension_reduction=1e-4, + **kwargs): """ Transform the :class:`PEP` under the SDP form, and solve it. Parse the options for solving the SDPs, instantiate the concerning wrappers and call the main internal solve option for solving the PEP. @@ -296,6 +297,9 @@ def solve(self, wrapper="cvxpy", return_primal_or_dual="dual", verbose=1, (primal value of the objective). Default is "dual". Note both value should be almost the same by strong duality. + safe_mode (bool, optional): Enable safe mode that includes basic checks such as appropriate packages + being installed or not, or licenses. Deactivating might lead to codes that + are harder to debug. verbose (int, optional): Level of information details to print (Override the solver verbose parameter). @@ -315,11 +319,11 @@ def solve(self, wrapper="cvxpy", return_primal_or_dual="dual", verbose=1, eig_regularization (float, optional): The regularization we use to make :math:`G + \\mathrm{eig_regularization}I_d \succ 0`. (only used when "dimension_reduction_heuristic" is not None) - The default value is 1e-5. + The default value is 1e-3. tol_dimension_reduction (float, optional): The error tolerance in the heuristic minimization problem. Precisely, the second problem minimizes "optimal_value - tol" (only used when "dimension_reduction_heuristic" is not None) - The default value is 1e-5. + The default value is 1e-4. kwargs (keywords, optional): Additional solver-specific arguments. Returns: @@ -330,21 +334,23 @@ def solve(self, wrapper="cvxpy", return_primal_or_dual="dual", verbose=1, # Check that the solver is installed, if it is not, switch to CVXPY. found_python_package = importlib.util.find_spec(wrapper_name) - if found_python_package is None: - if verbose: - print('\033[96m(PEPit) {} not found in system environment,' - ' switching to cvxpy\033[0m'.format(wrapper_name)) - wrapper_name = "cvxpy" + if safe_mode: + if found_python_package is None: + if verbose: + print('\033[96m(PEPit) {} not found in system environment,' + ' switching to cvxpy\033[0m'.format(wrapper_name)) + wrapper_name = "cvxpy" # Initiate a wrapper to interface with the solver wrapper = WRAPPERS[wrapper_name](verbose=verbose) # Check that a valid license to the solver is found. Otherwise, switch to CVXPY. - if not wrapper.check_license(): - if verbose: - print('\033[96m(PEPit) No valid {} license found, switching to cvxpy\033[96m'.format(wrapper_name)) - wrapper_name = "cvxpy" - wrapper = WRAPPERS[wrapper_name](verbose=verbose) + if safe_mode: + if not wrapper.check_license(): + if verbose: + print('\033[96m(PEPit) No valid {} license found, switching to cvxpy\033[96m'.format(wrapper_name)) + wrapper_name = "cvxpy" + wrapper = WRAPPERS[wrapper_name](verbose=verbose) # Store wrapper information in self self.wrapper_name = wrapper_name From 3043f0e3b6a44030753e190af373a6c2dada86d3 Mon Sep 17 00:00:00 2001 From: AdrienTaylor <10559960+AdrienTaylor@users.noreply.github.com> Date: Fri, 28 Nov 2025 18:25:44 +0100 Subject: [PATCH 2/2] whatsnew --- docs/source/whatsnew/0.4.1.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/source/whatsnew/0.4.1.rst b/docs/source/whatsnew/0.4.1.rst index fb8b98cc..26e58856 100644 --- a/docs/source/whatsnew/0.4.1.rst +++ b/docs/source/whatsnew/0.4.1.rst @@ -5,4 +5,6 @@ What's new in PEPit 0.4.1 - Added uselessly complexified tests to verify numerically that the formulations are in line. -- Fix: An integer overflow (due to previously specified dtype=int8) in :class:`MosekWrapper` has been fixed. \ No newline at end of file +- Fix: An integer overflow (due to previously specified dtype=int8) in :class:`MosekWrapper` has been fixed. + +- New: one can disable some software verification tools (licensing, installation, etc) to allow for fast processing time (via boolean option safe_mode).