Equivalence checking¶
Two versions of a circuit — the first and its simplification, a design and
its restructuring into subsystems, a Lustre model and the circuit drawn from
it — should do the same. A test can show that they agree on the inputs it
tries; intrepyd.equivalence asks the engines whether they agree on every
input, at every step.
Comparing two circuits¶
The circuits are compared on their interface: the same inputs and the same
outputs, by name, of the same types. A side is a circuit diagram (a dict, or
the path of a *.icircuit, as the editors save them) or a
Circuit subclass, as
intrepyd.tools.translate_lustre and translate_simulink make them.
from intrepyd.equivalence import check_equivalence
if __name__ == "__main__": # the engines run in processes of their own
answer = check_equivalence("door.icircuit", "door-simplified.icircuit")
print(answer["verdict"])
for result in answer["results"]:
print(result["output"], result["verdict"], result.get("step"))
check_equivalence builds a miter: both circuits in one context, the
second on the first's inputs (matched by name) and under a namespace of its
own, and, for each pair of outputs, a target reached when they differ (their
exclusive or for booleans, their inequality for the other types). Each target
is checked on its own:
- same: the target is unreachable, the two outputs are equal at every step;
- differs: the target is reached; the answer has the step where they first differ and a witness: the inputs, step by step (an input the engine leaves free takes false, or 0), and both outputs along them;
- unknown: no engine answered within the timeout, or the depth.
The circuits are equivalent when every pair is the same, not equivalent when one differs, and unknown otherwise. The comparison is from the initial states of both circuits (sequential equivalence): their latches start at their initial values.
engine chooses one engine (bmc, kind, br, pdr) instead of the
portfolio of all of them, timeout the seconds for each pair of outputs,
depth the deepest depth of BMC and k-induction; certificates=True gives
each pair proved the same its proof certificate, as verify does.
Interfaces and assumptions¶
Circuits whose inputs or outputs differ (a name in one only, a type that
differs) are not compared: check_equivalence raises EquivalenceError
saying which. interface(circuit) gives a circuit's inputs and outputs with
their types, and interface_problems(first, second) what keeps two circuits
from being compared.
The assumptions of either circuit (its Assume blocks, a Lustre model's assertions) restrict the inputs of both: the circuits are compared only on the runs where every assumption holds. The answer lists them.
From the command line¶
python -m intrepyd.diagram equivalence first.icircuit second.icircuit \
[--engine pdr] [--timeout 30] [--depth 50] [--certificates]
prints the answer as JSON (- reads the first diagram from standard input);
a mismatch of the interfaces is an error, its reason on standard error.
equivalence - alone reads both diagrams and the options as one JSON object
from standard input, {"first": ..., "second": ..., "engine": "pdr",
"timeout": 30}: that is what the editors send.