Skip to content

Commit eda30fa

Browse files
committed
Integrate via hypergraph solver wip
1 parent a32441d commit eda30fa

File tree

15 files changed

+1267
-12
lines changed

15 files changed

+1267
-12
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"nodeWithPortPoints": {
3+
"capacityMeshNodeId": "cmn_via_01",
4+
"center": {
5+
"x": 0,
6+
"y": 0
7+
},
8+
"width": 10,
9+
"height": 10,
10+
"portPoints": [
11+
{
12+
"portPointId": "pp1",
13+
"x": -5,
14+
"y": -3,
15+
"z": 0,
16+
"connectionName": "net_1",
17+
"rootConnectionName": "net_1"
18+
},
19+
{
20+
"portPointId": "pp2",
21+
"x": 5,
22+
"y": 3,
23+
"z": 0,
24+
"connectionName": "net_1",
25+
"rootConnectionName": "net_1"
26+
},
27+
{
28+
"portPointId": "pp3",
29+
"x": -5,
30+
"y": 3,
31+
"z": 0,
32+
"connectionName": "net_2",
33+
"rootConnectionName": "net_2"
34+
},
35+
{
36+
"portPointId": "pp4",
37+
"x": 5,
38+
"y": -3,
39+
"z": 0,
40+
"connectionName": "net_2",
41+
"rootConnectionName": "net_2"
42+
}
43+
],
44+
"availableZ": [0, 1]
45+
},
46+
"colorMap": {
47+
"net_1": "#e6194b",
48+
"net_2": "#3cb44b"
49+
},
50+
"traceWidth": 0.15,
51+
"hyperParameters": {}
52+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { ViaHighDensitySolver } from "lib/solvers/ViaHighDensitySolver"
2+
import { GenericSolverDebugger } from "lib/testing/GenericSolverDebugger"
3+
import input from "./via-high-density01-input.json"
4+
5+
export default () => {
6+
const createSolver = () => {
7+
return new ViaHighDensitySolver({
8+
nodeWithPortPoints: input.nodeWithPortPoints as any,
9+
colorMap: input.colorMap,
10+
hyperParameters: input.hyperParameters,
11+
traceWidth: input.traceWidth,
12+
})
13+
}
14+
15+
return <GenericSolverDebugger createSolver={createSolver} />
16+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"nodeWithPortPoints": {
3+
"capacityMeshNodeId": "cmn_via_02",
4+
"center": {
5+
"x": 5,
6+
"y": 5
7+
},
8+
"width": 15,
9+
"height": 12,
10+
"portPoints": [
11+
{
12+
"portPointId": "pp1",
13+
"x": -2.5,
14+
"y": -1,
15+
"z": 0,
16+
"connectionName": "signal_a",
17+
"rootConnectionName": "signal_a"
18+
},
19+
{
20+
"portPointId": "pp2",
21+
"x": 12.5,
22+
"y": 11,
23+
"z": 0,
24+
"connectionName": "signal_a",
25+
"rootConnectionName": "signal_a"
26+
},
27+
{
28+
"portPointId": "pp3",
29+
"x": -2.5,
30+
"y": 5,
31+
"z": 0,
32+
"connectionName": "signal_b",
33+
"rootConnectionName": "signal_b"
34+
},
35+
{
36+
"portPointId": "pp4",
37+
"x": 12.5,
38+
"y": 5,
39+
"z": 0,
40+
"connectionName": "signal_b",
41+
"rootConnectionName": "signal_b"
42+
},
43+
{
44+
"portPointId": "pp5",
45+
"x": 5,
46+
"y": -1,
47+
"z": 0,
48+
"connectionName": "signal_c",
49+
"rootConnectionName": "signal_c"
50+
},
51+
{
52+
"portPointId": "pp6",
53+
"x": 5,
54+
"y": 11,
55+
"z": 0,
56+
"connectionName": "signal_c",
57+
"rootConnectionName": "signal_c"
58+
}
59+
],
60+
"availableZ": [0, 1]
61+
},
62+
"colorMap": {
63+
"signal_a": "#e6194b",
64+
"signal_b": "#3cb44b",
65+
"signal_c": "#4363d8"
66+
},
67+
"traceWidth": 0.15,
68+
"hyperParameters": {
69+
"TILE_SIZE": 4
70+
}
71+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { ViaHighDensitySolver } from "lib/solvers/ViaHighDensitySolver"
2+
import { GenericSolverDebugger } from "lib/testing/GenericSolverDebugger"
3+
import input from "./via-high-density02-input.json"
4+
5+
export default () => {
6+
const createSolver = () => {
7+
return new ViaHighDensitySolver({
8+
nodeWithPortPoints: input.nodeWithPortPoints as any,
9+
colorMap: input.colorMap,
10+
hyperParameters: input.hyperParameters,
11+
traceWidth: input.traceWidth,
12+
})
13+
}
14+
15+
return <GenericSolverDebugger createSolver={createSolver} />
16+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
{
2+
"nodeWithPortPoints": {
3+
"capacityMeshNodeId": "cmn_via_03",
4+
"center": {
5+
"x": 0,
6+
"y": 0
7+
},
8+
"width": 20,
9+
"height": 20,
10+
"portPoints": [
11+
{
12+
"portPointId": "pp1",
13+
"x": -10,
14+
"y": -8,
15+
"z": 0,
16+
"connectionName": "power",
17+
"rootConnectionName": "power"
18+
},
19+
{
20+
"portPointId": "pp2",
21+
"x": 10,
22+
"y": 8,
23+
"z": 0,
24+
"connectionName": "power",
25+
"rootConnectionName": "power"
26+
},
27+
{
28+
"portPointId": "pp3",
29+
"x": -10,
30+
"y": 0,
31+
"z": 0,
32+
"connectionName": "ground",
33+
"rootConnectionName": "ground"
34+
},
35+
{
36+
"portPointId": "pp4",
37+
"x": 10,
38+
"y": 0,
39+
"z": 0,
40+
"connectionName": "ground",
41+
"rootConnectionName": "ground"
42+
},
43+
{
44+
"portPointId": "pp5",
45+
"x": -10,
46+
"y": 8,
47+
"z": 0,
48+
"connectionName": "data_0",
49+
"rootConnectionName": "data_0"
50+
},
51+
{
52+
"portPointId": "pp6",
53+
"x": 10,
54+
"y": -8,
55+
"z": 0,
56+
"connectionName": "data_0",
57+
"rootConnectionName": "data_0"
58+
},
59+
{
60+
"portPointId": "pp7",
61+
"x": 0,
62+
"y": -10,
63+
"z": 0,
64+
"connectionName": "data_1",
65+
"rootConnectionName": "data_1"
66+
},
67+
{
68+
"portPointId": "pp8",
69+
"x": 0,
70+
"y": 10,
71+
"z": 0,
72+
"connectionName": "data_1",
73+
"rootConnectionName": "data_1"
74+
}
75+
],
76+
"availableZ": [0, 1]
77+
},
78+
"colorMap": {
79+
"power": "#e6194b",
80+
"ground": "#3cb44b",
81+
"data_0": "#4363d8",
82+
"data_1": "#f58231"
83+
},
84+
"traceWidth": 0.15,
85+
"hyperParameters": {
86+
"TILE_SIZE": 5,
87+
"SHUFFLE_SEED": 42
88+
}
89+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { ViaHighDensitySolver } from "lib/solvers/ViaHighDensitySolver"
2+
import { GenericSolverDebugger } from "lib/testing/GenericSolverDebugger"
3+
import input from "./via-high-density03-input.json"
4+
5+
export default () => {
6+
const createSolver = () => {
7+
return new ViaHighDensitySolver({
8+
nodeWithPortPoints: input.nodeWithPortPoints as any,
9+
colorMap: input.colorMap,
10+
hyperParameters: input.hyperParameters,
11+
traceWidth: input.traceWidth,
12+
})
13+
}
14+
15+
return <GenericSolverDebugger createSolver={createSolver} />
16+
}

lib/solvers/HighDensitySolver/HighDensitySolver.ts

Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ import { combineVisualizations } from "lib/utils/combineVisualizations"
1111
import { ConnectivityMap } from "circuit-json-to-connectivity-map"
1212
import { mergeRouteSegments } from "lib/utils/mergeRouteSegments"
1313
import { getGlobalInMemoryCache } from "lib/cache/setupGlobalCaches"
14+
import {
15+
ViaHighDensitySolver,
16+
ViaHighDensityHyperParameters,
17+
} from "../ViaHighDensitySolver"
1418

1519
export class HighDensitySolver extends BaseSolver {
1620
override getSolverName(): string {
@@ -27,23 +31,41 @@ export class HighDensitySolver extends BaseSolver {
2731
viaDiameter: number
2832
traceWidth: number
2933

30-
failedSolvers: (IntraNodeRouteSolver | HyperSingleIntraNodeSolver)[]
31-
activeSubSolver: IntraNodeRouteSolver | HyperSingleIntraNodeSolver | null =
32-
null
34+
failedSolvers: (
35+
| IntraNodeRouteSolver
36+
| HyperSingleIntraNodeSolver
37+
| ViaHighDensitySolver
38+
)[]
39+
activeSubSolver:
40+
| IntraNodeRouteSolver
41+
| HyperSingleIntraNodeSolver
42+
| ViaHighDensitySolver
43+
| null = null
3344
connMap?: ConnectivityMap
3445

46+
/** Enable via high-density routing using ViaGraphSolver */
47+
useViaRouting: boolean
48+
/** Hyper parameters for ViaHighDensitySolver when useViaRouting is enabled */
49+
viaHyperParameters?: ViaHighDensityHyperParameters
50+
3551
constructor({
3652
nodePortPoints,
3753
colorMap,
3854
connMap,
3955
viaDiameter,
4056
traceWidth,
57+
useViaRouting,
58+
viaHyperParameters,
4159
}: {
4260
nodePortPoints: NodeWithPortPoints[]
4361
colorMap?: Record<string, string>
4462
connMap?: ConnectivityMap
4563
viaDiameter?: number
4664
traceWidth?: number
65+
/** Enable via high-density routing using ViaGraphSolver from @tscircuit/hypergraph */
66+
useViaRouting?: boolean
67+
/** Hyper parameters for ViaHighDensitySolver when useViaRouting is enabled */
68+
viaHyperParameters?: ViaHighDensityHyperParameters
4769
}) {
4870
super()
4971
this.unsolvedNodePortPoints = nodePortPoints
@@ -54,6 +76,8 @@ export class HighDensitySolver extends BaseSolver {
5476
this.MAX_ITERATIONS = 1e6
5577
this.viaDiameter = viaDiameter ?? this.defaultViaDiameter
5678
this.traceWidth = traceWidth ?? this.defaultTraceThickness
79+
this.useViaRouting = useViaRouting ?? false
80+
this.viaHyperParameters = viaHyperParameters
5781
}
5882

5983
/**
@@ -65,7 +89,22 @@ export class HighDensitySolver extends BaseSolver {
6589
if (this.activeSubSolver) {
6690
this.activeSubSolver.step()
6791
if (this.activeSubSolver.solved) {
68-
this.routes.push(...this.activeSubSolver.solvedRoutes)
92+
// Handle different solver output types
93+
if (this.activeSubSolver instanceof ViaHighDensitySolver) {
94+
// Convert ViaHighDensitySolver output to HighDensityIntraNodeRoute format
95+
for (const route of this.activeSubSolver.solvedRoutes) {
96+
this.routes.push({
97+
connectionName: route.connectionName,
98+
rootConnectionName: route.rootConnectionName,
99+
traceThickness: route.traceThickness,
100+
viaDiameter: this.viaDiameter,
101+
route: route.route,
102+
vias: route.viaRegions.map((v) => v.center),
103+
})
104+
}
105+
} else {
106+
this.routes.push(...this.activeSubSolver.solvedRoutes)
107+
}
69108
this.activeSubSolver = null
70109
} else if (this.activeSubSolver.failed) {
71110
this.failedSolvers.push(this.activeSubSolver)
@@ -90,13 +129,24 @@ export class HighDensitySolver extends BaseSolver {
90129
}
91130
const node = this.unsolvedNodePortPoints.pop()!
92131

93-
this.activeSubSolver = new HyperSingleIntraNodeSolver({
94-
nodeWithPortPoints: node,
95-
colorMap: this.colorMap,
96-
connMap: this.connMap,
97-
viaDiameter: this.viaDiameter,
98-
traceWidth: this.traceWidth,
99-
})
132+
// Use ViaHighDensitySolver when useViaRouting is enabled
133+
if (this.useViaRouting) {
134+
this.activeSubSolver = new ViaHighDensitySolver({
135+
nodeWithPortPoints: node,
136+
colorMap: this.colorMap,
137+
connMap: this.connMap,
138+
traceWidth: this.traceWidth,
139+
hyperParameters: this.viaHyperParameters,
140+
})
141+
} else {
142+
this.activeSubSolver = new HyperSingleIntraNodeSolver({
143+
nodeWithPortPoints: node,
144+
colorMap: this.colorMap,
145+
connMap: this.connMap,
146+
viaDiameter: this.viaDiameter,
147+
traceWidth: this.traceWidth,
148+
})
149+
}
100150
this.updateCacheStats()
101151
}
102152

0 commit comments

Comments
 (0)