From 4de545aca54a4b377994d439243e874327324ee8 Mon Sep 17 00:00:00 2001 From: EmptyPokerCards <148206721+EmptyPokerCards@users.noreply.github.com> Date: Mon, 25 May 2026 16:49:51 +0700 Subject: [PATCH 1/2] Update SingleInnerPartitionPackingSolver.ts --- .../SingleInnerPartitionPackingSolver.ts | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/lib/solvers/PackInnerPartitionsSolver/SingleInnerPartitionPackingSolver.ts b/lib/solvers/PackInnerPartitionsSolver/SingleInnerPartitionPackingSolver.ts index 88db103..8580c11 100644 --- a/lib/solvers/PackInnerPartitionsSolver/SingleInnerPartitionPackingSolver.ts +++ b/lib/solvers/PackInnerPartitionsSolver/SingleInnerPartitionPackingSolver.ts @@ -38,6 +38,13 @@ export class SingleInnerPartitionPackingSolver extends BaseSolver { } override _step() { + // Intercept decoupling capacitors and use deterministic linear placement + if (this.partitionInputProblem.partitionType === "decoupling_caps") { + this.layout = this.createLinearPackingResult() + this.solved = true + return + } + // Initialize PackSolver2 if not already created if (!this.activeSubSolver) { const packInput = this.createPackInput() @@ -64,6 +71,60 @@ export class SingleInnerPartitionPackingSolver extends BaseSolver { } } + private createLinearPackingResult(): OutputLayout { + const chipPlacements: Record = {} + let minGap = this.partitionInputProblem.chipGap + if (this.partitionInputProblem.partitionType === "decoupling_caps") { + minGap = this.partitionInputProblem.decouplingCapsGap ?? minGap + } + + const chips = Object.values(this.partitionInputProblem.chipMap) + + // Sort chips deterministically + chips.sort((a, b) => a.chipId.localeCompare(b.chipId)) + + // Determine stacking direction based on pin locations + // If pins are on left/right (x-axis), we stack them vertically (y-axis) + // If pins are on top/bottom (y-axis), we stack them horizontally (x-axis) + let stackDir: "x" | "y" = "y" + let ccwRotationDegrees = 0 + + if (chips.length > 0) { + const firstChip = chips[0] + if (firstChip.pins.length >= 2) { + const pin1 = this.partitionInputProblem.chipPinMap[firstChip.pins[0]] + const pin2 = this.partitionInputProblem.chipPinMap[firstChip.pins[1]] + if (pin1 && pin2) { + if (pin1.offset.x !== pin2.offset.x) { + stackDir = "y" + ccwRotationDegrees = 90 + } else { + stackDir = "x" + ccwRotationDegrees = 0 + } + } + } + } + + let currentPos = 0 + + for (const chip of chips) { + chipPlacements[chip.chipId] = { + x: stackDir === "x" ? currentPos : 0, + y: stackDir === "y" ? currentPos : 0, + ccwRotationDegrees, + } + + const chipSizeInStackDir = stackDir === "x" ? chip.size.x : chip.size.y + currentPos += chipSizeInStackDir + minGap + } + + return { + chipPlacements, + groupPlacements: {}, + } + } + private createPackInput(): PackInput { // Fall back to filtered mapping (weak + strong) const pinToNetworkMap = createFilteredNetworkMapping({ From 438c1512cdf30975396cb5e2b61d2cec339f242e Mon Sep 17 00:00:00 2001 From: EmptyPokerCards <148206721+EmptyPokerCards@users.noreply.github.com> Date: Mon, 25 May 2026 16:50:27 +0700 Subject: [PATCH 2/2] Update package.json --- package.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 1fd506e..06134fb 100644 --- a/package.json +++ b/package.json @@ -26,10 +26,14 @@ "graphics-debug": "^0.0.64", "react-cosmos": "^7.0.0", "react-cosmos-plugin-vite": "^7.0.0", - "tscircuit": "^0.0.593", + "tscircuit": "^0.0.1780", "tsup": "^8.5.0" }, "peerDependencies": { "typescript": "^5" + }, + "dependencies": { + "bun": "^1.3.14", + "circuit-to-svg": "^0.0.350" } }