Skip to main content

omnibias.convex.torch.solver

0.1.0a2AlphaPython >=3.10AGPL / commercial

Differentiable LP and QP solver paths, barrier methods, KKT sensitivities, and scoped optimality evidence.

import omnibias.convex.torch.solver
Module contract & mathematical conventions

Closed-form-Hessian log-barrier interior-point LP/QP solver (torch).

Bit-identical algorithm to omnibias.convex.jax.solver: a damped-Newton central-path method with the closed-form barrier Hessian H = t Q + A^T diag(1/s^2) A solved by torch.linalg.solve. Solves in float64 for interior-point conditioning.

Shared formulas do not imply universal floating-point identity. Verify dtype, shape, derivative-order support, and the stated numerical assumptions for the path you use.

CLASS

InfeasibleProblemError​

omnibias.convex.torch.InfeasibleProblemErrorSource ↗
class InfeasibleProblemError(ValueError)

Raised when no strictly feasible point A x < b can be found.

Regression example · infeasible raises

This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.

def test_infeasible_raises() -> None:
    c = np.array([1.0])
    A = np.array([[1.0], [-1.0]])
    b = np.array([-1.0, -1.0])
    with pytest.raises(InfeasibleProblemError):
        solve_lp(_t(c), _t(A), _t(b))
python -m pytest packages/omnibias-convex/tests/test_solver_torch.py -k test_infeasible_raises -q
Read the implementation
class InfeasibleProblemError(ValueError):
    """Raised when no strictly feasible point ``A x < b`` can be found."""
Other public import paths
  • omnibias.convex.torch.InfeasibleProblemError
  • omnibias.convex.torch.solver.InfeasibleProblemError
FUNCTION

solve_lp​

omnibias.convex.torch.solve_lpSource ↗
solve_lp(c: object, A: object, b: object, *, x0: object | None=None, options: BarrierOptions | None=None) -> ConvexSolution[Tensor]

Solve the LP min c^T x s.t. A x <= b (Q = 0).

Parameters

NameType & defaultContract
cpositional-or-keywordobjectRequiredSee the operation contract and implementation below.
Apositional-or-keywordobjectRequiredSee the operation contract and implementation below.
bpositional-or-keywordobjectRequiredSee the operation contract and implementation below.
x0keyword-onlyobject | NoneDefault: NoneSee the operation contract and implementation below.
optionskeyword-onlyBarrierOptions | NoneDefault: NoneSee the operation contract and implementation below.
ReturnsConvexSolution[Tensor]
Executed regression · infeasible raises

Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.

def test_infeasible_raises() -> None:
    c = np.array([1.0])
    A = np.array([[1.0], [-1.0]])
    b = np.array([-1.0, -1.0])
    with pytest.raises(InfeasibleProblemError):
        solve_lp(_t(c), _t(A), _t(b))
python -m pytest "packages/omnibias-convex/tests/test_solver_torch.py::test_infeasible_raises" -q
Regression example · exterior start from infeasible point

This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.

def test_exterior_start_from_infeasible_point() -> None:
    c, A, b = _lp_2d()
    sol = solve_lp_penalty(c, A, b, x0=_t([9.0, 9.0]))
    ref = solve_lp(c, A, b)
    assert sol.converged
    np.testing.assert_allclose(sol.x.numpy(), ref.x.numpy(), atol=5e-3)
python -m pytest packages/omnibias-convex/tests/test_penalty_torch.py -k test_exterior_start_from_infeasible_point -q
Read the implementation
def solve_lp(
    c: object,
    A: object,
    b: object,
    *,
    x0: object | None = None,
    options: BarrierOptions | None = None,
) -> ConvexSolution[Tensor]:
    r"""Solve the LP ``min c^T x  s.t.  A x <= b`` (``Q = 0``)."""
    ct = _as64(c)
    n = ct.shape[0]
    Q = torch.zeros((n, n), dtype=torch.float64)
    return solve_qp(Q, ct, A, b, x0=x0, options=options)
Other public import paths
  • omnibias.convex.torch.solve_lp
  • omnibias.convex.torch.solver.solve_lp
FUNCTION

solve_qp​

omnibias.convex.torch.solve_qpSource ↗
solve_qp(Q: object, c: object, A: object, b: object, *, x0: object | None=None, options: BarrierOptions | None=None) -> ConvexSolution[Tensor]

Solve min 1/2 x^T Q x + c^T x s.t. A x <= b (Q PSD), in float64.

Parameters

NameType & defaultContract
Qpositional-or-keywordobjectRequiredSee the operation contract and implementation below.
cpositional-or-keywordobjectRequiredSee the operation contract and implementation below.
Apositional-or-keywordobjectRequiredSee the operation contract and implementation below.
bpositional-or-keywordobjectRequiredSee the operation contract and implementation below.
x0keyword-onlyobject | NoneDefault: NoneSee the operation contract and implementation below.
optionskeyword-onlyBarrierOptions | NoneDefault: NoneSee the operation contract and implementation below.
ReturnsConvexSolution[Tensor]
Explicit validation & failure cases
  • When bool((bt - At @ start <= 0.0).any()), raises InfeasibleProblemError('provided x0 is not strictly feasible (A x0 < b violated)').

These are explicit source guards. Backend operations may also raise for invalid shapes, dtypes, or unsupported devices.

Executed regression · infeasible raises

Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.

def test_infeasible_raises() -> None:
    c = np.array([1.0])
    A = np.array([[1.0], [-1.0]])
    b = np.array([-1.0, -1.0])
    with pytest.raises(InfeasibleProblemError):
        solve_lp(_t(c), _t(A), _t(b))
python -m pytest "packages/omnibias-convex/tests/test_solver_torch.py::test_infeasible_raises" -q
Regression example · qp projection onto nonnegative orthant

This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.

def test_qp_projection_onto_nonnegative_orthant() -> None:
    p = np.array([1.5, -2.0, 0.7, -0.1])
    n = 4
    sol = solve_qp(_t(np.eye(n)), _t(-p), _t(-np.eye(n)), _t(np.zeros(n)))
    np.testing.assert_allclose(sol.x.numpy(), np.maximum(p, 0.0), atol=1e-6)
python -m pytest packages/omnibias-convex/tests/test_solver_torch.py -k test_qp_projection_onto_nonnegative_orthant -q
Read the implementation
def solve_qp(
    Q: object,
    c: object,
    A: object,
    b: object,
    *,
    x0: object | None = None,
    options: BarrierOptions | None = None,
) -> ConvexSolution[Tensor]:
    r"""Solve ``min 1/2 x^T Q x + c^T x  s.t.  A x <= b`` (``Q`` PSD), in float64."""
    opts = options or BarrierOptions()
    Qt = _as64(Q)
    ct = _as64(c)
    At = _as64(A)
    bt = _as64(b)
    n = ct.shape[0]
    m = bt.shape[0]
    validate_shapes(
        n, m, A_shape=tuple(At.shape), b_shape=tuple(bt.shape),
        c_shape=tuple(ct.shape), Q_shape=tuple(Qt.shape),
    )

    if x0 is not None:
        start = _as64(x0)
        phase1_newton = 0
    else:
        start, phase1_newton = _strictly_feasible_start(At, bt, opts)
    if bool((bt - At @ start <= 0.0).any()):
        raise InfeasibleProblemError("provided x0 is not strictly feasible (A x0 < b violated)")

    x, slack, t, iterations, gap, converged, newton_total = _central_path_solve(
        Qt, ct, At, bt, start, opts
    )
    dual = 1.0 / (t * slack)
    return ConvexSolution(
        x=x,
        dual=dual,
        slack=slack,
        obj=_objective(Qt, ct, x),
        gap=gap,
        iterations=iterations,
        converged=converged,
        newton_iterations=newton_total + phase1_newton,
    )
Other public import paths
  • omnibias.convex.torch.solve_qp
  • omnibias.convex.torch.solver.solve_qp