How to use the qpsolvers.sparse_solvers function in qpsolvers

To help you get started, we’ve selected a few qpsolvers 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 stephane-caron / qpsolvers / examples / dense_problem.py View on Github external
h = array([3., 2., -2.]).reshape((3,))
P_csc = csc_matrix(P)
G_csc = csc_matrix(G)


if __name__ == "__main__":
    if get_ipython() is None:
        print("Usage: ipython -i %s" % basename(__file__))
        exit()

    dense_instr = {
        solver: "u = solve_qp(P, q, G, h, solver='%s')" % solver
        for solver in dense_solvers}
    sparse_instr = {
        solver: "u = solve_qp(P_csc, q, G_csc, h, solver='%s')" % solver
        for solver in sparse_solvers}

    print("\nTesting all QP solvers on a dense quadratic program...")

    sol0 = solve_qp(P, q, G, h, solver=dense_solvers[0])
    for solver in dense_solvers:
        sol = solve_qp(P, q, G, h, solver=solver)
        delta = norm(sol - sol0)
        assert delta < 1e-4, "%s's solution offset by %.1e" % (solver, delta)
    for solver in sparse_solvers:
        sol = solve_qp(P_csc, q, G_csc, h, solver=solver)
        delta = norm(sol - sol0)
        assert delta < 1e-4, "%s's solution offset by %.1e" % (solver, delta)

    print("\nDense solvers\n-------------")
    for solver, instr in dense_instr.items():
        print("%s: " % solver, end='')
github stephane-caron / qpsolvers / examples / sparse_problem.py View on Github external
def time_sparse_solvers():
    instructions = {
        solver: "u = solve_qp(P, q, G, h, solver='%s')" % solver
        for solver in sparse_solvers}
    print("\nSparse solvers\n--------------")
    for solver, instr in instructions.items():
        print("%s: " % solver, end='')
        get_ipython().magic('timeit %s' % instr)

qpsolvers

Quadratic programming solvers in Python with a unified API.

LGPL-3.0
Latest version published 3 months ago

Package Health Score

76 / 100
Full package analysis

Similar packages