Skip to content

Getting started

Install

$ pip install twindex            # checker and CLI only: no dependencies at all
$ pip install "twindex[search]"  # also the numerical search (adds numpy)

Twindex supports Python 3.10 to 3.13. If pip install twindex reports "from versions: none", your pip belongs to an older Python. Create an environment with a newer one, for example python3.11 -m venv .venv && .venv/bin/pip install twindex.

Check a certificate

$ twindex example regression_pair > pair.json
$ twindex check pair.json
$ twindex check pair.json --json --depth 10

twindex check accepts several files. Its exit code is 0 when every file is VALID, 1 when any file is INVALID, and 2 when any file is INCONCLUSIVE and none is INVALID.

Use the Python API

from fractions import Fraction
from twindex.model import Problem
from twindex.poly import Poly
from twindex.checker import check_witness, check_pair

x = Poly.x()
p = (x - x**2).scale(Fraction(1, 2))   # exact solution when theta = 0
sensors = [Fraction(i, 6) for i in range(1, 6)]
problem = Problem.build(sensors, [p(s) for s in sensors], "1/1000", [[0, 4]] * 4)

print(check_witness(problem, [4, 4, 4, 4], p).verdict)              # Verdict.VALID
print(check_pair(problem, ([0] * 4, p), ([4] * 4, p), 4).verdict)   # Verdict.VALID

Generate certificates

These commands need the search extra.

$ twindex search --output pair.json      # local twin search around theta = 500
$ twindex sivia pair.json --output paving.json --max-leaves 64

The search is a heuristic and the checker decides: every generated certificate is replayed exactly before it is written.