Metadata-Version: 2.4
Name: kos-verify
Version: 1.0.0b1
Summary: Independent exact-arithmetic checker for KOS linear programming certificates
Author-email: Katsenia SpA <support@katsenia.com>
License-Expression: Apache-2.0
Project-URL: Homepage, https://katsenia.com
Project-URL: Documentation, https://katsenia.com/help.html
Keywords: linear programming,LP,certificate,verification,exact arithmetic,KOS
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Mathematics
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# kos-verify

An independent checker, in exact arithmetic, for the certificates that KOS (the Katsenia Optimization Solver) writes
for **linear programs (LP)**.

After solving an LP, KOS can write a certificate: a JSON file in the open `kos-certificate` format (version 1) that
says what the solve proves about the model and carries the numbers that prove it. kos-verify reads the model file
with its own MPS and LP readers, checks that the certificate belongs to that model (by a fingerprint it computes
itself) and checks every claim in exact rational arithmetic. It shares no code with KOS and does not trust its
numbers: the point, the duals and the ray are data, and what they prove is derived here from them and from the model.

What each kind of LP certificate proves:

- `optimal`: the objective of the optimum, within a stated tolerance from both sides (a point that satisfies the
  constraints within the primal tolerance, and duals whose rigorous bound closes the gap);
- `infeasible`: Farkas multipliers that prove the LP has no feasible point;
- `unbounded`: a ray (and possibly a point) that proves the LP has no finite optimum;
- `bound`: duals that prove a bound on the objective, when the solve did not prove an optimum.

kos-verify checks certificates of linear programs only. A model with integer columns (a MIP) exits with status 3:
MIP certificates are not part of this version.

## Installation

```
pip install --pre kos-verify
```

Python 3.9 or newer, standard library only (no dependencies). The package installs the `kos-verify` command and the
`kos_verify` module.

## Usage

Solve an LP with KOS and write its certificate, for example from Python with the `kos-solver` package (`import kos`):

```python
import kos

m = kos.Model.read("model.mps")
m.solve()
m.write_certificate("model.cert.json")
```

(or `kos solve model.mps --certificate model.cert.json` from the KOS command line), then check it:

```
kos-verify model.mps model.cert.json
```

```
kos-verify MODEL CERTIFICATE [--format auto|mps|lp] [--primal-tolerance T] [--gap-tolerance T]
           [--report FILE] [--quiet] [--version]
```

It prints `kos-verify: PROVEN (...)`, with the tolerances the proof used, or `kos-verify: REJECTED: reason`.
`--report FILE` writes a JSON report. Exit status: 0 proven, 1 rejected (also a malformed certificate or one of
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.

## The format

The `kos-certificate` format, version 1, is specified in `CERTIFICADO.md`: the model and how the files are read, the
fingerprint, the certificate file, what each kind proves and what a verifier checks, precisely enough to write
another verifier. The specification is included in the source distribution and installed with the package in
`share/doc/kos-verify/CERTIFICADO.md` (under the Python prefix, for example the virtual environment).

## License

kos-verify is licensed under the Apache License, Version 2.0 (see LICENSE). KOS itself is proprietary software of
Katsenia SpA, distributed separately (the `kos-solver` package) under its own license. More: https://katsenia.com.
