cictikz

AI-driven TikZ circuit schematics

View the Project on GitHub wulffern/cictikz

The dialect, the IR, and the xschem bridge

The constrained TikZ dialect

Arbitrary TikZ cannot be parsed back into a circuit, so cictikz defines a dialect and refuses everything outside it — loudly, with a line number — rather than guessing. In dialect:

Element bipoles the library has no macro for — to[I], to[cI], to[V], to[L] and friends — are accepted and round-trip verbatim as bipole: instances. Out of dialect, deliberately: bipoles that do have a house macro (to[R], to[C], to[D] — use the macros), component node shapes (node[pnp]), the TikZ calc library, pgfplots, and figure-local multi-argument macros.

The IR

cictikz.schematic — plain dataclasses, JSON round-trip via to_dict/from_dict (unknown keys rejected):

{"name": "amp",
 "instances": [{"name": "M1", "symbol": "lvnmos", "pos": [0, 0],
                "args": ["M1", "$v_i$"],
                "conns": {"drain": "vo", "source": "vss", "gate": "vi"}}],
 "wires":  [{"points": [[0, 1.6], [0.8, 1.6]], "net": "vo"}],
 "ports":  [{"net": "vo", "pos": [0.8, 1.6], "direction": "out"}],
 "labels": [{"text": "$v_o$", "pos": [0.5, 2], "anchor": "west"}]}

Coordinates are figure units (\grid = 1.6), y up. infer_nets() derives connectivity from geometry with a union–find over coincident pins, wire endpoints and ports; ground/supply symbols name their whole net; net names fall back to net1, net2, ....

The round trip is exact: write → read → infer_nets → write reproduces the TikZ byte for byte.

The xschem bridge

Symbol metadata carries a verified xschem mapping — pin offsets measured from the installed .sym files, rotation semantics ((x,y) → (-y,x) per step, flip mirrors x first) checked against xschem’s own headless netlister:

Headless verification recipe:

cat > rc.tcl <<'EOF'
set XSCHEM_LIBRARY_PATH /path/to/xschem_library:/path/to/sky130
EOF
xschem --rcfile rc.tcl --netlist --quit --no_x -o out mysch.sch

(The library path must be set in the rc file; the environment variable alone is not honoured.)