Skip to content

Commit bd6cf67

Browse files
auto-solve debug option (tscircuit#715)
1 parent 845c8db commit bd6cf67

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

lib/testing/AutoroutingPipelineDebugger.tsx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ const PIPELINE_SOLVERS = {
5656
const PIPELINE_STORAGE_KEY = "selectedPipeline"
5757
const EFFORT_STORAGE_KEY = "selectedEffort"
5858
const LAYER_OVERRIDE_STORAGE_KEY = "selectedLayerOverride"
59+
const AUTO_SOLVE_STORAGE_KEY = "autoSolve"
5960
const AUTO_RUN_DRC_STORAGE_KEY = "autoRunDrc"
6061

6162
const parseLayerOverride = (value: string | null): LayerOverride => {
@@ -300,6 +301,19 @@ export const AutoroutingPipelineDebugger = ({
300301
}
301302
}
302303

304+
const [autoSolve, setAutoSolveState] = useState<boolean>(
305+
() => localStorage.getItem(AUTO_SOLVE_STORAGE_KEY) === "true",
306+
)
307+
308+
const setAutoSolve = (enabled: boolean) => {
309+
setAutoSolveState(enabled)
310+
try {
311+
localStorage.setItem(AUTO_SOLVE_STORAGE_KEY, String(enabled))
312+
} catch (e) {
313+
console.warn("Could not save auto-solve preference to localStorage:", e)
314+
}
315+
}
316+
303317
const [autoRunDrc, setAutoRunDrcState] = useState<boolean>(
304318
() => localStorage.getItem(AUTO_RUN_DRC_STORAGE_KEY) === "true",
305319
)
@@ -417,6 +431,7 @@ export const AutoroutingPipelineDebugger = ({
417431
() => window.localStorage.getItem("lastBreakpointNodeId") || "",
418432
)
419433
const isSolvingToBreakpointRef = useRef(false) // Ref to track breakpoint solving state
434+
const autoSolvedSolverRef = useRef<any>(null)
420435
const autoRanDrcForSolveRef = useRef(false)
421436

422437
// Reset solver
@@ -464,6 +479,26 @@ export const AutoroutingPipelineDebugger = ({
464479
}
465480
}, [isAnimating, speedLevel, solver, animationSpeed])
466481

482+
useEffect(() => {
483+
if (!autoSolve || solver.solved || solver.failed) {
484+
return
485+
}
486+
487+
if (autoSolvedSolverRef.current === solver) {
488+
return
489+
}
490+
491+
autoSolvedSolverRef.current = solver
492+
isSolvingToBreakpointRef.current = false
493+
setIsAnimating(false)
494+
495+
const startTime = performance.now() / 1000
496+
solver.solve()
497+
const endTime = performance.now() / 1000
498+
setSolveTime(endTime - startTime)
499+
setForceUpdate((prev) => prev + 1)
500+
}, [autoSolve, solver])
501+
467502
useEffect(() => {
468503
if (!solver.solved) {
469504
autoRanDrcForSolveRef.current = false
@@ -924,6 +959,8 @@ export const AutoroutingPipelineDebugger = ({
924959
onSetCanSelectObjects={setCanSelectObjects}
925960
onRunDrcChecks={handleRunDrcChecks}
926961
onRunRelaxedDrcChecks={handleRunRelaxedDrcChecks}
962+
autoSolve={autoSolve}
963+
onSetAutoSolve={setAutoSolve}
927964
autoRunDrc={autoRunDrc}
928965
onSetAutoRunDrc={setAutoRunDrc}
929966
animationSpeed={speedLevel}

lib/testing/AutoroutingPipelineMenuBar.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ interface AutoroutingPipelineMenuBarProps {
6868
onSetCanSelectObjects: (canSelect: boolean) => void
6969
onRunDrcChecks: () => void
7070
onRunRelaxedDrcChecks: () => void
71+
autoSolve: boolean
72+
onSetAutoSolve: (autoSolve: boolean) => void
7173
autoRunDrc: boolean
7274
onSetAutoRunDrc: (autoRunDrc: boolean) => void
7375
animationSpeed: number
@@ -95,6 +97,8 @@ export const AutoroutingPipelineMenuBar = ({
9597
onSetCanSelectObjects,
9698
onRunDrcChecks,
9799
onRunRelaxedDrcChecks,
100+
autoSolve,
101+
onSetAutoSolve,
98102
autoRunDrc,
99103
onSetAutoRunDrc,
100104
onSolveToBreakpointClick,
@@ -203,6 +207,10 @@ export const AutoroutingPipelineMenuBar = ({
203207
Solve to Breakpoint
204208
</MenubarItem>
205209
<MenubarSeparator />
210+
<MenubarItem onClick={() => onSetAutoSolve(!autoSolve)}>
211+
Auto Solve
212+
{autoSolve && <MenubarShortcut></MenubarShortcut>}
213+
</MenubarItem>
206214
<MenubarItem onClick={() => onSetAutoRunDrc(!autoRunDrc)}>
207215
Auto Run DRC
208216
{autoRunDrc && <MenubarShortcut></MenubarShortcut>}

0 commit comments

Comments
 (0)