How to use the diffcp.cone_program.SolverError function in diffcp

To help you get started, we’ve selected a few diffcp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cvxgrp / diffcp / tests.py View on Github external
def test_infeasible(self):
        np.random.seed(0)
        c = np.ones(1)
        b = np.array([1.0, -1.0])
        A = sparse.csc_matrix(np.ones((2, 1)))
        cone_dims = {"f": 2}
        with self.assertRaises(cone_prog.SolverError, msg='Solver ecos returned status Infeasible'):
            cone_prog.solve_and_derivative(A, b, c, cone_dims, solver="ECOS")
github cvxgrp / diffcp / diffcp / cone_program.py View on Github external
data["s"] = warm_start[2]

    kwargs.setdefault("verbose", False)
    result = scs.solve(data, cone_dict, **kwargs)

    status = result["info"]["status"]
    if status == "Solved/Inaccurate" and "acceleration_lookback" not in kwargs:
        # anderson acceleration is sometimes unstable
        result = scs.solve(data, cone_dict, acceleration_lookback=0, **kwargs)
        status = result["info"]["status"]

    if status == "Solved/Inaccurate":
        warnings.warn("Solved/Inaccurate.")
    elif status != "Solved":
        if raise_on_error:
            raise SolverError("Solver scs returned status %s" % status)
        else:
            result["D"] = None
            result["DT"] = None
            return result

    x = result["x"]
    y = result["y"]
    s = result["s"]

    # pre-compute quantities for the derivative
    m, n = A.shape
    N = m + n + 1
    cones = cone_lib.parse_cone_dict(cone_dict)
    cones_parsed = cone_lib.parse_cone_dict_cpp(cones)
    z = (x, y - s, np.array([1]))
    u, v, w = z