@tscircuit/matchpack 0.0.6 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { GraphicsObject } from 'graphics-debug';
2
2
  import { Point, Bounds } from '@tscircuit/math-utils';
3
- import { PhasedPackSolver } from 'calculate-packing';
3
+ import { PackSolver2 } from 'calculate-packing';
4
4
 
5
5
  declare class BaseSolver {
6
6
  MAX_ITERATIONS: number;
@@ -120,7 +120,7 @@ type OutputLayout = {
120
120
  declare class SingleInnerPartitionPackingSolver extends BaseSolver {
121
121
  inputProblem: InputProblem;
122
122
  layout: OutputLayout | null;
123
- phasedPackSolver: PhasedPackSolver | null;
123
+ activeSubSolver: PackSolver2 | null;
124
124
  constructor(inputProblem: InputProblem);
125
125
  _step(): void;
126
126
  private createPackInput;
@@ -164,7 +164,7 @@ declare class PartitionPackingSolver extends BaseSolver {
164
164
  packedPartitions: PackedPartition[];
165
165
  inputProblem: InputProblem;
166
166
  finalLayout: OutputLayout | null;
167
- phasedPackSolver: PhasedPackSolver | null;
167
+ packSolver2: PackSolver2 | null;
168
168
  constructor(input: PartitionPackingSolverInput);
169
169
  _step(): void;
170
170
  private organizePackedPartitions;
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // lib/solvers/BaseSolver.ts
2
2
  var BaseSolver = class {
3
- MAX_ITERATIONS = 1e3;
3
+ MAX_ITERATIONS = 1e5;
4
4
  solved = false;
5
5
  failed = false;
6
6
  iterations = 0;
@@ -453,31 +453,127 @@ var ChipPartitionsSolver = class extends BaseSolver {
453
453
  };
454
454
 
455
455
  // lib/solvers/PackInnerPartitionsSolver/SingleInnerPartitionPackingSolver.ts
456
- import { PhasedPackSolver } from "calculate-packing";
456
+ import { PackSolver2 } from "calculate-packing";
457
+
458
+ // lib/utils/networkFiltering.ts
459
+ function createFilteredNetworkMapping(inputProblem) {
460
+ const pinToNetworkMap = /* @__PURE__ */ new Map();
461
+ const filteredPins = /* @__PURE__ */ new Set();
462
+ const strongConnectedChipSides = /* @__PURE__ */ new Map();
463
+ for (const [connKey, connected] of Object.entries(
464
+ inputProblem.pinStrongConnMap
465
+ )) {
466
+ if (!connected) continue;
467
+ const pins = connKey.split("-");
468
+ if (pins.length === 2 && pins[0] && pins[1]) {
469
+ const pin1 = inputProblem.chipPinMap[pins[0]];
470
+ const pin2 = inputProblem.chipPinMap[pins[1]];
471
+ if (pin1 && pin2) {
472
+ const chip1Id = pins[0].split(".")[0];
473
+ const chip2Id = pins[1].split(".")[0];
474
+ if (chip1Id && chip2Id && chip1Id !== chip2Id) {
475
+ const key1 = `${chip1Id}-${chip2Id}`;
476
+ const key2 = `${chip2Id}-${chip1Id}`;
477
+ if (!strongConnectedChipSides.has(key1)) {
478
+ strongConnectedChipSides.set(key1, /* @__PURE__ */ new Set());
479
+ }
480
+ if (!strongConnectedChipSides.has(key2)) {
481
+ strongConnectedChipSides.set(key2, /* @__PURE__ */ new Set());
482
+ }
483
+ strongConnectedChipSides.get(key1).add(pin1.side);
484
+ strongConnectedChipSides.get(key2).add(pin2.side);
485
+ }
486
+ }
487
+ }
488
+ }
489
+ for (const [connKey, connected] of Object.entries(inputProblem.netConnMap)) {
490
+ if (!connected) continue;
491
+ const [pinId, netId] = connKey.split("-");
492
+ if (pinId && netId) {
493
+ const pin = inputProblem.chipPinMap[pinId];
494
+ if (!pin) continue;
495
+ const chipId = pinId.split(".")[0];
496
+ let shouldIncludeInNetwork = true;
497
+ for (const [
498
+ strongKey,
499
+ strongSides
500
+ ] of strongConnectedChipSides.entries()) {
501
+ const [fromChip, toChip] = strongKey.split("-");
502
+ if (fromChip === chipId) {
503
+ for (const [otherConnKey, otherConnected] of Object.entries(
504
+ inputProblem.netConnMap
505
+ )) {
506
+ if (!otherConnected) continue;
507
+ const [otherPinId, otherNetId] = otherConnKey.split("-");
508
+ if (otherNetId === netId && otherPinId && otherPinId !== pinId) {
509
+ const otherPin = inputProblem.chipPinMap[otherPinId];
510
+ if (!otherPin) continue;
511
+ const otherChipId = otherPinId.split(".")[0];
512
+ if (otherChipId === toChip) {
513
+ if (!strongSides.has(otherPin.side)) {
514
+ shouldIncludeInNetwork = false;
515
+ break;
516
+ }
517
+ }
518
+ }
519
+ }
520
+ }
521
+ }
522
+ if (shouldIncludeInNetwork) {
523
+ pinToNetworkMap.set(pinId, netId);
524
+ } else {
525
+ const disconnectedNetworkId = `${pinId}_opposite-strong-side-disconnected`;
526
+ pinToNetworkMap.set(pinId, disconnectedNetworkId);
527
+ filteredPins.add(pinId);
528
+ }
529
+ }
530
+ }
531
+ for (const [connKey, connected] of Object.entries(
532
+ inputProblem.pinStrongConnMap
533
+ )) {
534
+ if (!connected) continue;
535
+ const pins = connKey.split("-");
536
+ if (pins.length === 2 && pins[0] && pins[1]) {
537
+ const existingNet = pinToNetworkMap.get(pins[0]) || pinToNetworkMap.get(pins[1]);
538
+ if (existingNet) {
539
+ pinToNetworkMap.set(pins[0], existingNet);
540
+ pinToNetworkMap.set(pins[1], existingNet);
541
+ } else {
542
+ pinToNetworkMap.set(pins[0], connKey);
543
+ pinToNetworkMap.set(pins[1], connKey);
544
+ }
545
+ }
546
+ }
547
+ return {
548
+ pinToNetworkMap,
549
+ filteredPins
550
+ };
551
+ }
552
+
553
+ // lib/solvers/PackInnerPartitionsSolver/SingleInnerPartitionPackingSolver.ts
457
554
  var SingleInnerPartitionPackingSolver = class extends BaseSolver {
458
555
  inputProblem;
459
556
  layout = null;
460
- phasedPackSolver = null;
461
557
  constructor(inputProblem) {
462
558
  super();
463
559
  this.inputProblem = inputProblem;
464
560
  }
465
561
  _step() {
466
562
  try {
467
- if (!this.phasedPackSolver) {
563
+ if (!this.activeSubSolver) {
468
564
  const packInput = this.createPackInput();
469
- this.phasedPackSolver = new PhasedPackSolver(packInput);
470
- this.activeSubSolver = this.phasedPackSolver;
565
+ this.activeSubSolver = new PackSolver2(packInput);
566
+ this.activeSubSolver = this.activeSubSolver;
471
567
  }
472
- this.phasedPackSolver.step();
473
- if (this.phasedPackSolver.failed) {
568
+ this.activeSubSolver.step();
569
+ if (this.activeSubSolver.failed) {
474
570
  this.failed = true;
475
- this.error = `PhasedPackSolver failed: ${this.phasedPackSolver.error}`;
571
+ this.error = `PackSolver2 failed: ${this.activeSubSolver.error}`;
476
572
  return;
477
573
  }
478
- if (this.phasedPackSolver.solved) {
574
+ if (this.activeSubSolver.solved) {
479
575
  this.layout = this.createLayoutFromPackingResult(
480
- this.phasedPackSolver.getResult()
576
+ this.activeSubSolver.packedComponents
481
577
  );
482
578
  this.solved = true;
483
579
  this.activeSubSolver = null;
@@ -488,32 +584,7 @@ var SingleInnerPartitionPackingSolver = class extends BaseSolver {
488
584
  }
489
585
  }
490
586
  createPackInput() {
491
- const pinToNetworkMap = /* @__PURE__ */ new Map();
492
- for (const [connKey, connected] of Object.entries(
493
- this.inputProblem.netConnMap
494
- )) {
495
- if (!connected) continue;
496
- const [pinId, netId] = connKey.split("-");
497
- if (pinId && netId) {
498
- pinToNetworkMap.set(pinId, netId);
499
- }
500
- }
501
- for (const [connKey, connected] of Object.entries(
502
- this.inputProblem.pinStrongConnMap
503
- )) {
504
- if (!connected) continue;
505
- const pins = connKey.split("-");
506
- if (pins.length === 2 && pins[0] && pins[1]) {
507
- const existingNet = pinToNetworkMap.get(pins[0]) || pinToNetworkMap.get(pins[1]);
508
- if (existingNet) {
509
- pinToNetworkMap.set(pins[0], existingNet);
510
- pinToNetworkMap.set(pins[1], existingNet);
511
- } else {
512
- pinToNetworkMap.set(pins[0], connKey);
513
- pinToNetworkMap.set(pins[1], connKey);
514
- }
515
- }
516
- }
587
+ const { pinToNetworkMap } = createFilteredNetworkMapping(this.inputProblem);
517
588
  const packComponents = Object.entries(this.inputProblem.chipMap).map(
518
589
  ([chipId, chip]) => {
519
590
  const pads = [];
@@ -572,8 +643,8 @@ var SingleInnerPartitionPackingSolver = class extends BaseSolver {
572
643
  };
573
644
  }
574
645
  visualize() {
575
- if (this.phasedPackSolver && !this.solved) {
576
- return this.phasedPackSolver.visualize();
646
+ if (this.activeSubSolver && !this.solved) {
647
+ return this.activeSubSolver.visualize();
577
648
  }
578
649
  if (!this.layout) {
579
650
  return super.visualize();
@@ -653,12 +724,12 @@ var PackInnerPartitionsSolver = class extends BaseSolver {
653
724
  };
654
725
 
655
726
  // lib/solvers/PartitionPackingSolver/PartitionPackingSolver.ts
656
- import { PhasedPackSolver as PhasedPackSolver2 } from "calculate-packing";
727
+ import { PackSolver2 as PackSolver22 } from "calculate-packing";
657
728
  var PartitionPackingSolver = class extends BaseSolver {
658
729
  packedPartitions;
659
730
  inputProblem;
660
731
  finalLayout = null;
661
- phasedPackSolver = null;
732
+ packSolver2 = null;
662
733
  constructor(input) {
663
734
  super();
664
735
  this.packedPartitions = input.packedPartitions;
@@ -680,20 +751,20 @@ var PartitionPackingSolver = class extends BaseSolver {
680
751
  return;
681
752
  }
682
753
  const partitionGroups = this.organizePackedPartitions();
683
- if (!this.phasedPackSolver) {
754
+ if (!this.packSolver2) {
684
755
  const packInput = this.createPackInput(partitionGroups);
685
- this.phasedPackSolver = new PhasedPackSolver2(packInput);
686
- this.activeSubSolver = this.phasedPackSolver;
756
+ this.packSolver2 = new PackSolver22(packInput);
757
+ this.activeSubSolver = this.packSolver2;
687
758
  }
688
- this.phasedPackSolver.step();
689
- if (this.phasedPackSolver.failed) {
759
+ this.packSolver2.step();
760
+ if (this.packSolver2.failed) {
690
761
  this.failed = true;
691
- this.error = `PhasedPackSolver failed: ${this.phasedPackSolver.error}`;
762
+ this.error = `PackSolver2 failed: ${this.packSolver2.error}`;
692
763
  return;
693
764
  }
694
- if (this.phasedPackSolver.solved) {
765
+ if (this.packSolver2.solved) {
695
766
  const packedLayout = this.applyPackingResult(
696
- this.phasedPackSolver.getResult(),
767
+ this.packSolver2.packedComponents,
697
768
  partitionGroups
698
769
  );
699
770
  this.finalLayout = packedLayout;
@@ -876,8 +947,8 @@ var PartitionPackingSolver = class extends BaseSolver {
876
947
  };
877
948
  }
878
949
  visualize() {
879
- if (this.phasedPackSolver && !this.solved) {
880
- return this.phasedPackSolver.visualize();
950
+ if (this.packSolver2 && !this.solved) {
951
+ return this.packSolver2.visualize();
881
952
  }
882
953
  if (!this.finalLayout) {
883
954
  return super.visualize();
@@ -979,7 +1050,7 @@ var LayoutPipelineSolver = class extends BaseSolver {
979
1050
  constructor(inputProblem) {
980
1051
  super();
981
1052
  this.inputProblem = inputProblem;
982
- this.MAX_ITERATIONS = 1e3;
1053
+ this.MAX_ITERATIONS = 1e6;
983
1054
  this.startTimeOfPhase = {};
984
1055
  this.endTimeOfPhase = {};
985
1056
  this.timeSpentOnPhase = {};
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@tscircuit/matchpack",
3
3
  "main": "dist/index.js",
4
4
  "type": "module",
5
- "version": "0.0.6",
5
+ "version": "0.0.8",
6
6
  "files": [
7
7
  "dist"
8
8
  ],
@@ -10,7 +10,8 @@
10
10
  "start": "cosmos",
11
11
  "build": "tsup-node --format esm --dts --clean ./lib/index.ts",
12
12
  "format": "biome format --write .",
13
- "format:check": "biome format ."
13
+ "format:check": "biome format .",
14
+ "build:site": "cosmos-export"
14
15
  },
15
16
  "devDependencies": {
16
17
  "@biomejs/biome": "^2.1.3",
@@ -20,7 +21,7 @@
20
21
  "@tscircuit/schematic-viewer": "^2.0.26",
21
22
  "@types/bun": "latest",
22
23
  "bpc-graph": "^0.0.66",
23
- "calculate-packing": "^0.0.19",
24
+ "calculate-packing": "^0.0.27",
24
25
  "circuit-json": "^0.0.226",
25
26
  "graphics-debug": "^0.0.62",
26
27
  "react-cosmos": "^7.0.0",