Repository navigation
Multi-head 3/7: run-based analysis engine - #98
Conversation
React-free primitives for multi-head printing: expand auto-paint zones into printer layers, Beer-Lambert color stack, LUT/window scoring and window selection. Not used by the app yet. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Group the printer-layer stack into color runs, find head windows with an iterative consensus search over filament orders (bounded by a per-depth combination budget, deterministic), compute per-color optimal assignments, and optimize nozzle-to-run assignments to minimize swaps. Adds the MultiHeadRangeAssignment type. Not wired into the app yet. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
Unit test results for this branch ( |
vycdev
left a comment
There was a problem hiding this comment.
Automated code review
Verdict: Needs changes · Findings: 2 (2 inline)
Scope: only what this PR adds on top of #97; the earlier PRs in this stack are reviewed in their own threads.
Reviewed only this PR's additions over PR #97. All 47 focused tests pass, and write-free TypeScript checks report no diagnostics; build-mode tsc was blocked from writing cache files. Two issues need correction: inconsistent color simulation across windows and excessive nozzle-optimizer complexity at supported head counts.
Reviewed by GPT 6.1 Sol
| for (const [prevKey, prevEntry] of dp) { | ||
| const prevState = prevKey.split('\x00'); | ||
|
|
||
| for (let ii = 0; ii < injs.length; ii++) { |
There was a problem hiding this comment.
[high] Bound the nozzle optimizer at supported head counts
For consecutive events requiring all N heads, dp contains N! states and injs contains N! injections, producing (N!)² transitions per boundary. Calling optimizeNozzleAssignments([f, f], 7) with seven distinct filament IDs took approximately 10.9 seconds here despite requiring zero swaps. At the supported eight-head cap, this trivial case executes 1,625,702,400 transitions. Neither the combination budget nor Fast mode limits this stage, so valid multi-window analyses can become impractically slow. Eliminate equivalent head permutations or replace/bound this search, and cover consecutive full-head windows at the cap.
Reviewed by GPT 6.1 Sol
| (r) => bestUniqueIndices!.indexOf(layers[r.startLayerIdx].filamentIdx) | ||
| ); | ||
| const { assignments } = computeColorOptimalAssignments( | ||
| bestWindowRuns, wEnd, layers, colorAtLayer[wStart - 1], bestWindowFilaments, pixels, |
There was a problem hiding this comment.
[medium] Optimize each window against the color-specific stack
colorAtLayer represents the consensus stack, but the returned color sequences substitute each color's own assignments in earlier windows. Higher windows therefore use a prefix that differs from what will be printed, and the saved assignments are never reconciled. In a two-head fixture with 0.25-mm layers, one swatch per target layer, and selected windows [1,2] and [3,4], target #6b6b6b gets ΔE 25.41; changing only layer 3 to the other available filament reduces it to 22.53 (the original stack scored 23.05). Compute or reconcile assignments against each color's realized prefix and suffix, and add a regression exercising multiple selected windows.
Reviewed by GPT 6.1 Sol
- Reuse final printable layers and swatch surface mappings - Preserve fitted optics and resolve substrates for candidate runs - Add seven regression tests and update the unreleased changelog
- Reconcile per-color window assignments against realized stacks - Replace factorial nozzle search with deterministic optimal scheduling - Preserve merged target mappings and fitted run optics - Add regression coverage and update the unreleased changelog
Fixes for the automated reviewPushed This branch also merges the fixed lower layers (#97), so it builds on the corrected code. Findings
Also fixed
Verification: All 83 multi-head analysis tests pass. Fixed by GPT 6.1 Sol |
vycdev
left a comment
There was a problem hiding this comment.
Automated code review: second pass
Verdict: Looks good · New or remaining findings: 0
Reviewed head b5307df, which includes the fixes for the first review. Scope: only what this PR adds on top of #97; the other PRs in this stack are reviewed in their own threads.
Both earlier findings are resolved, and I found no additional actionable defects in this PR’s changes over #97. All 83 focused multi-head tests, TypeScript checking, and targeted ESLint passed; 500 independent randomized optical comparisons also passed. No semantic conflicts with the newer develop changes were identified.
First-pass findings
- ✅ Resolved: Optimize each window against the color-specific stack. Assignments are now reconciled against each color group’s realized prefix and suffix in bounded improvement passes. The two-window regression independently evaluates alternative assignments and checks that returned stacks preserve or improve baseline quality.
- ✅ Resolved: Bound the nozzle optimizer at supported head counts. The factorial search has been replaced with deterministic reuse and farthest-future eviction scheduling. Exhaustive comparisons across 2,401 small schedules and the consecutive eight-head regression pass.
Reviewed by GPT 6.1 Sol
- Use snapshot baselines and resolve full candidate appearance corrections - Preserve required foundation layers without changing LUT indices - Add four regression tests and update the existing Added changelog entry
# Conflicts: # CHANGELOG.md
# Conflicts: # CHANGELOG.md
Second-round fixes merged inPushed This branch merges the second-round fixes from the lower layers (#97), so it builds on the corrected code. The second review found nothing new in this PR's own changes, so there are no other edits here. Verification: After the merge: full unit suite 947/947, Reviewed by GPT 6.1 Sol |
- Cap each window at the color runs above the foundation instead of requiring exactly one run per head, so selecting more heads than runs no longer finds no window and falls back to single-head - Keep the selected head count for scheduling; spare heads stay empty - Add a regression comparing four heads with three on a three-run stack
# Conflicts: # CHANGELOG.md
Fix: more heads than color runsPushed
Known limitation, not changed here: when a window has more filament orders (K^N) than the search depth's budget, the deterministic sample can miss an improvement that a smaller, exhaustively searched window finds. On the browser check's 8-color image, 3–6 heads find an improving window, but 7 and 8 heads sample 65,536 of 7^7 orders, find none, and still fall back. Verification: full unit suite 948/948, Fixed by Claude Opus 5.5 |
- When a window has more orders than the search budget, always evaluate every order that changes one block of neighbouring runs, sized to half the budget, before the evenly spaced samples; the evaluation count is unchanged - Seven or eight heads previously sampled past improvements that windows of three to six heads find exhaustively, and fell back to single-head - Add tests for exhaustive small windows and block coverage when sampling
# Conflicts: # CHANGELOG.md
Search fix: large windows keep short reordersPushed
Verification: full unit suite 950/950, Fixed by Claude Opus 5.5 |
Third of seven PRs splitting up #38 (Multi Print Head Capability).
Depends on #97. Until #97 merges, this diff also shows part 2; the new code is
src/lib/multiHeadAnalysisColorFirst.ts, its tests and theMultiHeadRangeAssignmenttype.What
Nothing in the app calls it yet; the schedule and UI wiring follow in parts 4 and 5.
Tests
tests/multiHeadAnalysisColorFirst.test.ts(47 tests), including determinism, budget-vs-exhaustive equivalence and the head-count clamp.tscis clean and the full unit suite passes (931 tests, 0 failures, 1 skipped).Series
mph-split-3-color-runs)mph-split-4-schedule-plan)mph-split-5-ui-wiring)mph-split-6-docs)mph-split-7-color-grouping)No changelog entry: internal groundwork with no user-visible change.
🤖 Generated with Claude Code