Python cvxpy.SolverError() Examples
The following are 6
code examples of cvxpy.SolverError().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
cvxpy
, or try the search function
.
Example #1
Source File: scproblem.py From SuccessiveConvexificationFreeFinalTime with MIT License | 6 votes |
def solve(self, **kwargs): error = False try: self.prob.solve(**kwargs) except cvx.SolverError: error = True stats = self.prob.solver_stats print() info = { 'setup_time': stats.setup_time, 'solver_time': stats.solve_time, 'iterations': stats.num_iters, 'solver_error': error } return info
Example #2
Source File: test_measures.py From qiskit-terra with Apache License 2.0 | 6 votes |
def test_diamond_norm(self, num_qubits): """Test the diamond_norm for {num_qubits}-qubit pauli channel.""" # pylint: disable=import-outside-toplevel try: import cvxpy except ImportError: # Skip test if CVXPY not installed self.skipTest("CVXPY not installed.") # Pauli channels have an analytic expression for the # diamond norm so we can easily test it op = Choi(np.zeros((4 ** num_qubits, 4 ** num_qubits))) labels = [num_qubits * i for i in ['I', 'X', 'Y', 'Z']] coeffs = [-1.0, 0.5, 2.5, -0.1] for coeff, label in zip(coeffs, labels): op = op + coeff * Choi(Operator.from_label(label)) target = np.sum(np.abs(coeffs)) try: value = diamond_norm(op) self.assertAlmostEqual(value, target, places=4) except cvxpy.SolverError: self.skipTest("CVXPY solver failed.")
Example #3
Source File: scproblem.py From SCvx with MIT License | 5 votes |
def solve(self, **kwargs): error = False try: self.prob.solve(**kwargs) except cvx.SolverError: error = True return error
Example #4
Source File: scproblem.py From SCvx with MIT License | 5 votes |
def solve(self, **kwargs): error = False try: self.prob.solve(**kwargs) except cvx.SolverError: error = True return error
Example #5
Source File: test_demographic_parity.py From scikit-lego with MIT License | 5 votes |
def _test_same(dataset): X, y = dataset if X.shape[1] == 1: # If we only have one column (which is also the sensitive one) we can't fit return True sensitive_cols = [0] X_without_sens = np.delete(X, sensitive_cols, axis=1) lr = LogisticRegression( penalty="none", solver="lbfgs", multi_class="ovr", dual=False, tol=1e-4, C=1.0, fit_intercept=True, intercept_scaling=1, class_weight=None, random_state=None, max_iter=100, verbose=0, warm_start=False, n_jobs=None, l1_ratio=None, ) fair = DemographicParityClassifier( covariance_threshold=None, sensitive_cols=sensitive_cols, penalty="none" ) try: fair.fit(X, y) except SolverError: pass else: lr.fit(X_without_sens, y) normal_pred = lr.predict_proba(X_without_sens) fair_pred = fair.predict_proba(X) np.testing.assert_almost_equal(normal_pred, fair_pred, decimal=3) assert np.sum(lr.predict(X_without_sens) != fair.predict(X)) / len(X) < 0.01
Example #6
Source File: ecos.py From osqp_benchmarks with Apache License 2.0 | 4 votes |
def solve(self, example): ''' Solve problem Args: example: example object Returns: Results structure ''' problem = example.cvxpy_problem if 'verbose' in self._settings: verbose = self._settings["verbose"] else: verbose = False try: obj_val = problem.solve(solver=cvxpy.ECOS, verbose=verbose) except cvxpy.SolverError: if 'verbose' in self._settings: # if verbose is null, suppress it if self._settings['verbose']: print("Error in ECOS solution\n") return Results(s.SOLVER_ERROR, None, None, None, None, None) status = self.STATUS_MAP.get(problem.status, s.SOLVER_ERROR) # Obtain time and number of iterations run_time = problem.solver_stats.solve_time \ + problem.solver_stats.setup_time niter = problem.solver_stats.num_iters # Get primal, dual solution x, y = example.revert_cvxpy_solution() # Validate status if not is_qp_solution_optimal(example.qp_problem, x, y, high_accuracy=self._settings.get('high_accuracy')): status = s.SOLVER_ERROR # Validate execution time if 'time_limit' in self._settings: if run_time > self._settings['time_limit']: status = s.TIME_LIMIT return Results(status, obj_val, x, y, run_time, niter)