Skip to main content

Multi-layer crossing minimization for PCB connector pin assignment

Project description

PCB Crossing Optimizer

Multi-layer crossing minimization for PCB connector pin assignment. Detects trace crossings in SKiDL-generated KiCad netlists and computes optimal pin orderings for single-layer routing using Sugiyama-style barycenter sweep.

Installation

pip install pcb-crossing-optimizer

After installation, the pcb-crossing-optimizer command is available on your PATH.

Usage

The tool has two subcommands: analyze (default) and plan-footprint.

analyze (default)

Analyze crossings between component layers. This is the original behavior and remains the default when no subcommand is given.

pcb-crossing-optimizer [analyze] <netlist.net> --layers "L0_refs | L1_refs | L2_refs" --reorderable REF [REF ...] [--exclude REF:PIN ...] [--json] [--quiet]

Analyze the microSD breakout with passives in the middle layer:

pcb-crossing-optimizer examples/microsd_breakout.net --layers "J1 | R1,R2,C1 | J2" --reorderable J2 --exclude J1:SH

Simple two-connector case (just use two layers):

pcb-crossing-optimizer examples/i2c_breakout.net --layers "J1 | J2" --reorderable J2

JSON output for tooling integration:

pcb-crossing-optimizer examples/i2c_breakout.net --layers "J1 | J2" --reorderable J2 --json

Quiet mode for CI (exit code 0 = no crossings, 1 = crossings remain):

pcb-crossing-optimizer examples/i2c_breakout.net --layers "J1 | J2" --reorderable J2 --quiet

plan-footprint

Compute an optimal pin map for a custom footprint. Given a target component (whose footprint you are designing), fixed anchor components, and optional pin locks, it runs the crossing sweep and produces a complete pin-to-net assignment proposal.

pcb-crossing-optimizer plan-footprint <netlist.net> \
    --target J1 \
    --anchors "J2,U1 | R1,R2,R3,C1" \
    --lock 1=NC 2=NC 3=GND_EARLY_A \
    --unmatched end \
    --exclude-nets GND \
    [--json] [--quiet]

Options:

  • --target REF: Component whose footprint is being designed
  • --anchors "...": Fixed components organized in layers separated by |
  • --lock PIN=NET: Lock specific pins to nets (use PIN=NC for no-connect)
  • --unmatched start|end|split: Where to place pins with no anchor connections (default: end)
  • --exclude-nets NET [NET ...]: Nets to exclude from analysis (e.g. ground pours)

Nets spanning non-adjacent layers (e.g., J1 to J2 through a passive layer) are handled automatically via virtual pass-through nodes.

How it works

  1. Parses a KiCad .net file (S-expression format generated by SKiDL)
  2. Extracts pin-to-net connectivity for specified components
  3. Sugiyama-style barycenter sweep across all layers:
    • Inserts virtual nodes for long edges spanning non-adjacent layers
    • Reorders both pins within reorderable components and components within layers
    • Iterates forward/backward sweeps until convergence
  4. Reports current crossings, recommended reordering, and remaining crossings

Project structure

src/crossing_analyzer.py        Core logic + CLI
tests/                      pytest tests
examples/                   Sample netlists for testing
.github/workflows/          CI / PyPI publishing

Running tests

pip install pytest
pytest -v

Python import

The PyPI package name is pcb-crossing-optimizer, but the importable module is crossing_analyzer:

from crossing_analyzer import sweep_optimize, PinColumn, format_multilayer_report

Publishing to PyPI

Releases are published automatically via GitHub Actions trusted publishing (OIDC — no API tokens needed).

Setup (one-time)

  1. On pypi.org, go to your project → PublishingAdd a new publisher
  2. Configure the trusted publisher:
    • Owner: ashergarland
    • Repository: pcb-crossing-optimizer
    • Workflow: publish.yml
    • Environment: pypi
  3. On GitHub, go to Settings → Environments and create an environment named pypi

Releasing a new version

  1. Update the version in pyproject.toml
  2. Commit and push
  3. Tag and push the tag:
    git tag v0.5.0
    git push origin v0.5.0
    
  4. The publish.yml workflow triggers on v* tags and publishes to PyPI automatically

Manual publishing (fallback)

pip install build twine
python -m build
twine upload dist/*

Roadmap

  • Passive placement optimizer (assign positions to resistors/caps in routing channel)
  • F.Cu/B.Cu layer assignment for unavoidable crossings

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pcb_crossing_optimizer-0.5.0.tar.gz (21.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pcb_crossing_optimizer-0.5.0-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

Details for the file pcb_crossing_optimizer-0.5.0.tar.gz.

File metadata

  • Download URL: pcb_crossing_optimizer-0.5.0.tar.gz
  • Upload date:
  • Size: 21.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for pcb_crossing_optimizer-0.5.0.tar.gz
Algorithm Hash digest
SHA256 8ffbb3a4ec6a51c15b212f28cfd5b29f84bda2e719e64bc50e89da9a8a589e7f
MD5 b8d1d93f4b85e2c8b36d965d1b701433
BLAKE2b-256 1519de17234ca16f5e1bbf73dad81d81e074fed0504c6e29d423adf714f89fc7

See more details on using hashes here.

Provenance

The following attestation bundles were made for pcb_crossing_optimizer-0.5.0.tar.gz:

Publisher: publish.yml on ashergarland/pcb-crossing-optimizer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pcb_crossing_optimizer-0.5.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pcb_crossing_optimizer-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7bd14059fe739539a30196a88d2b35449e0f41de53818df01e2572e7aa6f1f27
MD5 d382cdd1db5c9ccb81ad8c01cce42d8c
BLAKE2b-256 f99c3fdac5a49b5279203a5b60b93a32a69d140f7f93dad77f06d0b01647bf5d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pcb_crossing_optimizer-0.5.0-py3-none-any.whl:

Publisher: publish.yml on ashergarland/pcb-crossing-optimizer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page