Skip to content

Commit d26d0a8

Browse files
committed
WIP
1 parent 290afb5 commit d26d0a8

File tree

1 file changed

+76
-54
lines changed

1 file changed

+76
-54
lines changed

scripts/make-data-related-to-linear-regression-for-better-pf-for-port-point-calculation.ts

Lines changed: 76 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,49 @@ import { getIntraNodeCrossings } from "lib/utils/getIntraNodeCrossings"
55
import { HighDensitySolver } from "lib/solvers/HighDensitySolver/HighDensitySolver"
66

77
const settings = [
8-
{ width: 1, height: 1, z: 1 },
9-
{ width: 0.1, height: 0.5, z: 1 },
10-
{ width: 0.5, height: 0.1, z: 1 },
11-
{ width: 1, height: 1, z: 1 },
12-
{ width: 2.9, height: 1.9, z: 1 },
8+
{ width: 1, height: 2.83, z: 1 },
9+
{ width: 2.83, height: 1, z: 1 },
10+
{ width: 81.574, height: 50.87, z: 1 },
11+
{ width: 30.41, height: 68.33, z: 1 },
12+
{ width: 10.86, height: 29.44, z: 1 },
13+
{ width: 5.43, height: 16.31, z: 1 },
14+
{ width: 0.839, height: 0.206, z: 1 },
15+
{ width: 3.19, height: 1.59, z: 1 },
1316
]
1417

1518
const connectionVariants = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
1619
const viaSizesVariants = [0.1, 0.2, 0.3, 0.4, 0.5]
1720
const traceWidthsVariants = [0.05, 0.1, 0.15, 0.2, 0.25]
1821

19-
type Features = {
20-
top_edge_ports_normalized_to_width: number
21-
right_edge_ports_normalized_to_height: number
22-
bottom_edge_ports_normalized_to_width: number
23-
left_edge_ports_normalized_to_height: number
24-
same_layer_crossings_normalized_to_if_all_where_layercrossing: number
25-
layer_transitions_normalized_to_if_all_connections_where_transition: number
26-
single_via_area_normalized_to_area: number
27-
two_via_area_normalized_to_area: number
28-
board_aspect_ratio_not_normalized: number
29-
total_trace_distance_normalized_to_diagonal: number
30-
same_net_crossings_normalized_to_segments: number
22+
const FEATURE_SCHEMA = {
23+
top_edge_ports_normalized_to_width: { useForGeometric: true },
24+
right_edge_ports_normalized_to_height: { useForGeometric: true },
25+
bottom_edge_ports_normalized_to_width: { useForGeometric: true },
26+
left_edge_ports_normalized_to_height: { useForGeometric: true },
27+
same_layer_crossings_normalized_to_if_all_where_layercrossing: {
28+
useForGeometric: false,
29+
},
30+
layer_transitions_normalized_to_if_all_connections_where_transition: {
31+
useForGeometric: false,
32+
},
33+
single_via_area_normalized_to_area: { useForGeometric: true },
34+
two_via_area_normalized_to_area: { useForGeometric: true },
35+
board_aspect_ratio_not_normalized: { useForGeometric: true },
36+
total_trace_distance_normalized_to_diagonal: { useForGeometric: true },
37+
same_net_crossings_normalized_to_segments: { useForGeometric: false },
38+
} as const
39+
40+
type FeatureKey = keyof typeof FEATURE_SCHEMA
41+
type Features = Record<FeatureKey, number> & {
3142
did_hight_density_solver_find_solution?: boolean
3243
}
3344

45+
type GeometricFeatureKey = {
46+
[K in FeatureKey]: (typeof FEATURE_SCHEMA)[K]["useForGeometric"] extends true
47+
? K
48+
: never
49+
}[FeatureKey]
50+
3451
const computeFeaturesForMl = (params: {
3552
portPoints: NodeWithPortPoints["portPoints"]
3653
node: CapacityMeshNode
@@ -151,16 +168,7 @@ type Candidate = {
151168
traceWidth: number
152169
}
153170

154-
type GeometricFeatures = {
155-
top_edge_ports_normalized_to_width: number
156-
right_edge_ports_normalized_to_height: number
157-
bottom_edge_ports_normalized_to_width: number
158-
left_edge_ports_normalized_to_height: number
159-
single_via_occupancy_normalized_to_area: number
160-
two_via_occupancy_normalized_to_area: number
161-
board_aspect_ratio_normalized_to_geometry: number
162-
port_distance_normalized_to_diagonal: number
163-
}
171+
type GeometricFeatures = Pick<Features, GeometricFeatureKey>
164172

165173
const getGeometricFeatures = (candidate: Candidate): GeometricFeatures => {
166174
const { node, nodeWithPortPoints, viaSize } = candidate
@@ -201,10 +209,10 @@ const getGeometricFeatures = (candidate: Candidate): GeometricFeatures => {
201209
right_edge_ports_normalized_to_height: safeDiv(rightPortCount, node.height),
202210
bottom_edge_ports_normalized_to_width: safeDiv(bottomPortCount, node.width),
203211
left_edge_ports_normalized_to_height: safeDiv(leftPortCount, node.height),
204-
single_via_occupancy_normalized_to_area: safeDiv(viaArea, area),
205-
two_via_occupancy_normalized_to_area: safeDiv(viaArea * 2, area),
206-
board_aspect_ratio_normalized_to_geometry: safeDiv(node.width, node.height),
207-
port_distance_normalized_to_diagonal: safeDiv(
212+
single_via_area_normalized_to_area: safeDiv(viaArea, area),
213+
two_via_area_normalized_to_area: safeDiv(viaArea * 2, area),
214+
board_aspect_ratio_not_normalized: safeDiv(node.width, node.height),
215+
total_trace_distance_normalized_to_diagonal: safeDiv(
208216
totalTraceDistance,
209217
numNet * diagonal,
210218
),
@@ -217,10 +225,10 @@ const featuresToVector = (features: GeometricFeatures): number[] => {
217225
features.right_edge_ports_normalized_to_height,
218226
features.bottom_edge_ports_normalized_to_width,
219227
features.left_edge_ports_normalized_to_height,
220-
features.single_via_occupancy_normalized_to_area,
221-
features.two_via_occupancy_normalized_to_area,
222-
features.board_aspect_ratio_normalized_to_geometry,
223-
features.port_distance_normalized_to_diagonal,
228+
features.single_via_area_normalized_to_area,
229+
features.two_via_area_normalized_to_area,
230+
features.board_aspect_ratio_not_normalized,
231+
features.total_trace_distance_normalized_to_diagonal,
224232
]
225233
}
226234

@@ -361,6 +369,19 @@ const isInformationSaturationReached = (
361369
return stdDev < 0.01
362370
}
363371

372+
const saveDatasetToJson = async (
373+
dataset: Array<Features & { cost: number }>,
374+
filename: string,
375+
) => {
376+
const fs = await import("node:fs/promises")
377+
const path = await import("node:path")
378+
379+
const outputPath = path.join(process.cwd(), filename)
380+
const jsonContent = JSON.stringify(dataset, null, 2)
381+
382+
await fs.writeFile(outputPath, jsonContent, "utf-8")
383+
}
384+
364385
async function run() {
365386
const MAX_COMPUTE = 5000
366387
const SAMPLE_SIZE = 100
@@ -374,6 +395,9 @@ async function run() {
374395
console.log(`Memory limit check enabled, batch size: ${BATCH_SIZE}`)
375396

376397
let iterationCount = 0
398+
let solvedCount = 0
399+
let failedCount = 0
400+
const TARGET_PER_CLASS = MAX_COMPUTE / 2
377401

378402
while (dataset.length < MAX_COMPUTE) {
379403
iterationCount++
@@ -439,12 +463,23 @@ async function run() {
439463

440464
hdSolver.solve()
441465

442-
dataset.push({
443-
...finalFeatures,
444-
cost,
445-
did_hight_density_solver_find_solution: hdSolver.solved,
446-
})
447-
processedGeometricFeatures.push(featuresToVector(bestGeo))
466+
if (hdSolver.solved && solvedCount < TARGET_PER_CLASS) {
467+
solvedCount++
468+
dataset.push({
469+
...finalFeatures,
470+
cost,
471+
did_hight_density_solver_find_solution: hdSolver.solved,
472+
})
473+
processedGeometricFeatures.push(featuresToVector(bestGeo))
474+
} else if (hdSolver.solved && failedCount < TARGET_PER_CLASS) {
475+
failedCount++
476+
dataset.push({
477+
...finalFeatures,
478+
cost,
479+
did_hight_density_solver_find_solution: hdSolver.solved,
480+
})
481+
processedGeometricFeatures.push(featuresToVector(bestGeo))
482+
}
448483

449484
if (dataset.length % 10 === 0) {
450485
console.log(
@@ -473,17 +508,4 @@ async function run() {
473508
return dataset
474509
}
475510

476-
const saveDatasetToJson = async (
477-
dataset: Array<Features & { cost: number }>,
478-
filename: string,
479-
) => {
480-
const fs = await import("node:fs/promises")
481-
const path = await import("node:path")
482-
483-
const outputPath = path.join(process.cwd(), filename)
484-
const jsonContent = JSON.stringify(dataset, null, 2)
485-
486-
await fs.writeFile(outputPath, jsonContent, "utf-8")
487-
}
488-
489511
run()

0 commit comments

Comments
 (0)