Metadata-Version: 2.5
Name: wbsvg
Version: 0.3.0
Summary: Read, query and check .wb.svg wire bond diagrams: SVG pictures that are also the data
Project-URL: Homepage, https://github.com/anfroholic/wirebond.svg
Project-URL: Documentation, https://github.com/anfroholic/wbsvg#readme
Project-URL: Source, https://github.com/anfroholic/wbsvg
Project-URL: Specification, https://github.com/anfroholic/wirebond.svg/blob/main/SPEC.md
Project-URL: App, https://anfroholic.github.io/wirebond.svg/app/
Project-URL: Issues, https://github.com/anfroholic/wbsvg/issues
Author: Andrew Wingate
License-Expression: MIT
License-File: LICENSE
Keywords: bondlist,chip-on-board,gds,kicad,packaging,svg,wb.svg,wbsvg,wire bonding,wirebond
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Manufacturing
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Scientific/Engineering :: Electronic Design Automation (EDA)
Requires-Python: >=3.10
Requires-Dist: lxml
Provides-Extra: dxf
Requires-Dist: ezdxf; extra == 'dxf'
Provides-Extra: test
Requires-Dist: ezdxf; extra == 'test'
Requires-Dist: pytest; extra == 'test'
Description-Content-Type: text/markdown

<p align="center">
  <a href="https://github.com/anfroholic/wirebond.svg">
    <img src="https://anfroholic.github.io/wirebond.svg/app/brand/wirebond-logo-light.svg" alt="wirebond.svg" width="360">
  </a>
</p>

# wbsvg

Bond a die to a board, and read, query and check `.wb.svg` wire bond diagrams, from Python or the shell.

Its other name is **wirebond**. `pip install wirebond`, `import wirebond` and the `wirebond` command all work, and each is the same as its `wbsvg` counterpart. See [One package, two names](#one-package-two-names).

A [wirebond.svg](https://github.com/anfroholic/wirebond.svg) file (`.wb.svg`) is a wire bond diagram you can open in any browser. It is also data. Every pad, land, wire, loop profile and layer is a drawn SVG element, and its values sit on it as `wb:` attributes:

```xml
<line x1="5060" y1="9003" x2="3300" y2="11000" stroke-width="20"
      wb:kind="wire" wb:name="W01" wb:from="U1.1" wb:to="L1" wb:profile="STD20" wb:seq="1" wb:net="clk_PAD"/>
```

This package reads that data back out: the bond list, nets, loop profiles, wire lengths, and design rule checks. The format is defined in [SPEC.md](https://github.com/anfroholic/wirebond.svg/blob/main/SPEC.md).

It also makes them. `wbsvg build` takes a die's GDS and the KiCad board or footprint it bonds to, and writes what the browser app, [Wire Bond Bench](https://anfroholic.github.io/wirebond.svg/app/), writes: the bonded board, the 3D model, the `.wb.svg` and the bond list. See [From a die and a board](#from-a-die-and-a-board).

## Install

```sh
pip install wbsvg               # the wbsvg command, and import wbsvg
pip install "wbsvg[dxf]"        # also ezdxf, for wbsvg export's 3D DXF
```

Python 3.10 or later. Reading needs only the standard library. `check` also needs `lxml`, which installs with the package. `build` and `kit` read GDS and KiCad files themselves and need nothing more, except `ezdxf` for the DXF.

## From the shell

```sh
wbsvg info board.wb.svg                          # what's in it: dies, wires, wire used, stack, fiducials, rules, seal
wbsvg seal board.wb.svg                          # was it changed since it was written? Its SHA-256 digests; exits 1 unless intact
wbsvg bondlist board.wb.svg -o bonds.csv         # one row per wire, in bond order, for a bonder
wbsvg bondlist board.wb.svg --origin board --units mm
wbsvg table board.wb.svg profiles                # also: wires pads lands nets dies layers fiducials parts
wbsvg query board.wb.svg wire "net=VSS|VDD"      # elements whose wb: attributes match, one JSON per line
wbsvg json board.wb.svg > board.json             # everything read, as JSON
wbsvg check board.wb.svg                         # consistency, design rules and the seal; exits 1 on an error
wbsvg check board.wb.svg --json                  # the same, with the measured clearances and gaps, as JSON
wbsvg place board.wb.svg                         # how far each die can move or turn before a check fails
wbsvg export board.wb.svg out                    # out.bondlist.csv, out.fiducials.csv, out.dxf (needs wbsvg[dxf])
```

`python -m wbsvg` works the same as `wbsvg`.

`wbsvg seal` answers one question: is this the file that was exported?

```
$ wbsvg seal board.wb.svg
seal: intact: not changed since it was written
  data sha256     ba990fed9a295940fe209b8e87cfc94ef34f11071aedf82d0251e3d7273fff2d
  drawing sha256  f774b5b38368a1c1744727b42570cee7d5fe8f7ca414a74fee26d856701f1881
```

More in [Was it edited?](#was-it-edited)

## From a die and a board

`wbsvg build` does what Wire Bond Bench does, without asking anything. Give it the die's GDS and the KiCad footprint or board with the lands it bonds to:

```sh
wbsvg build die.gds board.kicad_pcb -o out            # every file, then the checks; exits 1 if a check fails
wbsvg build die.gds pads.kicad_mod -o out             # a footprint of lands, in place of a board
wbsvg build die.gds board.kicad_pcb --only wbsvg,bondlist
wbsvg build logic.gds ram.gds board.kicad_pcb -o out  # several die
wbsvg kit die.gds -o kit                              # the die kit alone, with no board
```

For the 1x1 example die on its padring, that's:

```
$ wbsvg build waferspace_1x1_die.gds waferspace_default_padring_v0.2.kicad_mod -o out
waferspace_default_padring_v0.2.kicad_mod is the substrate: 74 lands.
waferspace_1x1_die.gds: 3.93 x 5.12 mm, 74 pads on 37/0, 74 named.
D1: chip_top, 74 pads, 3.932 x 5.122 mm, at 0.000, 0.000 turned 0, pairing by number
74 wires to 74 lands
wrote out/chip_top_kit/wbsvg_die.pretty/chip_top.kicad_mod
...
```

`--only` takes any of these. With no `--only`, it writes them all, so it needs `ezdxf` for the DXF: install `wbsvg[dxf]`, or name the files you want.

| `--only` | File |
|---|---|
| `board` | `<board>_bonded.kicad_pcb`: the board with the die, its wires and the wire types, and the 3D model embedded |
| `step` | `<board>_bond.step`: the 3D model of the die and wires |
| `wbsvg` | `<board>.wb.svg`: the bond diagram |
| `bondlist` | `<die>.bondlist.csv`: one row per wire, in bond order |
| `kit` | `<die>_kit/`: the die's footprint with its 3D model, symbol, STEP and `die.json` |
| `footprint` | `<die>.kicad_mod` alone |
| `symbol` | `<die>.kicad_sym` alone |
| `fiducials` | `<board>.fiducials.csv` |
| `dxf` | `<board>.dxf`: the 3D wires. Needs `ezdxf` |
| `report` | `<board>.report.json`: what it found, what it assumed, and the checks |

Where the app would ask, wbsvg gives the app's own answer, and a flag overrides it:

| The app asks | wbsvg's answer | Flag |
|---|---|---|
| Which footprint on the board holds the lands | The one the app suggests | `--substrate J1` |
| Which GDS cell, which layer has the pads, where pin 1 is | Found the way the app finds them | `--cell`, `--pad-layer 37/0`, `--corner ll`, `--dir cw` |
| Which pad goes to which land | The board's own wires. Else by number, or by net, if that pairs most pads with no wires crossing. Else round the ring | `--regime wires\|number\|nets\|ring` |
| Where the die sits | The die already on the board, else centred on the lands | `--at X,Y` in mm |
| How it's turned | The turn with the shortest wires | `--rot 90` |
| Wire types, thickness, attach, rules | The board's, else the app's defaults | `--types types.json`, `--thick`, `--attach`, `--rules rules.json` |

The die's artwork is drawn 1024 pixels across, where the app draws 4096. `--art-px` changes that, and `--no-art` leaves the artwork out, which is quicker. Apart from the artwork, the bonded board, the STEP, the `.wb.svg` and the bond list are the app's own, line for line. The development repo's tests build eight examples both ways and compare those four files.

`build` and `kit` are in the package only. The single-file `wbsvg.py` in the repo's `tools/` doesn't have them.

## From Python

```python
import re, wbsvg

a = wbsvg.load("board.wb.svg")
print(a.summary())

for w in a.wires:                                  # in bond order
    print(w.seq, w.name, w.from_, "->", w.to, w.profile, w.length, w.loop_height)   # um; None if it can't be known

a.wire("W01").loop3d()                             # the loop's control points on the board, (x, y, z)
a.pad("U1.12").net                                 # pads are named <die>.<pad>, as wires name them
a.net("VSS")                                       # Net(name, pads, lands, wires)
a.die("U1").to_board(496, 28)                      # a GDS point on the die, on the board
a.unbonded_pads(), a.unused_lands()
a.wire_usage()                                     # wire used, by material and diameter, in um

a.query("wire", net="VSS")                         # match any wb: attribute, as the file spells it
a.query("wire", to_kind="die")                     # wb:to-kind: write - as _
a.query("wire", profile=["PWR20", "GND20"])        # any of these
a.query("pad", die="D2", net=re.compile(r"DQ\d"))  # or a regex, or the object's own fields
a.query("wire", length=lambda v: v > 3000)         # or a function

a.bondlist()                                       # rows: die-centred, y up, z up, um, as wbsvg export writes
a.bondlist(origin="board", units="mm")             # from the board's lower-left corner instead
a.table("profiles")                                # per profile: wires using it, spans, loop heights, total length

r = a.check()                                      # Report: errors, warnings, notes, metrics
r.ok, r.errors
a.seal                                             # "intact", "drawing changed", "data changed" or "none"
a.seal_report()                                    # that, with the SHA-256 digests: as written, and as the file gives now

a.to_json()                                        # everything, as JSON
```

Every table is a list of flat dicts, so it goes straight into `csv.DictWriter` or pandas: `pandas.DataFrame(a.table("wires"))`.

The design rule checker underneath is `wbsvg.drc`:

```python
from wbsvg import drc

m = drc.rd("board.wb.svg")         # a dict: die (the first), dies, pads, lands, wires, prof, stack, seal, and fid, tol, board if present
m = drc.model(a)                   # the same, from an Assembly already read
res, errors = drc.check(m)
drc.place_limits(m)                # how far each die can move or turn before a check fails, by name
drc.seal("board.wb.svg")           # stamp a file written some other way with its seal, in place
```

### What it reads

| On `Assembly` | Holds |
|---|---|
| `design`, `rev`, `version`, `rules` | The root attributes; `rules` as `wire_gap`, `edge_clear`, `fid_clear` in µm |
| `board` | The board outline: `x`, `y`, `w`, `h` |
| `dies` | Each `Die`: `name`, `gds_cell`, size `w`, `h`, placement `x`, `y`, `rotation`, centre `cx`, `cy`, its `pads`, and `z_bottom`, `thickness`, `z_top`, `attach` from the section view |
| `pads` | Every die's `Pad`s: `die`, `name`, `ref` (`U1.12`), `net`, `x`, `y`, `w`, `h` in the die's own frame, and `cx`, `cy` on the board |
| `lands` | `Land`s: `name`, `net`, `finish`, as drawn, and `cx`, `cy`, `rotation` on the board |
| `wires` | `Wire`s in bond order: `name`, `seq`, `tier`, `net`, `from_`, `to`, `to_kind` (`land` or `die`), `profile`, `diameter`, bond points `x1`, `y1`, `z1`, `x2`, `y2`, `z2`, and `span`, `length`, `loop_height`, `loop_top` from the profile |
| `profiles` | `Profile`s: `name`, `material`, `diameter`, `style`, `dir`, `moves`, `interp`, `ref_span`, `choice`; `steps(span)` gives the moves in µm |
| `stack` | The section view's `Layer`s: `name`, `role`, `material`, `z`, `thickness`, `top` |
| `fiducials`, `parts`, `tolerances` | Fiducials in either frame with their reference points, parts from the board view, and die placement tolerances |
| `items` | Every element with a `wb:kind`, as written: `kind`, `name`, `tag`, `attrs`, `title` |

Every object also has `attrs`, its `wb:` attributes exactly as written, and `title`, its hover text. So an attribute this version doesn't know is still there: `w.get("security-bump")`.

### Units and coordinates

Lengths are µm. Board coordinates are the file's: x right, y down, from the board's top-left corner. Pad coordinates are the die's own, as in its GDS, with y up. z is up from the top of the board.

### Was it edited?

Files written by wbsvg or Wire Bond Bench are sealed: two SHA-256 digests on the root, `wb:data-sha256` over the data and `wb:drawing-sha256` over everything drawn ([SPEC.md, Seal](https://github.com/anfroholic/wirebond.svg/blob/main/SPEC.md#seal-draft)). wbsvg works both digests out again from the file and compares them with the ones written on it.

| The file | `wbsvg seal`, `a.seal` | `wbsvg check` |
|---|---|---|
| Unchanged since it was written | `intact` | Nothing |
| Only its drawing was changed: a label, hover text or a colour | `drawing changed` | A warning |
| Its data was changed, by hand or in another program | `data changed` | An error |
| It has no seal, so changes can't be found | `none` | A note |

Three places show it:

- `wbsvg seal board.wb.svg` prints the result and both digests, and exits 0 only when the seal is intact, so a script can refuse any other file. `--json` gives the same as JSON.
- `wbsvg info` ends with the same lines, and `wbsvg check` reports a broken seal with everything else it finds.
- In Python, `a.seal` is the result and `a.seal_report()` adds the digests: `{"seal": "intact", "data": {"written": "ba99…", "now": "ba99…"}, "drawing": {…}}`.

When a file was changed, each digest is shown twice, as the file gives it now and as it was written:

```
$ wbsvg seal edited.wb.svg
seal: data changed: the data was changed after the file was written
  data sha256     0879dd76959ebb2df4f332933b9c0dfd69f351605c634a67789a9ef806d451aa
    written as    ba990fed9a295940fe209b8e87cfc94ef34f11071aedf82d0251e3d7273fff2d
  drawing sha256  75d3fb1e42d18e59c577c8caf79a9ece12bd039d7be6dcd08a0a87acd0ef469e
    written as    f774b5b38368a1c1744727b42570cee7d5fe8f7ca414a74fee26d856701f1881
```

To be sure two people hold the same file, compare the digests: send them with the file, or read them out, and the other side runs `wbsvg seal` and checks they match.

Opening and saving in Inkscape without a change keeps the seal. The seal catches edits made in good faith, not deliberate ones: anyone can work the digests out again and reseal a file.

### What each part can read

`wbsvg` reads several dies, a turned die, stacked die and die-to-die wires, as Wire Bond Bench writes them. Its design rule checker, `wbsvg.drc`, reads files through it, so `check`, `place` and `export` take all of those too. The rules mean what the app's checks mean: a wire from one die to another clears the edge it leaves and the edge it comes in over, and the loop over any other die it passes clears that die. `place` gives each die's limits in turn, moving one die at a time.

## One package, two names

wbsvg is named after the file it reads, `.wb.svg`. Its other name, wirebond, works at every level:

| | wbsvg | wirebond |
|---|---|---|
| Install | `pip install wbsvg` | `pip install wirebond`: a placeholder on PyPI that installs wbsvg |
| Import | `import wbsvg` | `import wirebond`: ships in the wbsvg package, and hands back wbsvg's own objects |
| Command | `wbsvg` | `wirebond`: the same command |
| Run as a module | `python -m wbsvg` | `python -m wirebond` |

Installing either one gives you both names. `wirebond.Assembly is wbsvg.Assembly`, and `from wirebond import drc` is the same module as `from wbsvg import drc`, not a second copy. These docs use wbsvg.

## Development

From this folder:

```sh
pip install -e ".[test]"
pytest
```

The tests read the example files in `tests/data/`, which come from the wirebond.svg repo's `examples/`.

## Releasing

The version is `__version__` in `src/wbsvg/__init__.py`. To release:

1. Raise `__version__` and push.
2. On GitHub, publish a release whose tag is that version: `v0.3` or `v0.3.0` for `0.3.0`.

Publishing the release runs [publish.yml](https://github.com/anfroholic/wbsvg/blob/main/.github/workflows/publish.yml). It builds wbsvg and the `wirebond` placeholder, tests the wheel, checks that the tag is `__version__`, and uploads both to PyPI. PyPI knows the workflow by name ([trusted publishing](https://docs.pypi.org/trusted-publishers/)), so no API token is stored anywhere. The one-time setup on pypi.org is at the top of that file. PyPI never takes the same version twice, even after a delete, so a bad release is fixed by raising the version again.

To build and test without uploading, run the workflow from the Actions tab. Or here:

```sh
pip install build twine
pyproject-build --outdir dist      # dist/wbsvg-<version>.tar.gz and .whl
twine check --strict dist/*
```

The `wirebond` placeholder in [alias/](https://github.com/anfroholic/wbsvg/tree/main/alias) goes up with a release only when its own version, in `alias/pyproject.toml`, is new to PyPI. Raise it when wbsvg's extras change.

## Licence

MIT. See [LICENSE](https://github.com/anfroholic/wbsvg/blob/main/LICENSE).

---

Part of [wirebond.svg](https://github.com/anfroholic/wirebond.svg), a viewable wire bond exchange format, and its browser app Wire Bond Bench. (c) Andrew Wingate.
