kos-verify 1.0.0b1__py3-none-any.whl

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,371 @@
1
+ # The KOS certificate format (`kos-certificate`, version 1)
2
+
3
+ A **certificate** is a JSON file that KOS writes after solving an LP (`kos solve --certificate FILE`,
4
+ `kos_write_certificate` in C, `Model.write_certificate` in Python). It says what the solve proves about the model —
5
+ an optimum, an infeasibility, an unboundedness or a bound — and carries the numbers that prove it. **kos-verify**
6
+ (`kos-verify/kos_verify.py`, open source, independent of the KOS code) checks it against the model file in exact
7
+ rational arithmetic: it trusts no number of KOS, it only checks what the numbers imply. This page specifies the
8
+ format precisely enough for anyone to write another verifier.
9
+
10
+ Version 1 defines the kinds of **LP** certificates (models without integer columns). MIP certificates (the
11
+ branch-and-bound tree with its bounds, in the style of the VIPR format) will be new kinds of version 1, with
12
+ `model.problem = "mip"`; the integrality is already part of the model (section 1.1) and of the fingerprint. A verifier
13
+ rejects a kind it does not know (section 8).
14
+
15
+ This specification is licensed under the Creative Commons Attribution 4.0 International license (CC BY 4.0,
16
+ https://creativecommons.org/licenses/by/4.0/), copyright 2026 Katsenia SpA. kos-verify is licensed under the Apache
17
+ License, Version 2.0 (`kos-verify/LICENSE`).
18
+
19
+ ## 1. The model
20
+
21
+ The model is the LP
22
+
23
+ ```
24
+ minimize or maximize c^T x + k
25
+ subject to rl <= A x <= ru
26
+ cl <= x <= cu
27
+ ```
28
+
29
+ with `m` rows and `n` columns, the objective constant `k`, the costs `c`, the column bounds `cl`, `cu`, the row
30
+ bounds `rl`, `ru` and the matrix `A`. Every number is an IEEE 754 binary64 value ("double"); bounds may be `-inf`
31
+ or `+inf`; costs, coefficients and the constant are finite; no lower bound is `+inf`, no upper bound is `-inf`, and
32
+ nothing is NaN. A file that gives a cost, a coefficient or the constant that is not finite, a NaN bound, a lower
33
+ bound `+inf` or an upper bound `-inf` is not a model: KOS and a verifier reject it. A lower bound above its upper
34
+ bound is allowed (the LP is then infeasible). A column may be integer (a MIP); the LP kinds of section 4 are for
35
+ models without integer columns.
36
+
37
+ The sense `σ` is `+1` when minimizing and `-1` when maximizing; the **minimizing form** of the objective is
38
+ `σ c^T x`.
39
+
40
+ ### 1.1 Reading the model files
41
+
42
+ A verifier reads the model from the same MPS or LP file that KOS read. KOS writes a model, also one loaded through
43
+ the API, to an MPS file that reads back with the same bits (`kos_write`, `Model.write`, `kos solve --write-model`),
44
+ except what MPS cannot hold: a finite number of magnitude `1e30` or more (it reads back as infinite), a row range that
45
+ no width gives exactly, a row with crossed bounds. KOS warns in those cases, and the LP format holds them. The meaning
46
+ of a file is the one below; any difference changes the fingerprint (section 2), so a verifier that reads a file
47
+ differently rejects the certificate instead of checking it against another model.
48
+
49
+ Common to both formats:
50
+ - The file is decoded as UTF-8 with each invalid byte sequence replaced by U+FFFD (Python's
51
+ `bytes.decode("utf-8", errors="replace")`, Rust's `String::from_utf8_lossy`): only names can hold such bytes, and
52
+ names are not part of the model. A byte order mark is not removed: U+FEFF is then the first character of the first
53
+ line, which makes the file invalid in both formats. Lines end at `\n` (a `\r` just before it is removed). Blanks
54
+ are the Unicode `White_Space` characters.
55
+ - A number follows the grammar `[+-]? ( digits [. digits?] | . digits ) ( [eE] [+-]? digits )?` or `inf` /
56
+ `infinity` (any case, with an optional sign), with ASCII digits; its value is the double nearest to the decimal
57
+ (round half to even), `±inf` past the range.
58
+ - A bound with magnitude `>= 1e30` is infinite.
59
+ - Columns are numbered in the order they first appear; rows in their order.
60
+
61
+ **MPS** (free or fixed format). A file is read in free format. If reading its lines fails (an error of the format:
62
+ a section, a field, a name or a number that cannot be read, a missing section), it is read again in fixed format.
63
+ An error of the values of the model, found once all the lines are read (a cost, a coefficient or the constant that is
64
+ not finite, a NaN bound, a lower bound `+inf` or an upper bound `-inf`), is final: the file is not read as fixed.
65
+ - Sections: `NAME`, `OBJSENSE` (with `MIN`/`MINIMIZE`/`MINIMISE` or `MAX`/`MAXIMIZE`/`MAXIMISE`, on the same line or
66
+ the next), `OBJSENS`, `OBJNAME`, `ROWS`, `COLUMNS`, `RHS`, `RANGES`, `BOUNDS`, `ENDATA` (what follows it is
67
+ ignored). Section words and the sense are not case sensitive; an unknown section is an error. A section line
68
+ starts with a character other than a space or a tab; other lines are data. Lines that are blank or start with `*`
69
+ are skipped. With several `OBJSENSE` lines, the last one counts.
70
+ - In fixed format the fields are the characters 2-3, 5-12, 15-22, 25-36, 40-47 and 50-61 (blanks trimmed); in free
71
+ format, the blank-separated words, placed like the fixed fields by section: a ROWS line has 2 words; a COLUMNS
72
+ line 3 or 5; an RHS or RANGES line 2 to 5 (an even number of words means there is no set name); a BOUNDS line 2 to
73
+ 4 (with 3 words, the second is a set name if the type is `FR`, `MI` or `PL`, or `BV` with a third word that is a
74
+ column; with 2 words, the type must be one of those four).
75
+ - In numbers, `D` and `d` mean `E`. Every number read (also costs, coefficients, right-hand sides and ranges) with
76
+ magnitude `>= 1e30` becomes `±inf`.
77
+ - The first `N` row is the objective, or the one named by an `OBJNAME` that comes before `ROWS`; the other `N` rows
78
+ are dropped with their coefficients, right-hand sides and ranges. An `OBJNAME` that names no `N` row is an error
79
+ (it would leave the objective at zero); one that comes after `ROWS` does not change the objective. Row names are
80
+ unique; a row or a column name in COLUMNS, RHS, RANGES or BOUNDS that is not defined is an error (a column is
81
+ defined by its first COLUMNS line).
82
+ - In COLUMNS, a third field `MARKER` (quotes ignored, any case) with `INTORG`/`INTEND` in the fifth (or fourth) field
83
+ opens or closes integer columns. A coefficient of the objective row is the cost; a repeated (row, column) pair or a
84
+ repeated cost is an error; zero coefficients are dropped.
85
+ - RHS: the right-hand side of the objective row is `-k`. RHS, RANGES and BOUNDS read only the first set name they
86
+ see (lines of other sets are ignored); the last value given to a row wins.
87
+ - Row bounds from the type, the right-hand side `b` (0 if not given) and the range `R`: `E` gives `[b, b]`, or
88
+ `[b, b + R]` if `R >= 0` and `[b + R, b]` if `R < 0`; `L` gives `[-inf, b]`, or `[b - |R|, b]`; `G` gives
89
+ `[b, +inf]`, or `[b, b + |R|]` (sums in double precision, rounded to nearest).
90
+ - Columns start in `[0, +inf]`. The BOUNDS lines apply in order: `UP` (and `UI`) sets the upper bound, and if the
91
+ value is negative and the lower bound is then 0, the lower bound becomes `-inf`; `LO` (and `LI`) the lower; `FX`
92
+ both; `FR` `[-inf, +inf]`; `MI` the lower to `-inf`; `PL` the upper to `+inf`; `BV` `[0, 1]`. So the order matters:
93
+ `UP x -1` then `LO x 0` gives `[0, -1]`; `LO x 0` then `UP x -1` gives `[-inf, -1]`.
94
+ - Integer columns: those between the markers and those with a `BV`, `LI` or `UI` bound. An integer column of the
95
+ markers with no BOUNDS line at all (of any type) has the bounds `[0, 1]`.
96
+
97
+ **LP** (the algebraic `.lp` format):
98
+ - Comments run from `\` to the end of the line. Sections start with a keyword that is the first word of a line
99
+ (after any blanks, any case), and the rest of the line belongs to the section:
100
+ `minimize`/`minimise`/`minimum`/`min` or `maximize`/`maximise`/`maximum`/`max` (the objective; a line that starts
101
+ with `max` maximizes); `subject to`, `such that`, `st`, `s.t.`, `st.` (constraints); `bounds`, `bound`;
102
+ `general`, `generals`, `gen`, `integer`, `integers`; `binary`, `binaries`, `bin`; `end` (what follows it is
103
+ ignored). A keyword followed by `:` is a name, not a section. Semi-continuous variables, SOS, lazy constraints,
104
+ user cuts, quadratic terms and indicators are errors.
105
+ - Names start with an ASCII letter or one of ``!"#$%&()/,;?@_`'{}|~`` and go on with those, ASCII digits, `.`,
106
+ `[` and `]`.
107
+ - An expression is a sum of terms `[signs] [number] [*] name` or `[signs] number`, where several signs may come in a
108
+ row (`+ -3 x` is `-3 x`); repeated terms of a column are added in order, in double precision; constant terms are
109
+ added in order and moved to the right-hand side (`rhs − constant` in double precision); the objective constant is
110
+ `k`. `inf` and `infinity` are always numbers, never names; an infinite coefficient is an error.
111
+ - A constraint is `[name:] expression op number` or `[name:] number op expression op number` (a range: both `<=` or
112
+ both `>=`; `5 >= x + y >= 1` is the row `[1, 5]`), with `op` one of `<=`, `=<`, `<` (all `<=`), `>=`, `=>`, `>`
113
+ (all `>=`), `=`, `==`. `number op expression` alone (`3 >= x`) and `expression op expression` are errors. A row
114
+ without a name is called `R<i>`.
115
+ - Bounds: `x free`, `x op v`, `v op x`, `v op x op w`; `<=` on the column's right is its upper bound, `>=` its lower
116
+ bound and `=` both. Columns start in `[0, +inf]`; unlike MPS, a negative upper bound does not touch the lower bound
117
+ (`x <= -3` gives `[0, -3]`, crossed). Generals and binaries make the column integer; a binary column then has the
118
+ bounds `[max(l, 0), min(u, 1)]` from the bounds `[l, u]` it had.
119
+
120
+ ### 1.2 What is not part of the model
121
+
122
+ Names (other than to resolve the file), the problem name and warnings are not part of the model; the order of the
123
+ lines matters only as said above (the last value given to a row wins; the BOUNDS lines apply in order). Two files with
124
+ the same model have the same fingerprint.
125
+
126
+ ## 2. The fingerprint
127
+
128
+ The fingerprint identifies the model: the SHA-256 (FIPS 180-4) of this byte string, written as `sha256:` and 64
129
+ lowercase hexadecimal digits. Integers are unsigned 64-bit little endian; doubles are IEEE 754 binary64 little
130
+ endian, with `-0.0` written as `+0.0` and infinities as themselves.
131
+
132
+ 1. the 12 ASCII bytes `KOS-MODEL-1\n`;
133
+ 2. `m`, `n` and the number of nonzeros of `A` (integers);
134
+ 3. one byte: 0 if minimizing, 1 if maximizing;
135
+ 4. `k` (double);
136
+ 5. for each column `j`: `c_j`, `cl_j`, `cu_j` (doubles) and one byte, 1 if the column is integer and 0 if not;
137
+ 6. for each row `i`: `rl_i`, `ru_i` (doubles);
138
+ 7. for each column `j`: its number of nonzeros (integer) and, for each nonzero in increasing row order, its row
139
+ (integer) and its value (double). Zeros are not stored.
140
+
141
+ ## 3. The certificate file
142
+
143
+ A JSON object in UTF-8, without a byte order mark (invalid UTF-8 is rejected). A verifier rejects a certificate with
144
+ duplicate keys (at any depth), with keys not listed here or not allowed for its kind (a `ray` in an `optimal`), with the
145
+ constants `NaN`, `Infinity` or `-Infinity` anywhere, or with a missing required key. `format`, `version`, `kind` and
146
+ `model` are required in every certificate, and each kind requires its own keys (section 4); `solver` is optional and
147
+ may hold anything (it is never read) except duplicate keys and those constants. `version`, `rows` and `cols` are JSON
148
+ integers written without a fraction or an exponent (`1`, not `1.0` or `1e0`).
149
+
150
+ | key | value |
151
+ |---|---|
152
+ | `format` | `"kos-certificate"` |
153
+ | `version` | the integer `1` |
154
+ | `kind` | `"optimal"`, `"infeasible"`, `"unbounded"` or `"bound"` (section 4) |
155
+ | `model` | an object with exactly `problem` (`"lp"`), `fingerprint` (`"sha256:..."`), `rows` (`m`), `cols` (`n`) and `sense` (`"minimize"` or `"maximize"`) |
156
+ | `objective` | a number: the objective claimed (with the constant, in the sense of the model) |
157
+ | `bound` | a number: the bound claimed |
158
+ | `primal` | an array of `n` numbers: a point `x` |
159
+ | `dual` | an array of `m` numbers: duals `y` (or Farkas multipliers) |
160
+ | `ray` | an array of `n` numbers: a direction `r` |
161
+ | `solver` | an object with what the solver reports (KOS: `name`, `version`, `status`); never read by a verifier |
162
+
163
+ **Numbers.** A number is either
164
+ - a JSON number: its value is the double nearest to the decimal (round half to even); it must be finite (a decimal
165
+ beyond the double range is rejected); or
166
+ - a JSON string with an exact rational, the whole string matching the regular expression
167
+ `-?(0x[0-9a-fA-F]+|[0-9]+)(/(0x[0-9a-fA-F]+|[0-9]+))?`: `p`, `p/q`, `-p` or `-p/q` with `p` and `q` written in decimal
168
+ or in hexadecimal with the prefix `0x` (lowercase `x`; the hexadecimal digits in either case; leading zeros allowed;
169
+ `p` and `q` may use different bases; no `+`, no blanks, no other digits). `q` must not be zero. Its value is exactly
170
+ `p/q`.
171
+
172
+ KOS writes doubles (the shortest decimal that reads back as the same double) and exact rationals only where doubles
173
+ are not enough (section 6).
174
+
175
+ ## 4. The kinds and what they prove
176
+
177
+ Notation: `d = c − A^T y` (the reduced costs, with the `c` of the model), and in the minimizing form `c' = σc`,
178
+ `y' = σy`, `d' = c' − A^T y' = σd`, `z' = σ(z − k)` for an objective value `z`.
179
+
180
+ **The safe dual bound.** For any `y`, every feasible `x` satisfies
181
+ `σ c^T x = d'^T x + y'^T (A x) >= L(y) = Σ_i min_{r ∈ R_i} y'_i r + Σ_j min_{t ∈ X_j} d'_j t`, where `R_i` is a set
182
+ that contains `a_i x` for every feasible `x` (the row bounds `[rl_i, ru_i]`) and `X_j` one that contains `x_j` (the
183
+ column bounds). A term with a zero coefficient is 0; a term whose coefficient asks for an infinite bound makes
184
+ `L(y) = −inf`. This is the bound of A. Neumaier and O. Shcherbina, "Safe bounds in linear and mixed-integer linear
185
+ programming", Math. Programming 99 (2004) 283–296. A verifier may use, wherever the bound that the sign asks for is
186
+ infinite, any bound implied by the model for every feasible point (section 5).
187
+
188
+ ### `optimal`
189
+
190
+ Required: `objective` (`z`), `primal` (`x`), `dual` (`y`). It claims that `z` is the optimum within the verifier's
191
+ tolerances:
192
+ - **dual side:** the optimum of the LP is not better than `z` by more than `g = τ_g (1 + |z|)`: every feasible `x'`
193
+ has `σ (c^T x' + k) >= σ z − g`. It is proven by `y` when `L(y) >= z' − g` (or by the objective cut, section 5).
194
+ And the claim is not contradicted by that proof: when `y` proves `L(y)` (without the cut), `L(y) <= z' + g` (the
195
+ duals must not prove that the optimum is worse than `z` by more than `g`).
196
+ - **primal side:** `x` violates no bound by more than `τ_p (1 + |b|)` (for each violated bound `b`, of a column or
197
+ of a row, and both bounds of a column or row whose bounds are crossed) and `σ (c^T x + k) <= σ z + g`.
198
+
199
+ With a point that satisfies every bound exactly, the two sides prove that the optimum lies in `[z − g, z + g]` and,
200
+ more precisely, in the exact interval between `σL(y) + k` and `c^T x + k`. With a point that violates a bound by `δ`,
201
+ the dual side holds exactly (every feasible point has objective at least `σL(y) + k` when minimizing, which is within
202
+ `g` of `z`), and the primal side holds for the LP with its bounds relaxed by `δ`.
203
+
204
+ ### `infeasible`
205
+
206
+ Required: `dual` (`y`, Farkas multipliers). It claims that no `x` satisfies the bounds. It is proven when
207
+ `F(y) = Σ_j min_{t ∈ X_j} (A^T y)_j t − Σ_i max_{r ∈ R_i} y_i r > 0`, or trivially when a column or a row has its lower
208
+ bound above its upper bound. (`F(y)` is the dual bound of the zero objective with multipliers `−y`: if a feasible
209
+ `x` existed, `y^T A x` would be at least the first sum and at most the second.)
210
+
211
+ ### `unbounded`
212
+
213
+ Required: `ray` (`r`); optional: `primal` (`x`). It claims that the LP has no finite optimum. It is proven when, in
214
+ exact arithmetic, `r_j > 0` only for columns with `cu_j = +inf`, `r_j < 0` only for columns with `cl_j = −inf`,
215
+ `(A r)_i > 0` only for rows with `ru_i = +inf`, `(A r)_i < 0` only for rows with `rl_i = −inf`, and `σ c^T r < 0`. Then
216
+ the LP is infeasible or unbounded (it is dual infeasible). With `primal`, the point must violate no bound by more
217
+ than `τ_p (1 + |b|)`: the LP (relaxed by the point's violation, if any) is unbounded.
218
+
219
+ ### `bound`
220
+
221
+ Required: `dual` (`y`); optional: `bound` (`b`), `primal` (`x`). It claims that the optimum is not better than `b`
222
+ (not below it when minimizing, not above it when maximizing). It is proven when `L(y) >= σ (b − k)` (or by the
223
+ objective cut). Without `bound` it claims only that `L(y)` is finite, and the verifier reports `σ L(y) + k`. The point,
224
+ if any, is the solver's (a flagged optimum, the iterate at a limit) and is only measured and reported.
225
+
226
+ KOS writes `optimal` for an optimal LP, `infeasible` for a primal infeasible one, `unbounded` for a dual infeasible one
227
+ (with the point if it is within the primal tolerance) and `bound` for a flagged optimum, a limit (iterations, time,
228
+ work, objective) or a solve without a verdict.
229
+
230
+ ## 5. What a verifier checks
231
+
232
+ 1. Read the model (section 1.1) and compute its fingerprint (section 2). The kinds of section 4 are for models without
233
+ integer columns; a verifier that knows no kind for a MIP rejects every certificate of one (kos-verify exits with 3).
234
+ 2. Read the certificate (section 3): format, version, kind, keys, numbers, lengths.
235
+ 3. Compare `model.rows`, `model.cols`, `model.sense` and `model.fingerprint` with the model. Any difference rejects the
236
+ certificate.
237
+ 4. Check the claims of its kind (section 4) in exact rational arithmetic: every double is a dyadic rational, so sums
238
+ and products are exact; no rounding is allowed anywhere in a proof.
239
+
240
+ **Tolerances.** `τ_p` (primal tolerance) and `τ_g` (gap tolerance) are the verifier's, not the certificate's. They are
241
+ exact rationals: `1e-6` means `10^-6` exactly, not the double nearest to it. kos-verify uses `1e-6` for both by
242
+ default (`--primal-tolerance`, `--gap-tolerance`); with `0` it accepts only exact points and exact gaps.
243
+
244
+ **What every verifier accepts.** Implied bounds and the objective cut (below) are optional, so two sound verifiers may
245
+ differ on a certificate that needs them. A certificate whose claim is proven with the bounds of the columns and rows
246
+ alone (no implied bounds, no cut) is accepted by every conforming verifier with tolerances at least those used; it is
247
+ what KOS checks before writing a certificate (section 6). A `bound` without a claimed bound only needs a finite dual
248
+ bound, which may depend on the implied bounds of the verifier.
249
+
250
+ **Implied bounds.** A verifier may replace an infinite bound by any bound that every feasible point satisfies.
251
+ kos-verify derives them by propagation over the rows: a row `i` with bounds `[rl_i, ru_i]` gives, for a column `j` with
252
+ `a = a_ij`, `a x_j = a_i x − Σ_{k≠j} a_ik x_k`, so `x_j` is bounded by the row bound and the extreme activity of the
253
+ other columns (`Σ_{k≠j} min(a_ik l_k, a_ik u_k)` or the `max`) when all of them are finite. Each infinite side takes the
254
+ first finite bound a row gives (rounded outwards to a double) and propagates; then each column takes the best bound
255
+ of its rows. The activity of a row is bounded the same way by the bounds of its columns.
256
+
257
+ **The objective cut.** To prove that no feasible point is better than a value `v` (minimizing form: `σ c^T x >= v`),
258
+ a verifier may assume the contrary: a feasible `x` with `σ c^T x < v` satisfies the extra row `σ c^T x <= v`, so the
259
+ bounds implied with that row also hold for it; if `L(y) >= v` with those bounds, no such `x` exists. kos-verify uses
260
+ the cut when the plain bound does not reach the claim (`optimal`: `v = z' − g`; `bound`: `v = σ (b − k)`).
261
+
262
+ **Soundness.** A verifier must never accept a certificate whose claim is false. The claims are about the model as
263
+ read in section 1.1, with the stated tolerances; everything else (the solver, its status, its other numbers) is
264
+ information.
265
+
266
+ ## 6. How KOS writes certificates
267
+
268
+ - The point is the solution with each column moved into its bounds; the duals are the duals of the solve.
269
+ - An infeasible LP with a column or a row whose bounds are crossed gets an `infeasible` certificate with zero
270
+ multipliers (the claim is proven trivially).
271
+ - KOS checks its own numbers in exact arithmetic before writing them, with the bounds of the columns and rows only
272
+ (what it accepts, the verifier accepts): the duals must prove the objective minus KOS's gap (`dual_tolerance (1 +
273
+ |z|)`), the point must satisfy every bound within `1e-9 (1 + |bound|)`, the Farkas multipliers must give a
274
+ positive bound and the ray must be a ray.
275
+ - Duals in double whose reduced costs have, on some columns, the sign that asks for an infinite bound, or one of 1e20
276
+ or more, which many modelers write for infinity (the rounding noise of a reduced cost that is 0 in exact arithmetic,
277
+ or one within the dual tolerance), are **corrected exactly**: those columns (and, from the start, the columns with
278
+ an infinite bound and a reduced cost near 0) are zeroed at once by moving the duals on as many independent rows,
279
+ solving that system in exact arithmetic, within a work budget proportional to the size of the LP (the parameter
280
+ `certificate_work_limit`, per entry of the LP, plus a fixed minimum; `0` turns the correction off; an interrupt
281
+ request stops it); the corrected duals are exact rationals on those rows only, sharing a few denominators. The same
282
+ for Farkas multipliers.
283
+ - Otherwise KOS computes the basis in exact arithmetic (when its numbers fit in a budget) and writes its exact duals
284
+ and, if the basis is optimal, its exact point: those certificates prove an exact interval of width 0. The same for
285
+ an exact Farkas certificate or an exact ray of the basis.
286
+ - Large LPs whose exact numbers do not fit (for example, with 100,000-bit numbers) keep doubles or the exact
287
+ correction.
288
+ - If its numbers do not pass that exact check (the correction did not fit in its budget, the exact basis did not
289
+ fit), KOS still writes the certificate with the numbers it has, and says so: `certificate self check: failed` in
290
+ the summary of `kos solve` and `"certificate_self_check": "failed"` in its report (a verifier will probably reject
291
+ it; a larger `certificate_work_limit` may help).
292
+ - Writing a certificate only reads what the solve left (and computes the exact numbers on demand); it does not change
293
+ the solve, and without `--certificate` nothing is computed.
294
+
295
+ ## 7. kos-verify
296
+
297
+ ```
298
+ kos-verify MODEL CERTIFICATE [--format auto|mps|lp] [--primal-tolerance T] [--gap-tolerance T]
299
+ [--report FILE] [--quiet] [--version]
300
+ ```
301
+
302
+ `kos_verify.py` is one Python file (3.9 or later) with only the standard library: its own MPS and LP readers, its own
303
+ SHA-256 (from `hashlib`), and exact arithmetic with Python integers and `fractions.Fraction`. It prints what it proves
304
+ and a final line `kos-verify: PROVEN (…)` or `kos-verify: REJECTED: reason`. The parenthesis says which tolerances
305
+ the proof used: `(exact)` when none (an infeasibility, a ray without a point or with an exact point, a bound),
306
+ `(gap 1e-06)` for an optimum with an exact point, `(primal 1e-06, gap 1e-06)` for an optimum with a point within the
307
+ primal tolerance, `(primal 1e-06)` for a ray with such a point.
308
+
309
+ Exit status: `0` proven; `1` rejected (also a malformed certificate, or one of another model); `2` a usage error; `3`
310
+ the model cannot be read or has integer columns (a MIP, whose kinds this kos-verify does not know); `4` an internal
311
+ error of the verifier. Only `0` means proven.
312
+
313
+ The JSON report (`--report`) has `kos_verify_version`, `format_version`, `model`, `certificate`, `fingerprint`,
314
+ `rows`, `cols`, `sense`, `kind`, `verdict` (`proven`, `rejected` or `error`), `reasons` (when not proven) and
315
+ `results`: `dual_bound` (rounded towards the side it bounds), `dual_bound_by_cut`, `primal_objective`,
316
+ `primal_violation` and `primal_violation_relative` (rounded up), `objective`, `gap_below` and `gap_above` (relative to
317
+ `1 + |z|`, rounded up), `exact_interval`, `claimed_bound`, `farkas_bound`, `ray_slope`, `primal_tolerance` and
318
+ `gap_tolerance`, as they apply; and, when proven, `tolerances_used` (the tolerances the proof used, empty when exact).
319
+ Numbers are decimals with 17 significant digits, rounded in the direction that keeps the statement true.
320
+
321
+ ## 8. Versions
322
+
323
+ `version` changes only for a change that breaks: a change of what an existing kind, key or number means. New kinds
324
+ (the MIP certificates, with `model.problem = "mip"`) and new keys are added within version 1. A verifier rejects a
325
+ version it does not know, and a kind, a problem or a key it does not know: an older verifier rejects what it cannot
326
+ check, never accepts it.
327
+
328
+ ## 9. Example
329
+
330
+ ```json
331
+ {
332
+ "format": "kos-certificate",
333
+ "version": 1,
334
+ "kind": "optimal",
335
+ "model": {"problem": "lp", "fingerprint": "sha256:0884eb008089f481e1873356b2cf97464bef7be7729ae7b613db9f06fa29c92f", "rows": 27, "cols": 32, "sense": "minimize"},
336
+ "objective": -464.75314285714285,
337
+ "primal": [79.99999999999996, 25.499999999999954, 54.5, ...],
338
+ "dual": [-0.6285714285714286, 0, ...],
339
+ "solver": {"name": "KOS", "version": "1.0.0", "status": "optimal"}
340
+ }
341
+ ```
342
+
343
+ ```
344
+ $ kos solve afiro.mps --certificate afiro.json
345
+ $ kos-verify afiro.mps afiro.json
346
+ model: afiro.mps (27 rows, 32 columns, minimize; fingerprint sha256:0884eb00...)
347
+ certificate: afiro.json (kind optimal, from KOS 1.0.0 (status optimal))
348
+ the optimum of the LP is >= -4.6475314285714287e+02 (the safe dual bound of the duals, exact)
349
+ the point violates the bounds by at most 1.2954615158378147e-13 (...); its objective is -4.6475314285714284e+02
350
+ so every feasible point has objective >= -4.6475314285714287e+02, and the point, ... : the objective ... is within
351
+ 1e-06 (1 + |z|) of that bound, and the point's objective is not worse than it by more than that
352
+ kos-verify: PROVEN (primal 1e-06, gap 1e-06)
353
+ ```
354
+
355
+ ## 10. Conformance vectors
356
+
357
+ `kos-verify/conformidad/` holds small models and certificates for anyone who writes a reader or a verifier, listed in
358
+ `kos-verify/conformidad/vectores.json`:
359
+ - `models`: each model file (MPS free and fixed, LP; ranges, the negative `UP` rule and the order of the BOUNDS
360
+ lines, `OBJSENSE`, `OBJNAME`, constants, crossed bounds, finite bounds below `1e30` and infinite ones from it,
361
+ binaries and integer markers, names that are not UTF-8) with its dimensions, sense and fingerprint. KOS reads each to
362
+ the same fingerprint (a test of the KOS repository checks it), and kos-verify too.
363
+ - `unreadable`: files that are not models (an infinite constant, in MPS and from LP constants whose sum overflows; a
364
+ free file with a cost of `1e400` that fixed format would misread; an `OBJNAME` that names no `N` row; a byte order
365
+ mark; an infinite LP coefficient): KOS and kos-verify reject them.
366
+ - `certificates`: certificates of those models with the verdict a sound verifier gives with the default tolerances
367
+ (`proven` or `rejected`), the tolerances kos-verify reports, and why: each kind proven and rejected, a point between
368
+ crossed bounds, an objective that its own dual bound contradicts, exact rationals, a Farkas certificate and the
369
+ trivial one of crossed bounds, rays, bounds, and malformed certificates (duplicate keys, a key of another kind,
370
+ `1.0` for a version, `0X1`, `+1`, a zero denominator, another fingerprint). A certificate marked `proven` uses no
371
+ implied bounds and no cut, so every conforming verifier accepts it (section 5).
@@ -0,0 +1,97 @@
1
+ Metadata-Version: 2.4
2
+ Name: kos-verify
3
+ Version: 1.0.0b1
4
+ Summary: Independent exact-arithmetic checker for KOS linear programming certificates
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: linear programming,LP,certificate,verification,exact arithmetic,KOS
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Environment :: Console
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Programming Language :: Python :: 3.14
23
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
24
+ Requires-Python: >=3.9
25
+ Description-Content-Type: text/markdown
26
+ License-File: LICENSE
27
+ Dynamic: license-file
28
+
29
+ # kos-verify
30
+
31
+ An independent checker, in exact arithmetic, for the certificates that KOS (the Katsenia Optimization Solver) writes
32
+ for **linear programs (LP)**.
33
+
34
+ After solving an LP, KOS can write a certificate: a JSON file in the open `kos-certificate` format (version 1) that
35
+ says what the solve proves about the model and carries the numbers that prove it. kos-verify reads the model file
36
+ with its own MPS and LP readers, checks that the certificate belongs to that model (by a fingerprint it computes
37
+ itself) and checks every claim in exact rational arithmetic. It shares no code with KOS and does not trust its
38
+ numbers: the point, the duals and the ray are data, and what they prove is derived here from them and from the model.
39
+
40
+ What each kind of LP certificate proves:
41
+
42
+ - `optimal`: the objective of the optimum, within a stated tolerance from both sides (a point that satisfies the
43
+ constraints within the primal tolerance, and duals whose rigorous bound closes the gap);
44
+ - `infeasible`: Farkas multipliers that prove the LP has no feasible point;
45
+ - `unbounded`: a ray (and possibly a point) that proves the LP has no finite optimum;
46
+ - `bound`: duals that prove a bound on the objective, when the solve did not prove an optimum.
47
+
48
+ kos-verify checks certificates of linear programs only. A model with integer columns (a MIP) exits with status 3:
49
+ MIP certificates are not part of this version.
50
+
51
+ ## Installation
52
+
53
+ ```
54
+ pip install --pre kos-verify
55
+ ```
56
+
57
+ Python 3.9 or newer, standard library only (no dependencies). The package installs the `kos-verify` command and the
58
+ `kos_verify` module.
59
+
60
+ ## Usage
61
+
62
+ Solve an LP with KOS and write its certificate, for example from Python with the `kos-solver` package (`import kos`):
63
+
64
+ ```python
65
+ import kos
66
+
67
+ m = kos.Model.read("model.mps")
68
+ m.solve()
69
+ m.write_certificate("model.cert.json")
70
+ ```
71
+
72
+ (or `kos solve model.mps --certificate model.cert.json` from the KOS command line), then check it:
73
+
74
+ ```
75
+ kos-verify model.mps model.cert.json
76
+ ```
77
+
78
+ ```
79
+ kos-verify MODEL CERTIFICATE [--format auto|mps|lp] [--primal-tolerance T] [--gap-tolerance T]
80
+ [--report FILE] [--quiet] [--version]
81
+ ```
82
+
83
+ It prints `kos-verify: PROVEN (...)`, with the tolerances the proof used, or `kos-verify: REJECTED: reason`.
84
+ `--report FILE` writes a JSON report. Exit status: 0 proven, 1 rejected (also a malformed certificate or one of
85
+ another model), 2 a usage error, 3 the model cannot be read or is not an LP, 4 an internal error. Only 0 means proven.
86
+
87
+ ## The format
88
+
89
+ The `kos-certificate` format, version 1, is specified in `CERTIFICADO.md`: the model and how the files are read, the
90
+ fingerprint, the certificate file, what each kind proves and what a verifier checks, precisely enough to write
91
+ another verifier. The specification is included in the source distribution and installed with the package in
92
+ `share/doc/kos-verify/CERTIFICADO.md` (under the Python prefix, for example the virtual environment).
93
+
94
+ ## License
95
+
96
+ kos-verify is licensed under the Apache License, Version 2.0 (see LICENSE). KOS itself is proprietary software of
97
+ Katsenia SpA, distributed separately (the `kos-solver` package) under its own license. More: https://katsenia.com.
@@ -0,0 +1,8 @@
1
+ kos_verify.py,sha256=eulyssaSCwrv0L2xYwVQLn2JxCqen2W79GpMniuimU0,85249
2
+ kos_verify-1.0.0b1.data/data/share/doc/kos-verify/CERTIFICADO.md,sha256=xsCyQ32GBhKVQA2rtkE8cmYaBVgGoEyIvldDaO29e6g,27447
3
+ kos_verify-1.0.0b1.dist-info/licenses/LICENSE,sha256=pg7qgXUUUxZo1-AHZXMUSf4U0FnTJJ4LyTs23kX3WfI,10847
4
+ kos_verify-1.0.0b1.dist-info/METADATA,sha256=8HuJ9vjWwfeREJM9zvgnl5JdosNZja79oaJAy0zEsns,4366
5
+ kos_verify-1.0.0b1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
6
+ kos_verify-1.0.0b1.dist-info/entry_points.txt,sha256=jTdNU8vYhZSEg7dzRy37IH_seHRMQVqRUCFpNo3VEwk,47
7
+ kos_verify-1.0.0b1.dist-info/top_level.txt,sha256=GMX1nwIqvlxqXjQEgf517VZ2b-WqkuRZJQglYh_pC0s,11
8
+ kos_verify-1.0.0b1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ kos-verify = kos_verify:main