Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

KOS connectors: Pyomo, PuLP and CVXPY

Use KOS (the Katsenia Optimization Solver) from the modeling layer where your model already lives:

modeling layer import how to solve
Pyomo (6.9.2 or later) import kos_pyomo pyo.SolverFactory("kos").solve(model)
PuLP (3.3.1 or later) from kos_pulp import KOS prob.solve(KOS())
CVXPY (1.7.1 or later) from kos_cvxpy import KOS prob.solve(solver=KOS())

The connectors solve LPs and MILPs: a linear objective, linear constraints, and continuous, integer and binary variables. Anything else (nonlinear or quadratic terms, conic constraints, SOS, logical or disjunctive constraints) raises an error that says what is not supported.

Installation

pip install --pre "kos-connectors[pyomo]"     # or [pulp], [cvxpy], [all]

kos-connectors is pure Python, for Python 3.9 or later; it depends on kos-solver (the solver, a compiled package for Linux on x86_64 and aarch64, imported as kos) and, through the extras, on the modeling layer. The Community edition of kos-solver on PyPI solves models of up to 2,000 rows and 2,000 columns; a larger model raises kos.Error with the code size_limit (see https://katsenia.com/pricing.html); in Pyomo, it ends with the termination condition licensingProblems (Pyomo's condition for a license of the wrong type for the problem), with the KOS message in results.extra_info.kos_error. kos_connectors.edition() says which edition is installed. The limit counts the rows and columns KOS receives: with CVXPY, the rows of its conic form (bounds given as cp.Variable(n, bounds=[l, u]) are column bounds; x >= l and x <= u as constraints are rows).

The same result as KOS directly

Each connector hands KOS the model exactly as the modeling layer states it: the same columns and rows, in the same order, with the same coefficients, bounds, objective constant and integrality. The model goes to KOS as exact LP text (every number written so that it reads back as the same double), so what KOS computes through a connector (the status, the objective, the values, the duals, the reduced costs, the iterations) is the same, bit for bit, as KOS directly (kos.Model.read) on a file with that model and the same parameters; solver.kos_model is that KOS model. Every connector can write that file (write_model / writeModel), and our tests compare the two runs bit for bit on the netlib LPs, the netlib infeasible LPs and a bank of small MILPs.

What the modeling layer shows:

  • Pyomo: KOS's values, duals, reduced costs and incumbent_objective, unchanged.
  • PuLP: KOS's values (varValue), pi and dj, unchanged; PuLP computes constraint.slack from KOS's row activity (the right-hand side minus the activity); the objective PuLP shows (value(prob.objective), LpSolveStats.objective) is PuLP's own evaluation at those values, which can differ from KOS's in the last bits: KOS's is solver.kos_model.objective.
  • CVXPY: problem.solution.opt_val is KOS's objective of the minimization form (negated by CVXPY when maximizing); problem.value is CVXPY's own evaluation, and CVXPY may project x.value onto the variable bounds (a value 1e-13 below a bound of 0 shows as 0.0). KOS's values are in solver.kos_model.solution.

What each modeling layer hands its solvers:

  • Pyomo: the active constraints in their order (as (lower, body, upper), with the constant of the body moved to the bounds); the variables they and the objective use, in declaration order; fixed variables as constants.
  • PuLP: PuLP 4, the variables the problem uses, in creation order; PuLP 3, LpProblem.variables(), which PuLP sorts by name. The constraints in their order, each expression + constant <sense> 0 as expression <sense> -constant. PuLP has no ranged constraints.
  • CVXPY: its conic form (minimize c^T x + d subject to A x + s = b, s in the zero cone or the nonnegative orthant, and the variable bounds), with d as the objective constant, so that a MIP gap is relative to the true objective. A >= constraint reaches KOS as a <= row with its signs changed.

Parameters

Every KOS parameter can be set by name (kos.parameters() lists them; "profile" sets a KOS profile), after the standard options of the modeling layer and in the order given:

standard options mapped to KOS KOS parameters
Pyomo time_limit → time_limit, threads → threads, rel_gap → mip_relative_gap, abs_gap → mip_absolute_gap (classic interface: timelimit) solver_options={...} (classic interface: options={...})
PuLP timeLimit → time_limit, gapRel → mip_relative_gap, gapAbs → mip_absolute_gap, threads → threads, maxNodes → node_limit, mip=False solves the LP relaxation any other keyword argument, and options=["name=value", ...]
CVXPY (none) the constructor, KOS(method="primal", presolve="on"), then the keyword arguments of solve; method only in the constructor (CVXPY's solve takes method for itself)
pyo.SolverFactory("kos").solve(m, options={"profile": "stable", "primal_tolerance": 1e-9})
prob.solve(KOS(msg=False, timeLimit=60, gapRel=1e-6, presolve="on"))
prob.solve(solver=KOS(), time_limit=60, mip_relative_gap=1e-6)

An unknown name or a value out of range raises kos.Error (unknown_parameter or invalid_value) before solving. KOS has no MIP start in its public API: PuLP's warmStart is ignored with a warning.

Duals and reduced costs

KOS's duals y are the change of the objective per unit increase of the active bound of each row, in the sense of the model, and its reduced costs are d = c - A^T y. Each connector reports them in the convention of its modeling layer; they exist for an LP with a solution, not for a MILP.

duals reduced costs
Pyomo (model.dual, model.rc, get_duals, get_reduced_costs) y: minimizing, a binding <= constraint has a dual <= 0 and a >= one >= 0; maximizing, the opposite d (a fixed variable is a constant for KOS: it has no reduced cost, and asking for it raises ValueError)
PuLP (constraint.pi, variable.dj) y: minimizing, <= gives pi <= 0; maximizing, >= 0 d
CVXPY (constraint.dual_value) the multipliers of CVXPY's minimization form, >= 0 for inequalities: -y of the model KOS receives (KOS gets the minimization form, also when maximizing) (CVXPY has none)

PuLP's constraint.slack is the right-hand side minus the activity.

Statuses

The KOS status is always available: results.extra_info.kos_status (Pyomo), solver.kos_status (PuLP), problem.solver_stats.extra_stats["kos_status"] (CVXPY), and solver.kos_model is the kos.Model of the last solve.

KOS Pyomo TerminationCondition PuLP 4 LpSolveStatus CVXPY
optimal convergenceCriteriaSatisfied Optimal OPTIMAL
optimal_flagged unknown (solution status unknown; feasible in Pyomo 6.9, which has no unknown) NumericalError (with a solution) OPTIMAL_INACCURATE
infeasible provenInfeasible Infeasible INFEASIBLE
dual_infeasible unbounded with a feasible point, else infeasibleOrUnbounded Unbounded with a feasible point, else Undefined UNBOUNDED with a feasible point, else INFEASIBLE_OR_UNBOUNDED
unbounded unbounded Unbounded UNBOUNDED
infeasible_or_unbounded infeasibleOrUnbounded Undefined INFEASIBLE_OR_UNBOUNDED
iteration_limit iterationLimit IterationLimit USER_LIMIT or error
time_limit maxTimeLimit TimeLimit USER_LIMIT or error
objective_limit objectiveLimit GapLimit USER_LIMIT or error
work_limit maxTimeLimit TimeLimit USER_LIMIT or error
node_limit iterationLimit NodeLimit USER_LIMIT or error
solution_limit unknown SolutionLimit USER_LIMIT or error
target_reached objectiveLimit GapLimit USER_LIMIT or error
gap_after_nodes iterationLimit (solution status feasible) GapLimit USER_LIMIT or error
interrupted interrupted Interrupted USER_LIMIT or error
no_verdict error NumericalError error

Only optimal is convergenceCriteriaSatisfied in Pyomo: every limit, also the gap target by node count (gap_after_nodes), is a limit, and pyo.check_optimal_termination is false for them. dual_infeasible means that the LP has no finite optimum: it is unbounded if it has a feasible point, and it may also be infeasible; the connectors report it as unbounded only when KOS's certificate of the solve has a feasible point (a ray and a point within the primal tolerance). To know it, the connector writes that certificate after the solve, to a temporary folder that it removes: extra work, bounded by the KOS parameter certificate_work_limit, that time_limit does not count and Ctrl-C does not stop. In CVXPY, "USER_LIMIT or error" is USER_LIMIT when there is a solution (a MILP incumbent) and cvxpy.error.SolverError, with the KOS status and its meaning in the message, when there is none. With PuLP 3, the statuses are PuLP 3's LpStatus and sol_status: a limit with a solution is (Optimal, IntegerFeasible), PuLP 3's convention, without one (Not Solved, No Solution Found); an LP optimum that KOS flags is (Undefined, IntegerFeasible), and dual_infeasible without a feasible point is (Undefined, No Solution Found).

Pyomo follows the rules of its solver interfaces: by default a status other than convergenceCriteriaSatisfied raises NoOptimalSolutionError, and load_solutions=True without a solution raises NoFeasibleSolutionError (raise_exception_on_nonoptimal_result=False and load_solutions=False return the results instead). With no active objective, incumbent_objective is None.

Stopping a solve

Ctrl-C during a solve stops KOS cleanly: the result has the status interrupted, with the best MILP solution found so far, if any (a second Ctrl-C does not wait for KOS). From another thread, solver.interrupt() does the same.

License

Apache License 2.0 (see LICENSE and NOTICE). Copyright 2026 Katsenia SpA. KOS itself (the kos-solver package) is licensed separately: see https://katsenia.com/license.html.

Metadata

Release files for kos-connectors 1.0.0b1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kos-connectors 1.0.0b1
File Size Uploaded Provenance Actions
kos_connectors-1.0.0b1.tar.gz 35.0 kB Without provenance Details for kos_connectors-1.0.0b1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for kos-connectors 1.0.0b1
File Interpreter ABI Platform Actions
kos_connectors-1.0.0b1-py3-none-any.whl Python 3 none any Details for kos_connectors-1.0.0b1-py3-none-any.whl

Total release size: 70.3 kB

Release files / kos_connectors-1.0.0b1.tar.gz

Download URL kos_connectors-1.0.0b1.tar.gz
Size 35.0 kB
Tags Source
SHA-256 checksum
How to use checksums
b1a25a77e3a8582c3fdf642cec2886b65f254dbbd7a340c09fbd5ba3309de54d
BLAKE2b-256 checksum
How to use checksums
d96707a97f3e9adbb4207ed009688a0121d20e206ee064a44cea9922915b5e6f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / kos_connectors-1.0.0b1-py3-none-any.whl

Download URL kos_connectors-1.0.0b1-py3-none-any.whl
Size 35.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
798558034110ba1016d2a222f7643405609391e635a5ecf144f8b30930d272b7
BLAKE2b-256 checksum
How to use checksums
86febc85c9879995a2055d98f150b0477fbbaace006a4af7a72bcb11edcb13fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Security for kos-connectors 1.0.0b1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page