Skip to content

feat: specialized linear layout for decoupling capacitors#45

Open
mendarb wants to merge 2 commits intotscircuit:mainfrom
mendarb:feat/decoupling-caps-linear-layout
Open

feat: specialized linear layout for decoupling capacitors#45
mendarb wants to merge 2 commits intotscircuit:mainfrom
mendarb:feat/decoupling-caps-linear-layout

Conversation

@mendarb
Copy link
Copy Markdown

@mendarb mendarb commented Mar 20, 2026

/claim #15

Summary

  • Detects decoupling capacitor partitions and arranges them in clean horizontal rows instead of using the general packing solver (which produces messy, overlapping layouts)
  • Fixes net inference so IdentifyDecouplingCapsSolver works out of the box without manual isGround/isPositiveVoltageSource annotation
  • Fixes transitive net lookup so caps wired pin-to-pin to a chip (like C12.pin1 -> U3.IOVDD1) correctly inherit the chip pin's net (V3_3) for classification

Changes

SingleInnerPartitionPackingSolver

When partitionType === "decoupling_caps", bypasses PackSolver2 and uses a new createLinearDecouplingCapLayout() method that:

  • Sorts capacitors by chip ID (deterministic ordering)
  • Places them in a single horizontal row with configurable gap (decouplingCapsGap)
  • Centers the row at the partition origin

IdentifyDecouplingCapsSolver

  • Relaxed rotation constraint: 2-pin components without explicit availableRotations are now valid candidates (the pinsOnOppositeYSides check already confirms vertical orientation)
  • Added getNetIdsForPinTransitive(): when a cap pin has no direct net but is strongly connected to a chip pin, it inherits that chip pin's net -- this is needed for the common pattern where C12.pin1 -> U3.IOVDD1 and U3.IOVDD1 -> V3_3

getInputProblemFromCircuitJsonSchematic

  • Infers isGround and isPositiveVoltageSource from net names (GND, Vxx, VDD, VCC, etc.)

Test plan

  • 3 new tests in tests/DecouplingCapLayout/DecouplingCapLayout01.test.ts:
    • Decoupling cap groups correctly identified (V3_3/GND group with 6 caps, V1_1/GND group with 2 caps)
    • Partitions created with correct decoupling_caps type
    • Final layout has caps in horizontal rows (same Y coordinate) with zero overlaps
  • SVG snapshot written to __snapshots__/DecouplingCapLayout01_final.svg for visual verification
  • All 20 existing tests still pass (1 pre-existing fail + 1 pre-existing error unchanged)
  • bun run format:check passes

Results on RP2040 circuit

Before: 4 chip overlaps (U3-C14, C10-C7, C10-C12, C19-C15)
After: 0 overlaps -- IOVDD caps (C8, C12, C13, C14, C15, C19) in one clean row, DVDD caps (C7, C18) in another

Generated with Claude Code

When a partition is tagged as `decoupling_caps`, bypass the general
PackSolver2 and instead arrange capacitors in a clean horizontal row
sorted by chip ID. This eliminates the messy overlapping layout that
the generic packing algorithm produces for these components.

Three changes make this work end-to-end:

1. IdentifyDecouplingCapsSolver: relax the rotation constraint so
   2-pin components without explicit `availableRotations` are still
   candidates (the y+/y- pin check already confirms orientation).
   Add transitive net lookup so a cap pin strongly connected to a
   chip pin inherits that pin's net — needed when the circuit wires
   cap.pin1 directly to a chip IOVDD pin and the V3_3 net is on
   the chip side of the connection.

2. getInputProblemFromCircuitJsonSchematic: infer `isGround` and
   `isPositiveVoltageSource` flags from well-known net names
   (GND, Vxx, VDD, VCC, etc.) so the decoupling-cap net-pair
   validation works without manual annotation.

3. SingleInnerPartitionPackingSolver: new `createLinearDecouplingCapLayout`
   early-returns a deterministic horizontal row for decoupling_caps
   partitions, with configurable gap via `decouplingCapsGap`.

Tested on the RP2040 circuit: 0 overlaps, caps in clean rows.

Closes tscircuit#15

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 20, 2026

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

A member of the Team first needs to authorize it.

The test was importing from the .page.tsx file which transitively pulled
in circuit-to-svg (via LayoutPipelineDebugger), causing a missing export
error. Extracted the problem data to a standalone .ts file so tests can
import it without triggering UI dependency resolution.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant