Skip to content

feat: PowerNetBiasSolver — post-pack vertical bias for power/ground nets#63

Open
LuSrodri wants to merge 1 commit intotscircuit:mainfrom
LuSrodri:fix/algora-12-power-gnd-vertical-bias
Open

feat: PowerNetBiasSolver — post-pack vertical bias for power/ground nets#63
LuSrodri wants to merge 1 commit intotscircuit:mainfrom
LuSrodri:fix/algora-12-power-gnd-vertical-bias

Conversation

@LuSrodri
Copy link
Copy Markdown

Summary

Resolves #12 — bad schematic layout where power and ground chips were placed without any vertical bias, producing tangled, hard-to-read schematics.

Approach: Post-pack PowerNetBiasSolver phase

This PR adds a new PowerNetBiasSolver that runs as the final step in the LayoutPipelineSolver pipeline, after PartitionPackingSolver has placed all partitions.

Why post-pack (not in-pack)?
The PackSolver2 minimizes pad-to-pad distance for connected networks. Because power/ground nets span many chips simultaneously, injecting directional bias during packing creates conflicting forces. A clean post-pack pass lets the packing algorithm do its job, then applies deterministic, net-type-aware vertical displacement.

Algorithm

  1. Net ratio scoring: For each chip, count what fraction of its pins connect to isPositiveVoltageSource nets vs isGround nets.
  2. Vertical displacement: Chips with powerRatio ≥ 0.20 and powerRatio > groundRatio are displaced upward (positive Y in schematic math coordinates). Chips with groundRatio ≥ 0.20 and groundRatio > powerRatio are displaced downward. Mixed chips (decoupling caps, signal chips) are unaffected.
  3. Displacement magnitude: chipGap × 5 × netRatio — scales with how "power-dominant" the chip is.
  4. Overlap resolution: After bias, an iterative pairwise push-apart pass (up to 100 iterations) resolves any new overlaps, preserving the established vertical ordering.

Result

  • VCC/VDD chips float to the top of the layout
  • GND chips sink to the bottom
  • Signal and decoupling-cap chips stay in the middle
  • No chip overlaps introduced

Changes

  • lib/solvers/PowerNetBiasSolver/PowerNetBiasSolver.ts — new solver
  • lib/solvers/LayoutPipelineSolver/LayoutPipelineSolver.ts — adds powerNetBiasSolver as pipeline step 5; getOutputLayout() prefers bias-corrected layout; visualize() shows final biased state
  • pages/LayoutPipelineSolver/LayoutPipelineSolver06.problem.ts — extracted problem data with no UI imports (fixes transitive circuit-to-svg import error in tests)
  • pages/LayoutPipelineSolver/LayoutPipelineSolver06.page.tsx — simplified to import from .problem.ts
  • tests/PowerNetBiasSolver/PowerNetBiasSolver01.test.ts — 4 tests: direct solver with flat layout, overlap resolution, full pipeline ordering, ExampleCircuit02 regression

Test results

22 pass, 1 skip, 0 fail

/claim #12

…l bias

Adds a new PowerNetBiasSolver that runs as the final pipeline step after
PartitionPackingSolver. It applies vertical displacement to chips based
on their power/ground net connectivity — chips predominantly connected
to positive voltage nets (VCC, VDD, V+) are displaced upward, chips
predominantly connected to ground nets (GND, VSS) are displaced downward.

After biasing, an iterative overlap-resolution pass ensures no chips
overlap with the required chipGap.

Also extracts the LayoutPipelineSolver06 problem data into a separate
.problem.ts file (no UI imports), fixing the IdentifyDecouplingCapsSolver06
test that was failing due to a transitive import of circuit-to-svg.

Changes:
- lib/solvers/PowerNetBiasSolver/PowerNetBiasSolver.ts (new)
- lib/solvers/LayoutPipelineSolver/LayoutPipelineSolver.ts (add pipeline step)
- pages/LayoutPipelineSolver/LayoutPipelineSolver06.problem.ts (new)
- pages/LayoutPipelineSolver/LayoutPipelineSolver06.page.tsx (slim down)
- tests/PowerNetBiasSolver/PowerNetBiasSolver01.test.ts (new, 4 tests)
- tests/IdentifyDecouplingCapsSolver/IdentifyDecouplingCapsSolver06.test.ts (fix import)
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 14, 2026

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

A member of the Team first needs to authorize it.

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.

Propose/implement a solution to bad layout

1 participant