kos-verify 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,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,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.