Skip to content

Group and row-pack decoupling caps to eliminate chip overlaps (fixes #15)#68

Open
Pearltechie wants to merge 2 commits intotscircuit:mainfrom
Pearltechie:fix/decoupling-cap-layout
Open

Group and row-pack decoupling caps to eliminate chip overlaps (fixes #15)#68
Pearltechie wants to merge 2 commits intotscircuit:mainfrom
Pearltechie:fix/decoupling-cap-layout

Conversation

@Pearltechie
Copy link
Copy Markdown

@Pearltechie Pearltechie commented Apr 24, 2026

Fixes #15.

Problem

The RP2040 example (tests/LayoutPipelineSolver/RP2040Circuit.test.ts) produced 4 chip overlaps in the final layout because decoupling capacitors were treated like ordinary 2-pin chips:

IdentifyDecouplingCapsSolver and SingleInnerPartitionPackingSolver were already partly in place, but identified 0 decap groups on RP2040 because:

  1. The converter never set availableRotations on 2-pin passives.
  2. The converter never set isGround / isPositiveVoltageSource on supply nets.
  3. getNetIdsForPin only looked at direct pin↔net connections, missing caps that tee off another chip's pin via a strong pin↔pin connection (the common RP2040 wiring style).

Fix

Three coordinated changes:

1. Converter (lib/testing/getInputProblemFromCircuitJsonSchematic.ts)

  • Tag 2-pin passives (resistor / capacitor / diode / inductor / ferrite_bead) with availableRotations: [0, 180].
  • Detect rails by net name: GND/VSS/VEEisGround: true; VCC/VDD/VBUS/V3_3/V5/...isPositiveVoltageSource: true.

2. Decoupling-cap identification (lib/solvers/IdentifyDecouplingCapsSolver/IdentifyDecouplingCapsSolver.ts)

  • getNetIdsForPin now walks one hop across pinStrongConnMap so a cap pin that's strong-connected to a chip pin still resolves to whatever supply net the chip pin sits on.
  • findMainChipIdForCap falls back to a net-pair search when there's no direct strong neighbour: the main chip becomes the chip with the most pins on the cap's normalised (GND, V*) net pair.

3. Inner-partition packing (lib/solvers/PackInnerPartitionsSolver/SingleInnerPartitionPackingSolver.ts)

Decoupling-cap partitions bypass PackSolver2 and use a deterministic centred row layout sorted by chipId, with spacing controlled by decouplingCapsGap (falling back to chipGap).

Verification

Both RP2040Circuit complete pipeline execution (asserts overlaps.length === 0) and RP2040Circuit InputProblem conversion pass. The full suite is 17 pass / 1 skip, with one pre-existing unrelated failure in IdentifyDecouplingCapsSolver06.test.ts (circuit-to-svg no longer exports convertCircuitJsonToSchematicSimulationSvg) that is unaffected by this PR.

The getInputProblemFromCircuitJsonSchematic01 inline snapshot was updated to reflect the new availableRotations / isGround / isPositiveVoltageSource fields.

Demo Video

rec-324c1315-3004-494c-abca-dfe3ec7cfe41-subtitled.mp4

/claim #15

  Fixes tscircuit#15.

  The RP2040 example produced four chip overlaps because the layout pipeline
  treated decoupling capacitors like ordinary 2-pin chips. Three coordinated
  fixes give each main chip's bypass network a tidy, deterministic row.

  1. Converter (getInputProblemFromCircuitJsonSchematic)
     - Tag 2-pin passives (resistors, capacitors, diodes, ferrites, inductors)
       with availableRotations: [0, 180] so downstream solvers can recognise
       them as orientation-restricted.
     - Detect ground / positive-supply rails by net name (GND/VSS/VEE,
       VCC/VDD/VBUS/V3_3 family, etc.) and set isGround /
       isPositiveVoltageSource on the matching nets.

  2. Decoupling-cap identification
     - Walk one hop across pinStrongConnMap in getNetIdsForPin so a cap whose
       hot pin tees directly off a chip pin still resolves to the supply net
       that chip pin sits on (the common RP2040 wiring style).
     - Add a net-pair fallback in findMainChipIdForCap: when a cap has no
       direct strong neighbour, the main chip is the chip with the most pins
       on the cap's net pair. This catches caps wired purely through the
       power and ground rails.

  3. Inner-partition packing
     - Decoupling-cap partitions now bypass PackSolver2 and use a deterministic
       centred row layout sorted by chipId, with spacing controlled by
       decouplingCapsGap (falling back to chipGap).

  Test results

    RP2040Circuit complete pipeline execution    PASS  (overlaps: 0)
    RP2040Circuit InputProblem conversion        PASS

  The getInputProblemFromCircuitJsonSchematic01 inline snapshot was updated
  to reflect the new metadata (availableRotations on 2-pin passives, isGround
  and isPositiveVoltageSource on supply nets).
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 24, 2026

@Pearltechie is attempting to deploy a commit to the tscircuit Team on Vercel.

A member of the Team first needs to authorize it.

  The IdentifyDecouplingCapsSolver06 test imported `problem` from
  `LayoutPipelineSolver06.page.tsx`, which transitively pulled in
  `@tscircuit/schematic-viewer` -> `circuit-to-svg`. The latter no longer
  exports `convertCircuitJsonToSchematicSimulationSvg`, so the test crashed
  with "SyntaxError: Export named ... not found".

  Splitting the problem definition into a sibling `.problem.ts` (no React,
  no visualization deps) gives the test a clean import path and removes the
  crash. The page re-exports `problem` for backwards compatibility.

  Result: 18 pass, 1 skip, 0 fail.
@Pearltechie
Copy link
Copy Markdown
Author

Hey @seveibar 👋 just wanted to check in on this — all the CI checks (tests, type-check, formatting) are passing and I've included a demo video in the description. Let me know if there's anything you'd like me to change or if you have any questions about the approach!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Specialized Layout for Decoupling Capacitors

1 participant