schematizer 0.2.0__tar.gz → 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. schematizer-0.3.0/PKG-INFO +439 -0
  2. schematizer-0.3.0/README.md +405 -0
  3. {schematizer-0.2.0 → schematizer-0.3.0}/pyproject.toml +21 -11
  4. schematizer-0.3.0/rust/.gitignore +1 -0
  5. schematizer-0.3.0/rust/Cargo.lock +355 -0
  6. schematizer-0.3.0/rust/Cargo.toml +31 -0
  7. schematizer-0.3.0/rust/src/engine/bboxes.rs +165 -0
  8. schematizer-0.3.0/rust/src/engine/constants.rs +9 -0
  9. schematizer-0.3.0/rust/src/engine/conventions.rs +162 -0
  10. schematizer-0.3.0/rust/src/engine/decisions.rs +430 -0
  11. schematizer-0.3.0/rust/src/engine/gen_schematic.rs +562 -0
  12. schematizer-0.3.0/rust/src/engine/kicad.rs +1558 -0
  13. schematizer-0.3.0/rust/src/engine/labels.rs +463 -0
  14. schematizer-0.3.0/rust/src/engine/layouts.rs +297 -0
  15. schematizer-0.3.0/rust/src/engine/mod.rs +204 -0
  16. schematizer-0.3.0/rust/src/engine/node.rs +378 -0
  17. schematizer-0.3.0/rust/src/engine/nudge.rs +302 -0
  18. schematizer-0.3.0/rust/src/engine/place.rs +1533 -0
  19. schematizer-0.3.0/rust/src/engine/preplace.rs +963 -0
  20. schematizer-0.3.0/rust/src/engine/progress.rs +106 -0
  21. schematizer-0.3.0/rust/src/engine/rng.rs +98 -0
  22. schematizer-0.3.0/rust/src/engine/route.rs +1901 -0
  23. schematizer-0.3.0/rust/src/engine/snap.rs +492 -0
  24. schematizer-0.3.0/rust/src/engine/svg.rs +622 -0
  25. schematizer-0.3.0/rust/src/geometry.rs +498 -0
  26. schematizer-0.3.0/rust/src/ir.rs +287 -0
  27. schematizer-0.3.0/rust/src/lib.rs +274 -0
  28. schematizer-0.3.0/rust/src/loader.rs +267 -0
  29. schematizer-0.3.0/rust/src/main.rs +255 -0
  30. schematizer-0.3.0/rust/src/netcheck.rs +214 -0
  31. schematizer-0.3.0/rust/src/python.rs +128 -0
  32. schematizer-0.3.0/rust/src/quality.rs +437 -0
  33. schematizer-0.3.0/rust/src/sexp.rs +382 -0
  34. schematizer-0.3.0/rust/src/uuid.rs +33 -0
  35. schematizer-0.3.0/rust/tests/end_to_end.rs +102 -0
  36. schematizer-0.3.0/rust/tests/unit.rs +81 -0
  37. {schematizer-0.2.0 → schematizer-0.3.0}/src/schematizer/__init__.py +3 -2
  38. schematizer-0.3.0/src/schematizer/cli.py +206 -0
  39. schematizer-0.3.0/src/schematizer/engine/conventions.py +213 -0
  40. {schematizer-0.2.0 → schematizer-0.3.0}/src/schematizer/engine/decisions.py +9 -1
  41. {schematizer-0.2.0 → schematizer-0.3.0}/src/schematizer/engine/gen_schematic.py +294 -129
  42. schematizer-0.3.0/src/schematizer/engine/layouts.py +335 -0
  43. schematizer-0.3.0/src/schematizer/engine/nudge.py +283 -0
  44. {schematizer-0.2.0 → schematizer-0.3.0}/src/schematizer/engine/place.py +1073 -168
  45. schematizer-0.3.0/src/schematizer/engine/preplace.py +833 -0
  46. schematizer-0.3.0/src/schematizer/engine/progress.py +88 -0
  47. schematizer-0.3.0/src/schematizer/engine/rng.py +35 -0
  48. {schematizer-0.2.0 → schematizer-0.3.0}/src/schematizer/engine/route.py +498 -123
  49. {schematizer-0.2.0 → schematizer-0.3.0}/src/schematizer/engine/sch_node.py +68 -9
  50. {schematizer-0.2.0 → schematizer-0.3.0}/src/schematizer/engine/sexp_schematic.py +762 -194
  51. {schematizer-0.2.0 → schematizer-0.3.0}/src/schematizer/engine/snap.py +2 -9
  52. {schematizer-0.2.0 → schematizer-0.3.0}/src/schematizer/engine/svg_draw.py +11 -4
  53. {schematizer-0.2.0 → schematizer-0.3.0}/src/schematizer/engine/svg_schematic.py +134 -129
  54. {schematizer-0.2.0 → schematizer-0.3.0}/src/schematizer/geometry.py +39 -15
  55. {schematizer-0.2.0 → schematizer-0.3.0}/src/schematizer/ir.py +11 -0
  56. {schematizer-0.2.0 → schematizer-0.3.0}/src/schematizer/loader.py +10 -0
  57. schematizer-0.3.0/src/schematizer/netcheck.py +162 -0
  58. schematizer-0.3.0/src/schematizer/quality.py +377 -0
  59. schematizer-0.3.0/src/schematizer/render.py +400 -0
  60. schematizer-0.2.0/PKG-INFO +0 -186
  61. schematizer-0.2.0/README.md +0 -153
  62. schematizer-0.2.0/setup.cfg +0 -4
  63. schematizer-0.2.0/src/schematizer/cli.py +0 -99
  64. schematizer-0.2.0/src/schematizer/render.py +0 -162
  65. schematizer-0.2.0/src/schematizer.egg-info/PKG-INFO +0 -186
  66. schematizer-0.2.0/src/schematizer.egg-info/SOURCES.txt +0 -38
  67. schematizer-0.2.0/src/schematizer.egg-info/dependency_links.txt +0 -1
  68. schematizer-0.2.0/src/schematizer.egg-info/entry_points.txt +0 -2
  69. schematizer-0.2.0/src/schematizer.egg-info/requires.txt +0 -4
  70. schematizer-0.2.0/src/schematizer.egg-info/top_level.txt +0 -1
  71. schematizer-0.2.0/tests/test_labels.py +0 -225
  72. schematizer-0.2.0/tests/test_render.py +0 -147
  73. schematizer-0.2.0/tests/test_svg.py +0 -214
  74. {schematizer-0.2.0 → schematizer-0.3.0}/LICENSE +0 -0
  75. {schematizer-0.2.0 → schematizer-0.3.0}/src/schematizer/_utils.py +0 -0
  76. {schematizer-0.2.0 → schematizer-0.3.0}/src/schematizer/data/power.kicad_sym +0 -0
  77. {schematizer-0.2.0 → schematizer-0.3.0}/src/schematizer/engine/__init__.py +0 -0
  78. {schematizer-0.2.0 → schematizer-0.3.0}/src/schematizer/engine/backend.py +0 -0
  79. {schematizer-0.2.0 → schematizer-0.3.0}/src/schematizer/engine/bboxes.py +0 -0
  80. {schematizer-0.2.0 → schematizer-0.3.0}/src/schematizer/engine/constants.py +0 -0
  81. {schematizer-0.2.0 → schematizer-0.3.0}/src/schematizer/engine/debug_draw.py +0 -0
  82. {schematizer-0.2.0 → schematizer-0.3.0}/src/schematizer/engine/kicad_backend.py +0 -0
  83. {schematizer-0.2.0 → schematizer-0.3.0}/src/schematizer/engine/labels.py +0 -0
  84. {schematizer-0.2.0 → schematizer-0.3.0}/src/schematizer/engine/net_terminal.py +0 -0
  85. {schematizer-0.2.0 → schematizer-0.3.0}/src/schematizer/engine/tool_module.py +0 -0
@@ -0,0 +1,439 @@
1
+ Metadata-Version: 2.4
2
+ Name: schematizer
3
+ Version: 0.3.0
4
+ Classifier: Development Status :: 3 - Alpha
5
+ Classifier: Intended Audience :: Developers
6
+ Classifier: Intended Audience :: Science/Research
7
+ Classifier: License :: OSI Approved :: MIT License
8
+ Classifier: Operating System :: OS Independent
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3 :: Only
11
+ Classifier: Programming Language :: Python :: 3.8
12
+ Classifier: Programming Language :: Python :: 3.9
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Topic :: Scientific/Engineering :: Electronic Design Automation (EDA)
19
+ Requires-Dist: numpy
20
+ Requires-Dist: simp-sexp
21
+ Requires-Dist: pytest ; extra == 'test'
22
+ Provides-Extra: test
23
+ License-File: LICENSE
24
+ Summary: Turn a generic hierarchical netlist (JSON) into a KiCad schematic.
25
+ Keywords: KiCad,schematic,netlist,EDA,SKiDL
26
+ Author-email: Dave Vandenbout <dave@vdb.name>
27
+ License: MIT
28
+ Requires-Python: >=3.8
29
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
30
+ Project-URL: Homepage, https://github.com/devbisme/schematizer
31
+ Project-URL: Issues, https://github.com/devbisme/schematizer/issues
32
+ Project-URL: Repository, https://github.com/devbisme/schematizer
33
+
34
+ ![PyPI Version](https://img.shields.io/pypi/v/schematizer.svg)
35
+ ![Python Versions](https://img.shields.io/pypi/pyversions/schematizer.svg)
36
+ ![License](https://img.shields.io/pypi/l/schematizer.svg)
37
+ ![Downloads](https://img.shields.io/pypi/dm/schematizer.svg)
38
+ ![GitHub Stars](https://img.shields.io/github/stars/devbisme/schematizer.svg?style=social)
39
+ ![GitHub Forks](https://img.shields.io/github/forks/devbisme/schematizer.svg?style=social)
40
+ ![GitHub Issues](https://img.shields.io/github/issues/devbisme/schematizer.svg)
41
+ ![GitHub Last Commit](https://img.shields.io/github/last-commit/devbisme/schematizer.svg)
42
+
43
+ # schematizer
44
+
45
+ By 2030, most electronic design won't be done with schematics.
46
+ Probably not even with SKiDL.
47
+ AI will handle it, going from natural language descriptions of systems
48
+ to netlists that specify the interconnections of components.
49
+
50
+ But people *will* still need to understand the system the AI has designed,
51
+ and schematics are the most natural way to do that.
52
+ And while a netlist tells you what's connected to what,
53
+ it doesn't tell you where anything goes on the page or how they are logically ordered.
54
+
55
+ `schematizer` does that work. You give it a **generic, hierarchical netlist** (a JSON
56
+ file) and it places the components, routes the wires and writes either editable
57
+ `.kicad_sch` files or static, cross-linked `.svg` pages.
58
+
59
+ It isn't tied to any particular front end. [SKiDL](https://github.com/devbisme/skidl)
60
+ is the first tool to feed it (SKiDL describes the electrical connections in code and
61
+ hands the netlist over), but the input is just JSON, so *anything* that emits the format
62
+ can use it.
63
+
64
+ The netlist (produced by `skidl.schematic_netlist.build_generic_netlist`, or whatever
65
+ you write that does the same job) carries each component's symbol definition inside it.
66
+ So this tool needs **no access to KiCad symbol libraries**. The netlist also carries a
67
+ few layout *hints*: how to mirror or rotate a component (`symtx`) and which nets to
68
+ stub (`stub`/`netio`).
69
+
70
+ ## Install
71
+
72
+ ```bash
73
+ pip install schematizer
74
+ ```
75
+
76
+ The package comes with a compiled engine (written in Rust) for Linux (x86-64 and ARM),
77
+ Windows and macOS, and Python 3.8 or later. It draws the same schematics as the Python
78
+ engine about ten times faster: the 169-part test board takes 0.6 seconds instead of 5.7
79
+ (both counting the half second KiCad needs to check the netlist).
80
+
81
+ `render()` uses the compiled engine whenever it's installed and understands all the
82
+ options it's given. Otherwise it quietly uses the Python engine, which is still in the
83
+ package. To pick one yourself, set `SCHEMATIZER_ENGINE` to `rust` or `python`.
84
+
85
+ If you don't use Python at all, there's also a standalone `schematizer` executable
86
+ (`schematizer.exe` on Windows) that takes the same options as the command below.
87
+
88
+ ## Command-line use
89
+
90
+ ```bash
91
+ # netlist.json -> KiCad 9 schematic files in ./out/
92
+ schematizer netlist.json --tool kicad9 -o out --top-name mydesign
93
+
94
+ # ...or a set of linked SVG pages instead
95
+ schematizer netlist.json --tool kicad9 -o out --top-name mydesign --format svg
96
+ ```
97
+
98
+ A big design can still take a while with the Python engine. So you're not left staring at a dead terminal, the command
99
+ shows which sheet it's placing or routing on a status line. `--no-progress` turns that
100
+ off, and `--progress` shows it even when the output is redirected.
101
+
102
+ ## Library use
103
+
104
+ ```python
105
+ import json
106
+ from schematizer import render
107
+
108
+ with open("netlist.json") as f:
109
+ netlist = json.load(f)
110
+
111
+ render(netlist, tool="kicad9", filepath="out", top_name="mydesign")
112
+ render(netlist, tool="kicad9", filepath="out", format="svg")
113
+ ```
114
+
115
+ You can also skip the `json.load()` and hand `render()` the path to the JSON file.
116
+
117
+ `render()` keeps quiet unless you ask. `progress=True` shows the same status line the
118
+ command does. Pass a function instead and it gets each message ("routing fpga") as a
119
+ string:
120
+
121
+ ```python
122
+ render(netlist, filepath="out", progress=True)
123
+ render(netlist, filepath="out", progress=lambda msg: print(msg))
124
+ ```
125
+
126
+ ## How it fits with SKiDL
127
+
128
+ If you use SKiDL, nothing changes. `Circuit.generate_schematic()` and
129
+ `Circuit.generate_svg()` build the generic netlist internally and call `render()`
130
+ (with `format="kicad"` and `format="svg"`, respectively).
131
+
132
+ ## Status
133
+
134
+ **Self-contained.** The placement/routing/writer engine is in
135
+ `schematizer/engine`. The netlist is rebuilt into a lightweight intermediate
136
+ representation (`schematizer.ir`: `SchPart`/`SchPin`/`SchNet`) that the engine consumes
137
+ directly. That means no `.kicad_sym` re-parse, no KiCad library access, and **no runtime
138
+ dependency on SKiDL**.
139
+ The KiCad power-symbol library (for `GND` and the supply rails) is kept in `schematizer/data`.
140
+
141
+ The compiled engine is a port of the Python one, in `rust/`. It reads the same netlist
142
+ JSON, takes the same options and writes the same files, and it's built into the package
143
+ as `schematizer._engine`.
144
+
145
+ ## Output formats
146
+
147
+ `--format kicad` (the default) writes editable `.kicad_sch` files. `--format svg`
148
+ writes static `.svg` pages instead:
149
+
150
+ ```bash
151
+ schematizer netlist.json --tool kicad9 --format svg -o out
152
+ ```
153
+
154
+ The same placement and routing pass is used for either output. They only differ in the last step,
155
+ where the result gets written out, so an SVG page has the same layout as the `.kicad_sch`
156
+ you would have gotten. Symbols are drawn from the graphics embedded in the netlist, so
157
+ the SVG output doesn't need KiCad libraries either.
158
+
159
+ `--flatness` controls the hierarchy for both formats:
160
+
161
+ - At `0.0` (the default), every subcircuit gets its own page.
162
+ - At `1.0`, everything collapses into a single page.
163
+ - Values in between flatten only the smaller subcircuits.
164
+
165
+ In the SVG output, a child appears on its parent's page as a **hyperlinked rectangle**,
166
+ and each child page links back to its parent. You can click
167
+ your way through a hierarchical design in a browser.
168
+
169
+ In the KiCad output, a net that leaves a subcircuit's page gets a hierarchical label at
170
+ its pins. The subcircuit's sheet symbol in the parent gets a matching sheet pin
171
+ with a label on it, so the connection runs through the hierarchy the way KiCad expects.
172
+ Power nets travel by power symbol instead. Stubbed nets (the ones marked `stub`, or
173
+ turned into labels when routing fails) travel by global label.
174
+
175
+ Each KiCad page uses the smallest A-size sheet whose frame holds the drawing above the
176
+ title block. An SVG page is sized to its drawing instead, since an SVG renders at
177
+ whatever size it declares.
178
+
179
+ ## Labels-only mode
180
+
181
+ Sometimes you don't care what the schematic looks like. You just need one whose
182
+ connections are right, say as the input to a PCB layout flow. That's what
183
+ `mode="labels"` (CLI: `--mode labels`) is for. Its connectivity is exact by
184
+ construction:
185
+
186
+ - Parts are placed unrotated on a plain, deterministic grid. There's no placement
187
+ optimization and no wire routing, so it's fast (about two seconds for a 190-part design).
188
+ - Every connected pin gets a short wire stub ending in one of three things: a power
189
+ symbol (if the net name matches a KiCad power symbol), a global label (if the net is
190
+ on more than one sheet) or a local label (if it's on one sheet). Pins on the
191
+ no-connect net get a no-connect flag.
192
+ - Each subcircuit with parts becomes a sheet directly under the root sheet. (Nested
193
+ subcircuits become sibling sheets.)
194
+
195
+ ```bash
196
+ schematizer netlist.json --tool kicad10 --mode labels -o out --top-name mydesign
197
+ ```
198
+
199
+ This is KiCad output only; `format="svg"` is rejected in this mode. And if you compare
200
+ connectivity afterward, leave out the `#` references (power symbols, PWR_FLAGs). KiCad
201
+ leaves them out of the netlists it exports.
202
+
203
+ ## Optional netlist keys
204
+
205
+ These keys are additive. The schema stays at version 1, and readers ignore keys they
206
+ don't use:
207
+
208
+ - `components[].fields`: user part fields such as `MPN`. They're written as symbol
209
+ properties.
210
+ - `nets[].attrs`: per-net attributes for layout tools, e.g.
211
+ `{"netclasses": ["Power"]}`.
212
+ - `netclasses`: net class definitions referenced by `nets[].attrs`.
213
+ - A net with `"nc": true` is the no-connect net. Its pins get no-connect flags.
214
+
215
+ ## Placement
216
+
217
+ A schematic that's electrically correct can still be miserable to read. So wired parts
218
+ are placed by the drafting conventions a person would follow:
219
+
220
+ - **Rails up, grounds down.** A pin on a supply net (`VCC`, `+3V3`, `VBAT`, ...) points
221
+ up and a pin on a ground or negative supply (`GND`, `VSS`, `-12V`, ...) points down.
222
+ That way decoupling caps and pull-ups stand upright.
223
+ - **Signals flow left to right.** A part isn't mirrored if that would put its inputs on
224
+ the right or its outputs on the left, and each part goes on the side of the pin it's
225
+ wired to.
226
+ - **ICs stay upright.** A part with more than three pins can be mirrored, but it isn't
227
+ turned on its side.
228
+ - **Passives sit beside their pins.** A two-pin part that hangs off the circuit by one
229
+ pin (a pull-up, a series resistor, an LED with its resistor) is fixed next to the pin
230
+ it's wired to.
231
+ - **Power nets get power symbols.** Nets with power names are drawn with a power symbol
232
+ on each pin instead of being wired across the sheet. So are nets with names of their
233
+ own (`VBUS_SW`) that go to a power pin and at least three other pins; those get
234
+ labels. A power net that already has a power symbol part of its own in the netlist is
235
+ left wired, and it points the way its symbol does.
236
+ - **Labels go on pins, not out in space.** A one-pin net that leaves the sheet is labeled at
237
+ its pin. If it has several pins, they're wired together and the
238
+ label goes beside one of them, far enough out that the other wires have room to join
239
+ it.
240
+ - **Unwired parts go in tidy rows.** Parts with no wires at all (a bank of decoupling
241
+ caps whose pins all go to power symbols) are laid out in rows, with each rail's caps
242
+ side by side and room for their references and values.
243
+ - **Text stays clear.** A part's reference and value go together on a side of the part
244
+ with no pins, wherever they don't cover another part, a wire or other text. If a
245
+ neighbor leaves no room for both, they're placed separately. The names of power
246
+ symbols on neighboring pins of an IC are turned to read up the sheet, because side by
247
+ side they'd run together into one long, meaningless word.
248
+
249
+ A part whose orientation is set in the netlist (`symtx`) keeps it. You said where you
250
+ wanted it, so that's where it goes.
251
+
252
+ **Routing feeds back into placement.** Once a sheet is routed, a wire that steps
253
+ sideways between two pins is telling you something: those pins are nearly, but not
254
+ quite, in line. So the part with the least wired to it is moved by the size of the
255
+ step (up to 3 grid steps) and the sheet is routed again. The new routing is kept only
256
+ if it has fewer bends and wire crossings. Otherwise the parts go back where they were.
257
+ On my 169-part test board, this removes about a quarter of those steps and 8% of the
258
+ bends for about 15% more time.
259
+
260
+ **The same circuit is drawn the same way.** When a subcircuit is used more than once
261
+ (e.g., the two channels of an amplifier), the sheet of the first one is placed and routed and
262
+ the others use its layout. Sheets match if their parts have the same symbols and
263
+ are wired the same. The values and net names can differ.
264
+
265
+ **A sheet can be laid out several times.** With `sheet_tries=3` (CLI:
266
+ `--sheet-tries 3`), each sheet is placed and routed three times and the best layout is
267
+ kept. Layouts are compared the way `tries` compares whole drawings: by wire length, with
268
+ each bend and wire crossing counted as 5 mm of wire and each overlap of parts or text
269
+ as 10 mm. The difference is that `tries` keeps the best whole drawing, while this keeps
270
+ the best of each sheet. On the 169-part test board, three tries remove 8% of the bends,
271
+ 40% of the crossings and 6% of the wire. They also take about twice as long. (Nothing's
272
+ free.)
273
+
274
+ A named net that stays on one sheet is wired, but its name isn't shown. Routing a wire
275
+ out to a label makes a crowded sheet even harder to route. If you want those nets
276
+ labeled anyway, pass `label_local_nets=True`.
277
+
278
+ Don't like some of this? Four options turn parts of it off (CLI: `--no-preplace`,
279
+ `--no-power-symbols`, `--no-nudge`, `--no-reuse`):
280
+
281
+ ```python
282
+ render(netlist, filepath="out", preplace=False) # force-directed placement from random positions
283
+ render(netlist, filepath="out", power_symbols=False) # wire the power nets
284
+ render(netlist, filepath="out", nudge=False) # don't move parts after routing
285
+ render(netlist, filepath="out", reuse_layouts=False) # lay out identical sheets separately
286
+ ```
287
+
288
+ With `preplace=False`, groups of more than 20 wired parts are laid out in plain rows.
289
+ Force-directed placement is too slow for them.
290
+
291
+ With `auto_stub`, parts placed this way keep the short wires routed to them. Only nets
292
+ with many pins or far-apart pins become labels. (With `preplace=False`, auto-stubbing
293
+ works the way it used to: it labels every net of a small subcircuit and snaps two-pin
294
+ parts onto the pins they connect to.)
295
+
296
+ ## Reproducible drawings
297
+
298
+ Unwired parts and the blocks of a sheet start at random positions, and the router
299
+ breaks ties randomly. So the same netlist normally gives you a different (but equally
300
+ valid) drawing on every run. Pass a seed to pin it down:
301
+
302
+ ```bash
303
+ schematizer netlist.json --tool kicad9 --seed 42 -o out
304
+ ```
305
+
306
+ ```python
307
+ render(netlist, tool="kicad9", filepath="out", seed=42)
308
+ ```
309
+
310
+ The same netlist, seed and options give byte-identical output, across separate
311
+ processes and for both formats. (There's one exception: the ERC report that kicad-cli
312
+ writes when `auto_stub` is on. Its first line is a timestamp.) Without a seed, nothing
313
+ changes: you get a random drawing each run.
314
+
315
+ Why would you want this?
316
+
317
+ - **Regression testing.** The drawing you got yesterday is the drawing you get today.
318
+ - **Bug reports.** You can point at one specific bad layout instead of describing it.
319
+ - **Re-rolling.** If you don't like a layout, try `--seed 1`, `2`, `3` until you get
320
+ one you want. Then write the number down.
321
+
322
+ Retries still explore. When routing fails and the engine tries again with a larger
323
+ area, each attempt derives its own random stream from your seed. A retry is a different
324
+ layout, but the run as a whole stays reproducible.
325
+
326
+ The two engines use different random number generators, so the same seed gives a
327
+ different (but equally valid) drawing on each. Each one is reproducible on its own.
328
+
329
+ Seeding is local to this library. It uses its own generator, so it neither disturbs nor
330
+ depends on the global state of the `random` module in your program.
331
+
332
+ ## When routing fails
333
+
334
+ A crowded sheet doesn't always route on the first try. So the engine tries again at
335
+ three levels before it gives up:
336
+
337
+ 1. If a net can't find a way through, the nets routed ahead of it are torn up and all
338
+ of them are routed again with that net first (up to 4 times).
339
+ 2. A sheet that still fails is placed again by itself with 25% more room around its
340
+ parts and routed again (up to 6 times). This doesn't touch the other sheets, since
341
+ the parent only shows it as a sheet symbol.
342
+ 3. If that fails too, the whole design is placed and routed again with more room
343
+ (`retries`, 2 by default).
344
+
345
+ Routing only counts as done if three things are true:
346
+
347
+ - Every wired pin has a wire of its net ending on it.
348
+ - No wire runs over the end of another net's pin.
349
+ - Each net's wires are in one piece.
350
+
351
+ Why so picky? KiCad connects a pin only to a wire that ends on it. A drawing that
352
+ breaks one of these rules would look right and be missing connections, which is the
353
+ worst kind of wrong.
354
+
355
+ If all three levels fail, the command line says so in one line and exits with status 1.
356
+ `render()` raises `RoutingFailure`.
357
+
358
+ ### Auto-stubbing
359
+
360
+ Some nets just aren't worth wiring. `auto_stub` (CLI: `--auto-stub [PINS]`) draws the
361
+ ones that are hard to route with labels instead of wires. A net with more than `PINS`
362
+ pins, or one whose pins end up far apart, uses labels. Then KiCad's ERC is run on
363
+ the result (this needs `kicad-cli`) and the nets it still complains about become labels
364
+ too. If routing fails anyway, a labels-only schematic is written instead.
365
+
366
+ ```bash
367
+ schematizer netlist.json -o out --auto-stub # more than 3 pins -> labels
368
+ schematizer netlist.json -o out --auto-stub 6 # more than 6 pins -> labels
369
+ ```
370
+
371
+ In Python, `auto_stub=True` means 3 and `auto_stub=6` sets the count. A lower count
372
+ gives you fewer wires and more labels. On the 169-part test board, the total wire
373
+ length is about 560 at 2, 1060 at 3, 1440 at 4 and 1940 at 10 (mm, averaged over 4
374
+ seeds). Without auto-stubbing it's 3180. Don't get greedy, though: at 2, the labels
375
+ start to overlap on smaller boards.
376
+
377
+ ## Checking the result
378
+
379
+ A schematic can look fine and still be wired wrong. `check_netlist=True` (CLI:
380
+ `--check-netlist`) has KiCad read back the schematic that was written and compares its
381
+ connections with the input netlist:
382
+
383
+ ```bash
384
+ schematizer netlist.json -o out --check-netlist
385
+ ```
386
+
387
+ ```python
388
+ from schematizer import NetlistMismatch, render
389
+
390
+ try:
391
+ render(netlist, filepath="out", check_netlist=True)
392
+ except NetlistMismatch as e:
393
+ print(e.problems) # e.g. ["SDA is shorted to SCL", "EN is in 2 pieces (R4.1 not connected to the rest)"]
394
+ ```
395
+
396
+ If they differ, `render()` raises `NetlistMismatch`. The command line prints the nets
397
+ that differ and exits with status 1. The files are left in place so you can look at
398
+ them.
399
+
400
+ A few things to know about the check:
401
+
402
+ - It needs `kicad-cli` and KiCad output.
403
+ - It takes about as long as KiCad needs to open the design (around a second for 170
404
+ parts).
405
+ - It's off by default.
406
+ - With `tries`, only the layout that's kept is checked.
407
+ - It ignores `#` references (power symbols, flags), which KiCad leaves out of its
408
+ netlists, and nets with fewer than two pins.
409
+
410
+ Nothing else runs KiCad on the output, apart from the ERC that auto-stubbing uses to
411
+ find nets to label.
412
+
413
+ ## Building from source
414
+
415
+ `pip install .` in a copy of the repository builds the compiled engine, so it needs
416
+ [Rust](https://rustup.rs) 1.85 or later. (If yours is older, `rustup update` fixes
417
+ that.) The standalone executable is built with:
418
+
419
+ ```bash
420
+ cargo build --release --manifest-path rust/Cargo.toml
421
+ ```
422
+
423
+ which puts it in `rust/target/release/`. `cargo test --manifest-path rust/Cargo.toml`
424
+ runs the engine's own tests, and `pytest tests` runs the Python ones against whichever
425
+ engine `render()` picks.
426
+
427
+ ## Supported KiCad versions
428
+
429
+ `--tool` accepts `kicad6` through `kicad10`. They share one modern S-expression writer
430
+ (with a couple of format toggles for KiCad 8). The version still matters for
431
+ `--format svg`, because the symbol graphics embedded in the netlist are flavored by
432
+ KiCad version.
433
+
434
+ KiCad 5 is **not** supported, and you'll get an error that says so. It uses the legacy
435
+ EESCHEMA `.sch` format instead of `.kicad_sch`, and its libraries describe symbols in a
436
+ different form (not S-expressions) that the generic netlist doesn't carry.
437
+
438
+ Sorry, KiCad 5. It was a good run.
439
+