Skip to content

feat: add TraceAlignmentSolver to reduce trace zig-zag (#12)#97

Open
chenchong0215 wants to merge 2 commits into
tscircuit:mainfrom
chenchong0215:feature/trace-alignment-solver
Open

feat: add TraceAlignmentSolver to reduce trace zig-zag (#12)#97
chenchong0215 wants to merge 2 commits into
tscircuit:mainfrom
chenchong0215:feature/trace-alignment-solver

Conversation

@chenchong0215
Copy link
Copy Markdown

/claim #12

Problem

Issue #12 asks to improve the schematic layout shown in #11 (SI7021). After PartitionPackingSolver snaps chips to a packing grid, pins on adjacent chips often have small off-axis deltas that create visible zig-zag traces in the schematic.

Concrete numbers from the SI7021 repro:

  • R1.1 ↔ U1.4 zig-zag: 1.146 units
  • R2.1 ↔ U1.3 zig-zag: 1.105 units
  • SJ1 ↔ R1/R2 connections: even larger off-axis deltas

Solution

Add TraceAlignmentSolver as a post-pack pipeline phase that nudges chip positions to align strongly-connected pin pairs.

How it works

  1. Parse all strong pin connections from pinStrongConnMap
  2. For each chip with strong connections, compute average nudge that would align its pins with partner pins
  3. Clamp nudge to configurable max distance (default 0.6 units)
  4. Check AABB collision with all other chips before accepting nudge
  5. If full nudge causes overlap, try X-only or Y-only as fallback
  6. Require minimum improvement threshold to accept (prevents conflicting pulls)
  7. Run multiple passes to allow cascading improvements

Pipeline position

... → partitionPackingSolver → **traceAlignmentSolver** (final phase)

Results

Circuit Zig-Zag Before Zig-Zag After Reduction
SI7021 0.399 0.199 51.7%
RP2040Circuit 0.203 0.000 100%
ExampleCircuit04 0 overlaps 0 overlaps preserved

Tests

  • 4 new tests across 2 test files
  • All 14 existing tests still pass (9 pass, 1 skip, 0 fail)
  • No new overlaps introduced

Differentiation vs other PRs

Files touched

  • lib/solvers/TraceAlignmentSolver/TraceAlignmentSolver.ts (new)
  • lib/solvers/LayoutPipelineSolver/LayoutPipelineSolver.ts (register phase)
  • tests/TraceAlignmentSolver/TraceAlignmentSolver01.test.ts (new)
  • tests/TraceAlignmentSolver/TraceAlignmentSolverPipeline.test.ts (new)

…ayouts

Addresses issue tscircuit#12 - improves schematic layout by aligning strongly-connected pin pairs after partition packing.

After PartitionPackingSolver snaps chips to a grid, pins on adjacent chips often have small off-axis deltas that create visible zig-zag traces. TraceAlignmentSolver runs as a post-pack phase that:

- Identifies all strong pin connections from pinStrongConnMap
- Computes per-connection zig-zag (off-axis delta between connected pins)
- Nudges chip positions to minimize zig-zag using average alignment displacement
- Rejects nudges that would cause chip overlaps (AABB collision detection)
- Falls back to single-axis nudges if combined nudge causes overlap
- Requires minimum improvement threshold to accept any nudge

Results:
- SI7021 repro: 51.7% zig-zag reduction (0.399 → 0.199)
- RP2040Circuit: zig-zag reduced to 0.000 in pipeline integration
- No new overlaps introduced
- All existing tests pass (9 pass, 1 skip, 0 fail)

Pipeline integration: runs as final phase after PartitionPackingSolver.

/claim tscircuit#12
@vercel
Copy link
Copy Markdown

vercel Bot commented May 12, 2026

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

A member of the Team first needs to authorize it.

- Make maxNudge/minImprovement/passes optional in TraceAlignmentSolverInput
- Add null check for placement2 in wouldOverlap()
- Change buildStrongConnectionPairs/computeWorldPinPos from private to public
- Apply biome formatting
@chenchong0215
Copy link
Copy Markdown
Author

Hi @seveibar 👋 All CI checks are passing. Would appreciate a review when you get a chance. Thanks! (fixes #12)

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