kos-connectors 1.0.0b1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,4 @@
1
+ kos-connectors
2
+ Copyright 2026 Katsenia SpA
3
+
4
+ Licensed under the Apache License, Version 2.0 (see the LICENSE file).
@@ -0,0 +1,187 @@
1
+ Metadata-Version: 2.4
2
+ Name: kos-connectors
3
+ Version: 1.0.0b1
4
+ Summary: KOS (Katsenia Optimization Solver) for Pyomo, PuLP and CVXPY: LP and MILP, with the same result as KOS directly
5
+ Author-email: Katsenia SpA <support@katsenia.com>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://katsenia.com
8
+ Project-URL: Documentation, https://katsenia.com/help.html
9
+ Keywords: optimization,linear programming,mixed-integer programming,solver,pyomo,pulp,cvxpy
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Operating System :: POSIX :: Linux
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Programming Language :: Python :: 3.14
22
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
23
+ Requires-Python: >=3.9
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ License-File: NOTICE
27
+ Requires-Dist: kos-solver>=1.0.0b1
28
+ Requires-Dist: numpy
29
+ Provides-Extra: pyomo
30
+ Requires-Dist: pyomo>=6.9.2; extra == "pyomo"
31
+ Provides-Extra: pulp
32
+ Requires-Dist: pulp>=3.3.1; extra == "pulp"
33
+ Provides-Extra: cvxpy
34
+ Requires-Dist: cvxpy>=1.7.1; extra == "cvxpy"
35
+ Requires-Dist: scipy; extra == "cvxpy"
36
+ Provides-Extra: all
37
+ Requires-Dist: pyomo>=6.9.2; extra == "all"
38
+ Requires-Dist: pulp>=3.3.1; extra == "all"
39
+ Requires-Dist: cvxpy>=1.7.1; extra == "all"
40
+ Requires-Dist: scipy; extra == "all"
41
+ Dynamic: license-file
42
+
43
+ # KOS connectors: Pyomo, PuLP and CVXPY
44
+
45
+ Use KOS (the Katsenia Optimization Solver) from the modeling layer where your model already lives:
46
+
47
+ | modeling layer | import | how to solve |
48
+ |---|---|---|
49
+ | [Pyomo](https://www.pyomo.org) (6.9.2 or later) | `import kos_pyomo` | `pyo.SolverFactory("kos").solve(model)` |
50
+ | [PuLP](https://coin-or.github.io/pulp/) (3.3.1 or later) | `from kos_pulp import KOS` | `prob.solve(KOS())` |
51
+ | [CVXPY](https://www.cvxpy.org) (1.7.1 or later) | `from kos_cvxpy import KOS` | `prob.solve(solver=KOS())` |
52
+
53
+ The connectors solve LPs and MILPs: a linear objective, linear constraints, and continuous, integer and binary
54
+ variables. Anything else (nonlinear or quadratic terms, conic constraints, SOS, logical or disjunctive constraints)
55
+ raises an error that says what is not supported.
56
+
57
+ ## Installation
58
+
59
+ ```
60
+ pip install --pre "kos-connectors[pyomo]" # or [pulp], [cvxpy], [all]
61
+ ```
62
+
63
+ `kos-connectors` is pure Python, for Python 3.9 or later; it depends on `kos-solver` (the solver, a compiled package
64
+ for Linux on x86_64 and aarch64, imported as `kos`) and, through the extras, on the modeling layer. The Community
65
+ edition of `kos-solver` on PyPI solves models of up to 2,000 rows and 2,000 columns; a larger model raises
66
+ `kos.Error` with the code `size_limit` (see https://katsenia.com/pricing.html); in Pyomo, it ends with
67
+ the termination condition `licensingProblems` (Pyomo's condition for a license of the wrong type for the problem),
68
+ with the KOS message in `results.extra_info.kos_error`. `kos_connectors.edition()` says which edition is installed.
69
+ The limit counts the rows and columns KOS receives: with CVXPY, the rows of its conic form (bounds given as
70
+ `cp.Variable(n, bounds=[l, u])` are column bounds; `x >= l` and `x <= u` as constraints are rows).
71
+
72
+ ## The same result as KOS directly
73
+
74
+ Each connector hands KOS the model exactly as the modeling layer states it: the same columns and rows, in the same
75
+ order, with the same coefficients, bounds, objective constant and integrality. The model goes to KOS as exact LP text
76
+ (every number written so that it reads back as the same double), so what KOS computes through a connector (the
77
+ status, the objective, the values, the duals, the reduced costs, the iterations) is the same, bit for bit, as KOS
78
+ directly (`kos.Model.read`) on a file with that model and the same parameters; `solver.kos_model` is that KOS model.
79
+ Every connector can write that file (`write_model` / `writeModel`), and our tests compare the two runs bit for bit on
80
+ the netlib LPs, the netlib infeasible LPs and a bank of small MILPs.
81
+
82
+ What the modeling layer shows:
83
+
84
+ - **Pyomo**: KOS's values, duals, reduced costs and `incumbent_objective`, unchanged.
85
+ - **PuLP**: KOS's values (`varValue`), `pi` and `dj`, unchanged; PuLP computes `constraint.slack` from KOS's row
86
+ activity (the right-hand side minus the activity); the objective PuLP shows (`value(prob.objective)`,
87
+ `LpSolveStats.objective`) is PuLP's own evaluation at those values, which can differ from KOS's in the last bits:
88
+ KOS's is `solver.kos_model.objective`.
89
+ - **CVXPY**: `problem.solution.opt_val` is KOS's objective of the minimization form (negated by CVXPY when
90
+ maximizing); `problem.value` is CVXPY's own evaluation, and CVXPY may project `x.value` onto the variable bounds (a
91
+ value 1e-13 below a bound of 0 shows as 0.0). KOS's values are in `solver.kos_model.solution`.
92
+
93
+ What each modeling layer hands its solvers:
94
+
95
+ - **Pyomo**: the active constraints in their order (as `(lower, body, upper)`, with the constant of the body moved to
96
+ the bounds); the variables they and the objective use, in declaration order; fixed variables as constants.
97
+ - **PuLP**: PuLP 4, the variables the problem uses, in creation order; PuLP 3, `LpProblem.variables()`, which PuLP
98
+ sorts by name. The constraints in their order, each `expression + constant <sense> 0` as
99
+ `expression <sense> -constant`. PuLP has no ranged constraints.
100
+ - **CVXPY**: its conic form (`minimize c^T x + d` subject to `A x + s = b`, `s` in the zero cone or the nonnegative
101
+ orthant, and the variable bounds), with `d` as the objective constant, so that a MIP gap is relative to the true
102
+ objective. A `>=` constraint reaches KOS as a `<=` row with its signs changed.
103
+
104
+ ## Parameters
105
+
106
+ Every KOS parameter can be set by name (`kos.parameters()` lists them; `"profile"` sets a KOS profile), after the
107
+ standard options of the modeling layer and in the order given:
108
+
109
+ | | standard options mapped to KOS | KOS parameters |
110
+ |---|---|---|
111
+ | 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={...}`) |
112
+ | 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", ...]` |
113
+ | 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) |
114
+
115
+ ```python
116
+ pyo.SolverFactory("kos").solve(m, options={"profile": "stable", "primal_tolerance": 1e-9})
117
+ prob.solve(KOS(msg=False, timeLimit=60, gapRel=1e-6, presolve="on"))
118
+ prob.solve(solver=KOS(), time_limit=60, mip_relative_gap=1e-6)
119
+ ```
120
+
121
+ An unknown name or a value out of range raises `kos.Error` (`unknown_parameter` or `invalid_value`) before solving.
122
+ KOS has no MIP start in its public API: PuLP's `warmStart` is ignored with a warning.
123
+
124
+ ## Duals and reduced costs
125
+
126
+ KOS's duals `y` are the change of the objective per unit increase of the active bound of each row, in the sense of
127
+ the model, and its reduced costs are `d = c - A^T y`. Each connector reports them in the convention of its modeling
128
+ layer; they exist for an LP with a solution, not for a MILP.
129
+
130
+ | | duals | reduced costs |
131
+ |---|---|---|
132
+ | 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`) |
133
+ | PuLP (`constraint.pi`, `variable.dj`) | `y`: minimizing, `<=` gives `pi <= 0`; maximizing, `>= 0` | `d` |
134
+ | 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) |
135
+
136
+ PuLP's `constraint.slack` is the right-hand side minus the activity.
137
+
138
+ ## Statuses
139
+
140
+ The KOS status is always available: `results.extra_info.kos_status` (Pyomo), `solver.kos_status` (PuLP),
141
+ `problem.solver_stats.extra_stats["kos_status"]` (CVXPY), and `solver.kos_model` is the `kos.Model` of the last solve.
142
+
143
+ | KOS | Pyomo `TerminationCondition` | PuLP 4 `LpSolveStatus` | CVXPY |
144
+ |---|---|---|---|
145
+ | `optimal` | `convergenceCriteriaSatisfied` | `Optimal` | `OPTIMAL` |
146
+ | `optimal_flagged` | `unknown` (solution status `unknown`; `feasible` in Pyomo 6.9, which has no `unknown`) | `NumericalError` (with a solution) | `OPTIMAL_INACCURATE` |
147
+ | `infeasible` | `provenInfeasible` | `Infeasible` | `INFEASIBLE` |
148
+ | `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` |
149
+ | `unbounded` | `unbounded` | `Unbounded` | `UNBOUNDED` |
150
+ | `infeasible_or_unbounded` | `infeasibleOrUnbounded` | `Undefined` | `INFEASIBLE_OR_UNBOUNDED` |
151
+ | `iteration_limit` | `iterationLimit` | `IterationLimit` | `USER_LIMIT` or error |
152
+ | `time_limit` | `maxTimeLimit` | `TimeLimit` | `USER_LIMIT` or error |
153
+ | `objective_limit` | `objectiveLimit` | `GapLimit` | `USER_LIMIT` or error |
154
+ | `work_limit` | `maxTimeLimit` | `TimeLimit` | `USER_LIMIT` or error |
155
+ | `node_limit` | `iterationLimit` | `NodeLimit` | `USER_LIMIT` or error |
156
+ | `solution_limit` | `unknown` | `SolutionLimit` | `USER_LIMIT` or error |
157
+ | `target_reached` | `objectiveLimit` | `GapLimit` | `USER_LIMIT` or error |
158
+ | `gap_after_nodes` | `iterationLimit` (solution status `feasible`) | `GapLimit` | `USER_LIMIT` or error |
159
+ | `interrupted` | `interrupted` | `Interrupted` | `USER_LIMIT` or error |
160
+ | `no_verdict` | `error` | `NumericalError` | error |
161
+
162
+ Only `optimal` is `convergenceCriteriaSatisfied` in Pyomo: every limit, also the gap target by node count
163
+ (`gap_after_nodes`), is a limit, and `pyo.check_optimal_termination` is false for them. `dual_infeasible` means that
164
+ the LP has no finite optimum: it is unbounded if it has a feasible point, and it may also be infeasible; the connectors
165
+ report it as unbounded only when KOS's certificate of the solve has a feasible point (a ray and a point within the
166
+ primal tolerance). To know it, the connector writes that certificate after the solve, to a temporary folder that it
167
+ removes: extra work, bounded by the KOS parameter `certificate_work_limit`, that `time_limit` does not count and
168
+ Ctrl-C does not stop. In CVXPY, "`USER_LIMIT` or error" is `USER_LIMIT` when there is a solution (a MILP incumbent) and
169
+ `cvxpy.error.SolverError`, with the KOS status and its meaning in the message, when there is none. With PuLP 3, the
170
+ statuses are PuLP 3's `LpStatus` and `sol_status`: a limit with a solution is (`Optimal`, `IntegerFeasible`), PuLP 3's
171
+ convention, without one (`Not Solved`, `No Solution Found`); an LP optimum that KOS flags is (`Undefined`,
172
+ `IntegerFeasible`), and `dual_infeasible` without a feasible point is (`Undefined`, `No Solution Found`).
173
+
174
+ Pyomo follows the rules of its solver interfaces: by default a status other than `convergenceCriteriaSatisfied`
175
+ raises `NoOptimalSolutionError`, and `load_solutions=True` without a solution raises `NoFeasibleSolutionError`
176
+ (`raise_exception_on_nonoptimal_result=False` and `load_solutions=False` return the results instead). With no active
177
+ objective, `incumbent_objective` is `None`.
178
+
179
+ ## Stopping a solve
180
+
181
+ Ctrl-C during a solve stops KOS cleanly: the result has the status `interrupted`, with the best MILP solution found so
182
+ far, if any (a second Ctrl-C does not wait for KOS). From another thread, `solver.interrupt()` does the same.
183
+
184
+ ## License
185
+
186
+ Apache License 2.0 (see `LICENSE` and `NOTICE`). Copyright 2026 Katsenia SpA. KOS itself (the `kos-solver` package)
187
+ is licensed separately: see https://katsenia.com/license.html.
@@ -0,0 +1,145 @@
1
+ # KOS connectors: Pyomo, PuLP and CVXPY
2
+
3
+ Use KOS (the Katsenia Optimization Solver) from the modeling layer where your model already lives:
4
+
5
+ | modeling layer | import | how to solve |
6
+ |---|---|---|
7
+ | [Pyomo](https://www.pyomo.org) (6.9.2 or later) | `import kos_pyomo` | `pyo.SolverFactory("kos").solve(model)` |
8
+ | [PuLP](https://coin-or.github.io/pulp/) (3.3.1 or later) | `from kos_pulp import KOS` | `prob.solve(KOS())` |
9
+ | [CVXPY](https://www.cvxpy.org) (1.7.1 or later) | `from kos_cvxpy import KOS` | `prob.solve(solver=KOS())` |
10
+
11
+ The connectors solve LPs and MILPs: a linear objective, linear constraints, and continuous, integer and binary
12
+ variables. Anything else (nonlinear or quadratic terms, conic constraints, SOS, logical or disjunctive constraints)
13
+ raises an error that says what is not supported.
14
+
15
+ ## Installation
16
+
17
+ ```
18
+ pip install --pre "kos-connectors[pyomo]" # or [pulp], [cvxpy], [all]
19
+ ```
20
+
21
+ `kos-connectors` is pure Python, for Python 3.9 or later; it depends on `kos-solver` (the solver, a compiled package
22
+ for Linux on x86_64 and aarch64, imported as `kos`) and, through the extras, on the modeling layer. The Community
23
+ edition of `kos-solver` on PyPI solves models of up to 2,000 rows and 2,000 columns; a larger model raises
24
+ `kos.Error` with the code `size_limit` (see https://katsenia.com/pricing.html); in Pyomo, it ends with
25
+ the termination condition `licensingProblems` (Pyomo's condition for a license of the wrong type for the problem),
26
+ with the KOS message in `results.extra_info.kos_error`. `kos_connectors.edition()` says which edition is installed.
27
+ The limit counts the rows and columns KOS receives: with CVXPY, the rows of its conic form (bounds given as
28
+ `cp.Variable(n, bounds=[l, u])` are column bounds; `x >= l` and `x <= u` as constraints are rows).
29
+
30
+ ## The same result as KOS directly
31
+
32
+ Each connector hands KOS the model exactly as the modeling layer states it: the same columns and rows, in the same
33
+ order, with the same coefficients, bounds, objective constant and integrality. The model goes to KOS as exact LP text
34
+ (every number written so that it reads back as the same double), so what KOS computes through a connector (the
35
+ status, the objective, the values, the duals, the reduced costs, the iterations) is the same, bit for bit, as KOS
36
+ directly (`kos.Model.read`) on a file with that model and the same parameters; `solver.kos_model` is that KOS model.
37
+ Every connector can write that file (`write_model` / `writeModel`), and our tests compare the two runs bit for bit on
38
+ the netlib LPs, the netlib infeasible LPs and a bank of small MILPs.
39
+
40
+ What the modeling layer shows:
41
+
42
+ - **Pyomo**: KOS's values, duals, reduced costs and `incumbent_objective`, unchanged.
43
+ - **PuLP**: KOS's values (`varValue`), `pi` and `dj`, unchanged; PuLP computes `constraint.slack` from KOS's row
44
+ activity (the right-hand side minus the activity); the objective PuLP shows (`value(prob.objective)`,
45
+ `LpSolveStats.objective`) is PuLP's own evaluation at those values, which can differ from KOS's in the last bits:
46
+ KOS's is `solver.kos_model.objective`.
47
+ - **CVXPY**: `problem.solution.opt_val` is KOS's objective of the minimization form (negated by CVXPY when
48
+ maximizing); `problem.value` is CVXPY's own evaluation, and CVXPY may project `x.value` onto the variable bounds (a
49
+ value 1e-13 below a bound of 0 shows as 0.0). KOS's values are in `solver.kos_model.solution`.
50
+
51
+ What each modeling layer hands its solvers:
52
+
53
+ - **Pyomo**: the active constraints in their order (as `(lower, body, upper)`, with the constant of the body moved to
54
+ the bounds); the variables they and the objective use, in declaration order; fixed variables as constants.
55
+ - **PuLP**: PuLP 4, the variables the problem uses, in creation order; PuLP 3, `LpProblem.variables()`, which PuLP
56
+ sorts by name. The constraints in their order, each `expression + constant <sense> 0` as
57
+ `expression <sense> -constant`. PuLP has no ranged constraints.
58
+ - **CVXPY**: its conic form (`minimize c^T x + d` subject to `A x + s = b`, `s` in the zero cone or the nonnegative
59
+ orthant, and the variable bounds), with `d` as the objective constant, so that a MIP gap is relative to the true
60
+ objective. A `>=` constraint reaches KOS as a `<=` row with its signs changed.
61
+
62
+ ## Parameters
63
+
64
+ Every KOS parameter can be set by name (`kos.parameters()` lists them; `"profile"` sets a KOS profile), after the
65
+ standard options of the modeling layer and in the order given:
66
+
67
+ | | standard options mapped to KOS | KOS parameters |
68
+ |---|---|---|
69
+ | 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={...}`) |
70
+ | 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", ...]` |
71
+ | 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) |
72
+
73
+ ```python
74
+ pyo.SolverFactory("kos").solve(m, options={"profile": "stable", "primal_tolerance": 1e-9})
75
+ prob.solve(KOS(msg=False, timeLimit=60, gapRel=1e-6, presolve="on"))
76
+ prob.solve(solver=KOS(), time_limit=60, mip_relative_gap=1e-6)
77
+ ```
78
+
79
+ An unknown name or a value out of range raises `kos.Error` (`unknown_parameter` or `invalid_value`) before solving.
80
+ KOS has no MIP start in its public API: PuLP's `warmStart` is ignored with a warning.
81
+
82
+ ## Duals and reduced costs
83
+
84
+ KOS's duals `y` are the change of the objective per unit increase of the active bound of each row, in the sense of
85
+ the model, and its reduced costs are `d = c - A^T y`. Each connector reports them in the convention of its modeling
86
+ layer; they exist for an LP with a solution, not for a MILP.
87
+
88
+ | | duals | reduced costs |
89
+ |---|---|---|
90
+ | 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`) |
91
+ | PuLP (`constraint.pi`, `variable.dj`) | `y`: minimizing, `<=` gives `pi <= 0`; maximizing, `>= 0` | `d` |
92
+ | 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) |
93
+
94
+ PuLP's `constraint.slack` is the right-hand side minus the activity.
95
+
96
+ ## Statuses
97
+
98
+ The KOS status is always available: `results.extra_info.kos_status` (Pyomo), `solver.kos_status` (PuLP),
99
+ `problem.solver_stats.extra_stats["kos_status"]` (CVXPY), and `solver.kos_model` is the `kos.Model` of the last solve.
100
+
101
+ | KOS | Pyomo `TerminationCondition` | PuLP 4 `LpSolveStatus` | CVXPY |
102
+ |---|---|---|---|
103
+ | `optimal` | `convergenceCriteriaSatisfied` | `Optimal` | `OPTIMAL` |
104
+ | `optimal_flagged` | `unknown` (solution status `unknown`; `feasible` in Pyomo 6.9, which has no `unknown`) | `NumericalError` (with a solution) | `OPTIMAL_INACCURATE` |
105
+ | `infeasible` | `provenInfeasible` | `Infeasible` | `INFEASIBLE` |
106
+ | `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` |
107
+ | `unbounded` | `unbounded` | `Unbounded` | `UNBOUNDED` |
108
+ | `infeasible_or_unbounded` | `infeasibleOrUnbounded` | `Undefined` | `INFEASIBLE_OR_UNBOUNDED` |
109
+ | `iteration_limit` | `iterationLimit` | `IterationLimit` | `USER_LIMIT` or error |
110
+ | `time_limit` | `maxTimeLimit` | `TimeLimit` | `USER_LIMIT` or error |
111
+ | `objective_limit` | `objectiveLimit` | `GapLimit` | `USER_LIMIT` or error |
112
+ | `work_limit` | `maxTimeLimit` | `TimeLimit` | `USER_LIMIT` or error |
113
+ | `node_limit` | `iterationLimit` | `NodeLimit` | `USER_LIMIT` or error |
114
+ | `solution_limit` | `unknown` | `SolutionLimit` | `USER_LIMIT` or error |
115
+ | `target_reached` | `objectiveLimit` | `GapLimit` | `USER_LIMIT` or error |
116
+ | `gap_after_nodes` | `iterationLimit` (solution status `feasible`) | `GapLimit` | `USER_LIMIT` or error |
117
+ | `interrupted` | `interrupted` | `Interrupted` | `USER_LIMIT` or error |
118
+ | `no_verdict` | `error` | `NumericalError` | error |
119
+
120
+ Only `optimal` is `convergenceCriteriaSatisfied` in Pyomo: every limit, also the gap target by node count
121
+ (`gap_after_nodes`), is a limit, and `pyo.check_optimal_termination` is false for them. `dual_infeasible` means that
122
+ the LP has no finite optimum: it is unbounded if it has a feasible point, and it may also be infeasible; the connectors
123
+ report it as unbounded only when KOS's certificate of the solve has a feasible point (a ray and a point within the
124
+ primal tolerance). To know it, the connector writes that certificate after the solve, to a temporary folder that it
125
+ removes: extra work, bounded by the KOS parameter `certificate_work_limit`, that `time_limit` does not count and
126
+ Ctrl-C does not stop. In CVXPY, "`USER_LIMIT` or error" is `USER_LIMIT` when there is a solution (a MILP incumbent) and
127
+ `cvxpy.error.SolverError`, with the KOS status and its meaning in the message, when there is none. With PuLP 3, the
128
+ statuses are PuLP 3's `LpStatus` and `sol_status`: a limit with a solution is (`Optimal`, `IntegerFeasible`), PuLP 3's
129
+ convention, without one (`Not Solved`, `No Solution Found`); an LP optimum that KOS flags is (`Undefined`,
130
+ `IntegerFeasible`), and `dual_infeasible` without a feasible point is (`Undefined`, `No Solution Found`).
131
+
132
+ Pyomo follows the rules of its solver interfaces: by default a status other than `convergenceCriteriaSatisfied`
133
+ raises `NoOptimalSolutionError`, and `load_solutions=True` without a solution raises `NoFeasibleSolutionError`
134
+ (`raise_exception_on_nonoptimal_result=False` and `load_solutions=False` return the results instead). With no active
135
+ objective, `incumbent_objective` is `None`.
136
+
137
+ ## Stopping a solve
138
+
139
+ Ctrl-C during a solve stops KOS cleanly: the result has the status `interrupted`, with the best MILP solution found so
140
+ far, if any (a second Ctrl-C does not wait for KOS). From another thread, `solver.interrupt()` does the same.
141
+
142
+ ## License
143
+
144
+ Apache License 2.0 (see `LICENSE` and `NOTICE`). Copyright 2026 Katsenia SpA. KOS itself (the `kos-solver` package)
145
+ is licensed separately: see https://katsenia.com/license.html.
@@ -0,0 +1,43 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "kos-connectors"
7
+ version = "1.0.0b1"
8
+ description = "KOS (Katsenia Optimization Solver) for Pyomo, PuLP and CVXPY: LP and MILP, with the same result as KOS directly"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = "Apache-2.0"
12
+ license-files = ["LICENSE", "NOTICE"]
13
+ authors = [{ name = "Katsenia SpA", email = "support@katsenia.com" }]
14
+ keywords = ["optimization", "linear programming", "mixed-integer programming", "solver", "pyomo", "pulp", "cvxpy"]
15
+ classifiers = [
16
+ "Development Status :: 4 - Beta",
17
+ "Intended Audience :: Developers",
18
+ "Intended Audience :: Science/Research",
19
+ "Operating System :: POSIX :: Linux",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3 :: Only",
22
+ "Programming Language :: Python :: 3.9",
23
+ "Programming Language :: Python :: 3.10",
24
+ "Programming Language :: Python :: 3.11",
25
+ "Programming Language :: Python :: 3.12",
26
+ "Programming Language :: Python :: 3.13",
27
+ "Programming Language :: Python :: 3.14",
28
+ "Topic :: Scientific/Engineering :: Mathematics",
29
+ ]
30
+ dependencies = ["kos-solver>=1.0.0b1", "numpy"]
31
+
32
+ [project.optional-dependencies]
33
+ pyomo = ["pyomo>=6.9.2"]
34
+ pulp = ["pulp>=3.3.1"]
35
+ cvxpy = ["cvxpy>=1.7.1", "scipy"]
36
+ all = ["pyomo>=6.9.2", "pulp>=3.3.1", "cvxpy>=1.7.1", "scipy"]
37
+
38
+ [project.urls]
39
+ Homepage = "https://katsenia.com"
40
+ Documentation = "https://katsenia.com/help.html"
41
+
42
+ [tool.setuptools.packages.find]
43
+ where = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,19 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # Copyright 2026 Katsenia SpA. Licensed under the Apache License, Version 2.0 (kos-connectors/LICENSE).
3
+ """KOS connectors for modeling layers: Pyomo (`kos_pyomo`), PuLP (`kos_pulp`) and CVXPY (`kos_cvxpy`).
4
+
5
+ Each connector hands the model to KOS exactly as the modeling layer states it (same columns, rows, coefficients,
6
+ bounds, objective constant and integrality, in the same order) and solves it with the same parameters as KOS
7
+ directly: what KOS computes (status, objective, values, duals) is the same, bit for bit, as with `kos.Model.read` on a
8
+ file with that model. The modeling layer gets it with its own sign conventions, which each connector documents; PuLP
9
+ and CVXPY evaluate the objective they show themselves, and CVXPY may project the values onto the variable bounds.
10
+
11
+ This package holds what the connectors share; users import the connector of their modeling layer.
12
+ """
13
+
14
+ from ._nucleo import EXPLICACION as STATUS_MEANINGS
15
+ from ._nucleo import ModelError, edicion as edition
16
+
17
+ __version__ = "1.0.0b1"
18
+
19
+ __all__ = ["ModelError", "STATUS_MEANINGS", "edition", "__version__"]