Don't route net-label-only nets as wire traces (#79)#307
Open
s300169140 wants to merge 1 commit into
Open
Conversation
closes tscircuit#79 Two related issues caused spurious wire traces between pins that share only a net label (no direct wire): 1. **Shared-state bug in `getConnectivityMapsFromInputProblem`** — `new ConnectivityMap(directConnMap.netMap)` retained a reference to the underlying netMap, so the subsequent `netConnMap.addConnections` calls mutated `directConnMap.netMap` too. Pins added via netConnections then appeared to be in the direct-wire connectivity. Fixed by deep-cloning before passing to the netConnMap constructor. 2. **`MspConnectionPairSolver` iterated all nets, not just direct** — `this.queuedDcNetIds = Object.keys(netConnMap.netMap)` queued every net for MSP pair creation, then used `globalConnMap.getIdsConnectedToNet` to expand. Net-label-only nets (e.g. two capacitors both labeled GND) thus produced MSP pairs which became visible traces. Fixed by queuing only direct-connection nets and reading pins from `dcConnMap`. The README documents the intended behavior: "Net connections will not be routed, net labels are placed instead." This change brings the code in line with that contract. Adds `MspConnectionPairSolver_repro79.test.ts` covering both: - the mixed case (one pin direct, another only net-labeled) - the pure case (two pins joined only via net label, no direct wire) — this is the repro61 scenario from tscircuit/core PR #1503 Updates 11 example snapshots that previously rendered spurious traces; spot-checked example12 and example21 visually — the changes are strictly *removal* of unwanted same-net trace lines, not unrelated drift. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #79.
Summary
Two related root causes produced spurious wire traces between pins that share only a net label:
1. Shared-state in
getConnectivityMapsFromInputProblem—new ConnectivityMap(directConnMap.netMap)retained a reference to the underlying netMap, so subsequentnetConnMap.addConnections(...)calls mutateddirectConnMap.netMaptoo. Pins added via netConnections appeared to be in the direct-wire connectivity. Fixed by deep-cloning before seeding.2.
MspConnectionPairSolveriterated every net, not just direct ones —queuedDcNetIds = Object.keys(netConnMap.netMap)queued every net for MSP pair creation, including net-label-only ones. The README documents the intended behavior: "Net connections will not be routed, net labels are placed instead." This change brings the code in line with that contract by queuing only direct-connection nets and reading pins fromdcConnMap.Relationship to #275
This builds on the same root-cause analysis as #275 (h/t @chengyixu) but goes further. #275 addresses the mixed case (one pin in a directConnection, another only in a netConnection) — but the pure net-label-only case (two pins sharing a net name with no direct wire between them) still produces MSP pairs and therefore visible traces.
Verified on the #275 branch:
On #275 main:
On this branch:
This is the repro61 scenario from tscircuit/core PR #1503 — and the one I think is the actual subject of this bounty issue.
Tests
Adds
tests/solvers/MspConnectionPairSolver/MspConnectionPairSolver_repro79.test.tscovering both:Updates
MspConnectionPairSolver_repro1.test.tsfromexpect(4)toexpect(2)with a comment explaining why — the previous expectation was capturing the buggy behavior (creating MST pairs for the GND netConnection).Snapshot impact
11 example snapshots updated. I spot-checked example12 and example21 — every change is removal of spurious same-net trace lines, no unrelated drift. Happy to walk through any specific example if the diff is hard to read.
Verification
bun test— 59 pass / 0 fail / 4 skip (was 47 pass / 12 fail before snapshot update)bunx tsc --noEmit— cleanbun run format:check— clean