Export¶
Exports the circuit of a Context as a JSON graph (a netlist),
for drawing it as a block diagram. The module docstring below is the
authoritative description of the JSON schema.
export ¶
Exports the circuit of a Context as a JSON graph (a netlist), so that it can be drawn as a block diagram — the intrepid-vscode extension is the first consumer, but the format is generic.
The structure comes from the context's recipe (intrepyd.recipe), the
record of the calls that built every net, which already holds each net's
operator and its fanin as references; names come from net2name and the
outputs from context.outputs. Nothing is read from the native library, so
the export is pure python and works wherever a built Context does.
JSON schema (version 2)¶
Version 2 adds file/line to a node; version 1 is the same without them,
and a reader should accept both. Version 3, written only for a circuit that has
them, adds two kinds of node: "assertion" (a property that must always
hold, named, its one input in the condition) and "assumption" (a
condition the inputs are constrained to at every step, from
push_assumption, named, its input in).
::
{
"version": 2,
"nodes": [
{
"id": <int>, # the net, unique in the graph; edges use it
"kind": "input" | "latch" | "const" | "gate" | "output" | "external",
"name": <str|null>, # the user's name, null if intrepyd made one up
"op": <str|null>, # for a gate: "and", "add", "ite", ...; for a
# boolean constant: "true"/"false"; else absent
"type": <str|null>, # "bool", "int8", ..., "int", "real", "float32"
# when known (input/latch/const), else absent
"value": <str>, # for a const: "0", "true", "?", ... (else absent)
"group": <str>, # the namespace of the name, e.g. "Counter" for
# "Counter.q" (else absent)
"scope": <str>, # the namespaces pushed when the net was made,
# joined by "/" (else absent): a Lustre
# node instance, say ("sat.1/max.2"), or
# a Simulink model's subsystem ("A/B")
"file": <str>, # the source file that built the net (else absent)
"line": <int>, # the line in "file" that built it (with "file")
"output": true, # present only when the net is tagged an output
"outputs": [<str>] # the names of the outputs it is, when known
# (a Simulink model's Outports; else absent)
}
],
"edges": [
{ "from": <int>, "to": <int>, "port": <str> }
# the net <from> feeds input port <port> of net <to>; ports are
# "init"/"next" for a latch, "if"/"then"/"else" for an ite, "in" for a
# unary operator, "a"/"b" for a binary one, else "in0", "in1", ...
]
}
A node is one net. Outputs are a flag on the net they tag, not separate nodes.
const covers numbers and the predefined true/false/undef (whose
value is "?"). A fanin that was built outside the context appears as an
external node with no detail, so the graph stays connected.
A Simulink model's graph also says the signals through the ports of its subsystems, for naming the pins of the subsystems the editors make of the scopes (absent when there are none)::
"ports": [
{ "scope": "A/B", "dir": "in" | "out", "number": <int>, "name": <str>, "net": <int> }
]
(a block of the model the translator computes with several gates is a
scope too, A/B/Lookup, its pins u, u1, ... and y)
and the signals a Goto block carries to a From block, by their tag: of another subsystem, or of its own, with the visibility "local" (absent when there are none)::
"tags": [
{ "goto": "A", "from": "C/D", "name": <str>, "net": <int> }
]
and the functions the translator abstracts (sin, cos, exp, ...: see intrepyd.simulink), each an input of the circuit standing for the function of its arguments (absent when there are none)::
"abstractions": [
{ "net": <int>, "function": "sin", "args": [<int>, ...] }
]
and the blocks of the model where they are drawn, for the editors to draw the circuit as the model is, each with the net it is when it is one gate, a constant or a latch, and the tag of a Goto or a From (absent when the model says no position)::
"blocks": [
{ "scope": "A/B", "name": <str>, "type": "Switch",
"position": [<left>, <top>, <right>, <bottom>], "net": <int>, "tag": <str> }
]
and the lines of the model as it draws them, between blocks of one subsystem: the output they leave and the input they enter, from 1, and the points they run through, from the source's port to the destination's (absent when the model says no position)::
"lines": [
{ "scope": "A/B", "src": <str>, "srcPort": <int>, "dst": <str>, "dstPort": <int>,
"points": [[<x>, <y>], ...] }
]
and the version of the translator that made it, for the editors to say when it is older than the features they show need::
"translator": "1.4.0"
If the program also builds a trace (a simulation or a counterexample), the graph carries it, so a viewer can overlay the values on the blocks over time::
"trace": {
"depth": <int>, # number of steps, 0..depth-1
"values": { "<net id>": ["v@0", "v@1", ...], ... } # watched nets only
}
The values are the strings the trace holds ("5", "T"/"F" for booleans, "?" for unknown). Only the nets the trace watches are present. The field is absent when the program builds no usable trace.
to_graph ¶
The circuit of context as a JSON-able dict following the schema above.
assertions (name -> net) are the properties to show as assertion nodes,
targets (name -> net) those to show as target nodes (reached when the
net is true); the assumptions the context was given (push_assumption) are
assumption nodes, named by assumption_names (net -> name) if it names
them.
trace_payload ¶
A trace's watched nets as {"depth": n, "values": {str(net): [v@0, ...]}},
to overlay a simulation or counterexample on the graph (see the schema). The
values are the strings the trace holds; only the watched nets are present.
lustre_graph ¶
The circuit of a Lustre file's top node, as a graph: its properties as assertion nodes, its assertions as assumption nodes. The encodings of int and real are to be given when the model uses them (none is chosen silently). Raises LustreError for a file that cannot be translated.
simulink_graph ¶
The circuit of a Simulink model, as a graph: its Assertion blocks and
Design Verifier objectives as target nodes (reached when they fail), its
assumptions as assumption nodes. real_type: "float" (single and
double as floats, exactly) or "real". Raises SimulinkError when the model
cannot be translated, or the translator is missing (see intrepyd.simulink).
main ¶
python -m intrepyd.export program.py [-o out.json]: run the program and
export the circuit of the context it builds (the one with the most nets, if
it builds several) to out.json or standard output. On a Lustre file
(model.lus [--node TOP] [--int T] [--real T]), the circuit of its top
node; --describe says what the file is (its nodes, whether it uses int
and real) instead. On a Simulink model (model.slx or model.mdl,
[--real real] [--mat FILE]...), its circuit, translated by the
Simulink translator.