Skip to content

Multi-head 4/7: head schedule and plan conversion - #99

Merged
vycdev merged 17 commits into
vycdev:developfrom
Bjohnson131:mph-split-4-schedule-plan
Oct 31, 2026
Merged

vycdev merged 17 commits into
vycdev:developfrom
Bjohnson131:mph-split-4-schedule-plan

Conversation

@Bjohnson131

Copy link
Copy Markdown
Contributor

Fourth of seven PRs splitting up #38 (Multi Print Head Capability).

Depends on #97 and #98. Until they merge, this diff also shows parts 2 and 3; the new code is src/lib/multiHeadSchedule.ts, src/lib/patchedLayersToPlan.ts and their tests.

What

  • buildMultiHeadSchedule turns analysis windows and nozzle assignments into the initial head load plus each swap checkpoint: only changed heads are flagged, no-op pauses are merged away, and never-used heads are marked EMPTY.
  • patchedLayersToPlan converts a patched printer-layer stack into transition zones, slice data and per-color layer colors that the existing swap-plan and mesh pipeline can consume.

Nothing in the app calls it yet; wiring is part 5.

Tests

tests/multiHeadSchedule.test.ts and tests/patchedLayersToPlan.test.ts (34 tests). tsc is clean and the full unit suite passes (965 tests, 0 failures, 1 skipped).

Series

  1. Export and meshing (Multi-head 1/7: 3MF export and combined-mask meshing #96)
  2. Analysis core (Multi-head 2/7: window analysis core #97)
  3. Run-based analysis engine (mph-split-3-color-runs)
  4. Head schedule and plan conversion (mph-split-4-schedule-plan)
  5. Worker, UI and export wiring (mph-split-5-ui-wiring)
  6. Docs and diagrams (mph-split-6-docs)
  7. Color grouping mode (mph-split-7-color-grouping)

No changelog entry: internal groundwork with no user-visible change.

🤖 Generated with Claude Code

Bjohnson131 and others added 3 commits October 22, 2026 23:32
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]>
buildMultiHeadSchedule turns analysis windows and nozzle assignments
into the initial head load and per-swap checkpoints (changed heads
only, no-op pauses merged, unused heads EMPTY). patchedLayersToPlan
converts a patched printer-layer stack into transition zones, slice
data and per-color layer colors for the existing swap-plan and mesh
pipeline. Not wired into the app yet.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@Bjohnson131

Copy link
Copy Markdown
Contributor Author

Unit test results for this branch (npm test on mph-split-4-schedule-plan): 965 tests, 964 passed, 0 failed, 1 skipped. Full output: https://gist.github.com/Bjohnson131/58348b01975e2da17ab1f0eab5c7603f (file test-results-mph-split-4-schedule-plan.txt).

@vycdev vycdev left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated code review

Verdict: Needs changes · Findings: 2 (2 inline)

Scope: only what this PR adds on top of #98; the earlier PRs in this stack are reviewed in their own threads.

The new helpers are well scoped, but plan conversion loses optical data and several tests bypass their main assertions. All 34 focused tests, TypeScript checks, and focused ESLint passed. The full suite finished with 964 passing tests and one failure in the unchanged Windows file-association test.


Reviewed by GPT 6.1 Sol

return {
filamentId: filament?.id ?? `f${run.filamentIdx}`,
filamentColor: filament?.color ?? '#000000',
filamentTd: filament?.td ?? 0,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[medium] Preserve per-channel hiding distances in converted zones

PrinterLayer.td contains resolved per-channel hiding distances, but this conversion retains only the palette’s scalar HD and omits filamentTdChannels. Existing zone-based simulation therefore produces different colors from the source stack: a 0.1 mm layer of #ed275c with HD 0.7 over #101010 becomes #871834 through the converted zones instead of #872143. Preserve the run’s resolved channel HDs in filamentTdChannels and add a colored-filament round-trip assertion.

Reviewed by GPT 6.1 Sol

Comment thread tests/patchedLayersToPlan.test.ts Outdated
const { patchedLayers, colorLayerFilaments } = runMultiHeadLayerAnalysisColorFirst(
FOUR_FILAMENTS, result, swatches, LAYER_HEIGHT, FIRST_LAYER_HEIGHT, 2
);
if (patchedLayers.length === 0) return;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[medium] Exercise non-empty per-color rendering in the tests

The grayscale fixture selects zero windows in the current test run, so this guard and the corresponding guards below return before any non-empty buildPerColorLayerColors call. Consequently, all its tests still pass if the implementation always returns an empty Map; both reordered-plan integration tests also bypass their assertions. Use explicit layer/sequence fixtures or input guaranteed to select windows, and assert those preconditions instead of returning.

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
- Preserve resolved channel hiding distances and fitted optics in converted zones
- Resolve per-color transitions from each actual filament path
- Replace bypassed tests with deterministic multi-window and optical round-trip coverage
- Update the unreleased multi-head changelog entry
@vycdev

vycdev commented Oct 29, 2026

Copy link
Copy Markdown
Owner

Fixes for the automated review

Pushed c480b05 to this branch.

This branch also merges the fixed lower layers (#98), so it builds on the corrected code.

Findings

  • ✅ Preserve per-channel hiding distances in converted zones: Converted zones now retain resolved channel HDs and fitted run optics. Regression tests verify the reported #872143 color and fitted-color round trips.

  • ✅ Exercise non-empty per-color rendering in the tests: Replaced silently bypassed fixtures with deterministic input that selects two windows. Tests assert non-empty results and compare every surface against the shared physical-stack predictor.

Also fixed

  • Resolve transition optics for each color's actual filament path: The stronger tests exposed stale consensus-stack optics after filament reassignment. Rendering now resolves each path's foreground/substrate transitions and accepts the fitted optics model.

Verification: All 121 multi-head/plan-conversion tests pass.


Fixed by GPT 6.1 Sol

@vycdev vycdev left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated code review: second pass

Verdict: Looks good · New or remaining findings: 0

Reviewed head c480b05, which includes the fixes for the first review. Scope: only what this PR adds on top of #98; the other PRs in this stack are reviewed in their own threads.

Both first-pass findings are resolved, with meaningful regression coverage for channel HDs, fitted optics, and non-empty per-color rendering. I found no additional defects in this PR’s changes over PR #98 or semantic conflicts with newer develop changes. All 121 focused tests, npx tsc -b --noEmit, and ESLint on the added files passed.

First-pass findings

  • ✅ Resolved: Preserve per-channel hiding distances in converted zones. Converted zones retain resolved channel HDs and fitted run optics. Passing round-trip tests verify the reported #872143 color and fitted predictions beyond measured support.
  • ✅ Resolved: Exercise non-empty per-color rendering in the tests. The deterministic fixture asserts that two windows are selected and produces non-empty per-color paths. Tests verify divergence and compare every rendered surface against the shared physical-stack predictor.

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
vycdev added a commit to Bjohnson131/Kromacut-mph that referenced this pull request Oct 29, 2026
@vycdev

vycdev commented Oct 29, 2026

Copy link
Copy Markdown
Owner

Second-round fixes merged in

Pushed 9004929 to this branch.

This branch merges the second-round fixes from the lower layers (#98), 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 985/985, tsc -b and lint pass. On the top of the stack (#102 with every fix merged), a browser run with an 8-filament profile built routed 3-head models (no smoothing and Medium smoothing) and a routed 4-head model. The meshes were tagged with the scheduled heads, the 3MF used matching extruders and M600 pause markers, and every exported mesh was closed and consistently wound (each edge shared by exactly two triangles). The smoke e2e suite passed 64/66; the two failures are landing-page specs this stack does not touch, and develop has since fixed the landing credit link and updated both specs.


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
- Fall back to the prior optical model when the stored effective-optics
  model has no fitted filaments, matching the analysis and the single-head
  stack; keeping the empty model dropped every calibrated substrate
  transition, so multi-head previews and measurements used different
  colors from the ones the analysis optimized
- Add a regression on the calibrated frontlit profile: rendering unchanged
  paths reproduces the single-head stack
vycdev added a commit to Bjohnson131/Kromacut-mph that referenced this pull request Oct 29, 2026
@vycdev

vycdev commented Oct 29, 2026

Copy link
Copy Markdown
Owner

Fix: multi-head colors without fitted optics

Pushed 2f8746e to this branch, plus a merge of the #98 fix.

  • ✅ Per-color rendering dropped calibrated transitions: buildPerColorLayerColors fell back with effectiveOptics ?? prior. When nothing is fitted, Auto-paint stores an effective-optics model with no filament entries, so the renderer kept that empty model and dropped every substrate-dependent transition. The analysis and the single-head stack fall back to the prior model instead. On the calibrated frontlit profile, for example, red over purple rendered as #ab3207 instead of #aa2a55 (about 43 CIE76). This affected the multi-head preview colors and the measurements reported earlier, including the 4-head result on Multi-head 7/7: Color grouping mode #102. It did not change which layout the analysis picks or the 3MF filament colors. The renderer now uses the same fallback as the analysis.
  • Regression test: on the calibrated frontlit profile, rendering every color on its unchanged path reproduces the single-head stack.

Verification: after the merge, full unit suite 987/987, tsc -b and lint pass.


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
@vycdev

vycdev commented Oct 29, 2026

Copy link
Copy Markdown
Owner

Search fix merged in

Pushed 7de7840 to this branch. It merges the #98 sampling fix, so large windows keep the reorders that smaller windows find. There are no other changes in this PR.

Verification: after the merge, full unit suite 989/989, tsc -b and lint pass.


Fixed by Claude Opus 5.5

- Let per-color rendering apply the final stack's appearance model from
  each path's physical prefix, using the same rule as the final stack
- Reuse corrected colors across paths that share a physical prefix
- Test on the measured calibrated profile: unchanged paths reproduce the
  final stack's predicted colors exactly, and reordered paths are
  corrected from their own prefix
vycdev added a commit to Bjohnson131/Kromacut-mph that referenced this pull request Oct 31, 2026
@vycdev

vycdev commented Oct 31, 2026

Copy link
Copy Markdown
Owner

Note

🤖 Claude Opus 5.5 responding on behalf of Victor Sandu

Per-color rendering can now apply the full appearance model. Pushed ffc85a1, on top of a merge of the #98 search fix.

buildPerColorLayerColors only used fitted optics, so routed colors ignored the corrections Auto-paint applies from Palette Proofs and Stack Matrix evidence, while single-head predictions include them. On the measured benchmark profile and the cats image, those corrections move single-head colors by 3.21 mean CIEDE2000, and routed previews were 3.1–3.8 away from the full model.

It now takes an optional appearanceModel and corrects each layer from that path's own physical prefix, with the same rule the final stack uses. #100 passes the model in.

Verified:

  • With the filament order unchanged, the colors match the final stack's predicted colors on every layer (70/70 on cats, 18/18 on Rocco).
  • New tests on the measured profile check that match, and that reordered paths are corrected from their own prefix without affecting other paths.
  • After the merge: unit suite 991/991, tsc -b and lint pass.

The search itself still ranks candidates with fitted optics. That's tracked in #113.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants