當前位置: 首頁>>代碼示例>>Python>>正文


Python cvxpy.SolverError方法代碼示例

本文整理匯總了Python中cvxpy.SolverError方法的典型用法代碼示例。如果您正苦於以下問題:Python cvxpy.SolverError方法的具體用法?Python cvxpy.SolverError怎麽用?Python cvxpy.SolverError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cvxpy的用法示例。


在下文中一共展示了cvxpy.SolverError方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: solve

# 需要導入模塊: import cvxpy [as 別名]
# 或者: from cvxpy import SolverError [as 別名]
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 
開發者ID:EmbersArc,項目名稱:SuccessiveConvexificationFreeFinalTime,代碼行數:20,代碼來源:scproblem.py

示例2: test_diamond_norm

# 需要導入模塊: import cvxpy [as 別名]
# 或者: from cvxpy import SolverError [as 別名]
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.") 
開發者ID:Qiskit,項目名稱:qiskit-terra,代碼行數:25,代碼來源:test_measures.py

示例3: solve

# 需要導入模塊: import cvxpy [as 別名]
# 或者: from cvxpy import SolverError [as 別名]
def solve(self, **kwargs):
        error = False
        try:
            self.prob.solve(**kwargs)
        except cvx.SolverError:
            error = True

        return error 
開發者ID:EmbersArc,項目名稱:SCvx,代碼行數:10,代碼來源:scproblem.py

示例4: _test_same

# 需要導入模塊: import cvxpy [as 別名]
# 或者: from cvxpy import SolverError [as 別名]
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 
開發者ID:koaning,項目名稱:scikit-lego,代碼行數:40,代碼來源:test_demographic_parity.py

示例5: solve

# 需要導入模塊: import cvxpy [as 別名]
# 或者: from cvxpy import SolverError [as 別名]
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) 
開發者ID:oxfordcontrol,項目名稱:osqp_benchmarks,代碼行數:55,代碼來源:ecos.py


注:本文中的cvxpy.SolverError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。