Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -64,6 +71,60 @@ export class SingleInnerPartitionPackingSolver extends BaseSolver {
}
}

private createLinearPackingResult(): OutputLayout {
const chipPlacements: Record<string, Placement> = {}
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({
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Loading