Skip to content

Epic: Stage 1 — typed, machine-agnostic Motion IR #136

Closed

Description

@CameronBrooks11

Epic — Stage 1 of the engine roadmap (docs/development/roadmap.md). The keystone refactor: introduce one typed, machine-agnostic toolpath IR so motion math lives in a single place and G-code becomes a build artifact.

Problem (confirmed in code)

Motion math is triplicated against stringly-typed G-code:

  • the authoritative emitter machine._move_segment,
  • the simulator (simulate_program does line.split()),
  • the plotter (_collect_segments parses 'G0' text and ast.literal_evals the ; Parameters header).

Worse, the planner and simulator compute time from different formulas on the same moves — planner: mandrel in raw degrees, delivery-head included; simulator: arc-mm, delivery excluded — so PlanResultOut.timeSeconds and SimulationResultOut.estimatedTimeSeconds disagree by construction. There is no intermediate representation: strategies write strings straight into machine._gcode.

🔴 The committed examples/rocketry/*.gcode goldens are stale — none reproduces from its .wind today (A-axis sign flip; AvBay…triple.wind edited after its gcode was cut; AvBay…single has no gcode). There is currently zero trustworthy byte baseline, so the epic must freeze one first (#270).

Target

plan_wind emits a typed Program{meta: ProgramMeta, moves: list[Move]}; serialize(program, dialect) -> list[str] is the only place that knows axis letters / number formatting / header JSON / opcode strings (dialect = post-processor, G-code = build artifact). Simulator, plotter, and metrics consume the IR (no per-consumer G-code parsing). A single nominal_metrics(moves, diameter) (O1 surface-arc: Euclid(carriage_mm, mandrel_arc_mm)/feed, delivery excluded) is the one motion-math implementation, ending the divergence. The validated cylinder output is byte-equal to committed goldens at every step. The IR is a clean lowering target for Stage 2 (#137) and Stage 3a (#138).

IR shape (minimal, byte-grounded)

Move{kind, targets: dict[Axis,float], feed, text}; MoveKind ∈ {RAPID, SET_FEED, SET_POSITION, COMMENT}; Program{meta, moves}. Deviations from the original proposal (verified against an 818k-line opcode histogram — only G0/G92/comments are emitted; zero G1, zero G21/G94):

  • drop lay (not emitted; would change the plot signature — defer to Stage 2),
  • add Program/ProgramMeta (the header data must travel structurally so consumers stop re-parsing it),
  • SET_FEED → G0 F…, not G1 (no rapid-vs-feed distinction today),
  • G92, not M92; never emit the dead G21/G94 prologue.

Definition of done

  • All frozen .wind reproduce their committed .gcode byte-equal through plan_wind → serialize(program, dialect) (empty diff on every IR PR).
  • plan_wind returns Program; serialize() is the sole owner of axis letters / formatting / header / opcodes.
  • Exactly one motion-math/metrics implementation (nominal_metrics, O1) consumed by both planner and simulator; their reported time agrees by construction.
  • No duplicate motion-math; G-code text parsing, if any, is confined to a single boundary adapter (the CLI/API path that accepts an external .gcode file) — simulator and plotter are IR-native (verifiable by grep). (Reinterprets the original "no text parsing" line; see S-bnd.)
  • Simulator/plotter goldens regenerated + reviewed where the IR corrects the silently-dropped G92 reference frame and adopts O1 (these are not byte-gated — they're deliberate metric changes).

Slices

Prework (freeze the baseline before refactoring):

Build:

Later slices (coarse — promoted to issues when next):

Sequencing

Prework (#270 → #271 → #272) lands first — the frozen goldens + green harness are the gate. Then #273 → #274 (keystone; must show an empty G-code diff) → #275. Then S-bnd resolves the consumer-contract boundary, after which S3/S4 are internal consumer rewrites and S5 is cleanup. The validated cylinder G-code is golden-gated at every slice.

Constraints (roadmap)

Don't break the validated cylinder output (golden-gated); keep planning machine-agnostic (machine specifics stay in the dialect/post-processor); minimal-first (smallest IR that captures today's emission); additive/backward-compatible .wind.

Related

Next stages build on this IR: #137 (Stage 2 — one pattern primitive), #138 (Stage 3a — cones), #139 (Stage 3b — domes). Time-model calibration against real hardware is tracked separately (#130).

Plan produced by a multi-agent investigation of the planning/gcode/sim/viz code (6 probes → synthesis → adversarial critique); the critique tightened the slice split, added the boundary-reader slice, and pulled fiberpath_gui into scope.

Activity

  1. added
    enhancement
    python
    on Jun 25, 2026
  2. changed the title [-]Stage 1 — introduce a typed Motion IR (machine-agnostic toolpath)[/-] [+]Epic: Stage 1 — typed, machine-agnostic Motion IR[/+] on Jun 28, 2026
  3. added
    epic
    on Jun 28, 2026
  4. CameronBrooks11 commented on Jun 28, 2026

    @CameronBrooks11
    MemberAuthor

    ✅ Epic complete — Stage 1 Motion IR shipped

    Every slice merged and every Definition-of-Done bullet satisfied. A typed, machine-agnostic Program{meta, moves} is now the spine: plan_wind emits it, serialize(program, dialect) is the sole G-code producer, and read_program is the sole G-code→IR reader at the CLI/API boundary. Motion math lives in exactly one place (nominal_metrics, O1 surface-arc), consumed by both the planner and the simulator — the historical planner/simulator time divergence is closed by construction.

    Slices

    Phase PRs
    Prework — freeze goldens, byte-equal harness, sim/plot snapshot #270 · #271 · #272
    Build — IR types, keystone lowering, O1 planner time #273 · #274 · #275
    Boundary reader (read_program); simulator + plotter go IR-native S-bnd #282 → PR #283
    Simulator shares nominal_metrics (G92-aware; divergence closed) S3 #284 → PR #285
    Plotter honors the G92 reference frame (removes the boundary artifact) S4 #286 → PR #287
    Delete dead dump_header + CI guard for the single source of truth S5 #288 → PR #289

    Verified by three independent adversarial reviews before close

    • Byte-equality held at every step (test_example_goldens, all 7 goldens).
    • Numbers reproduced from scratch — an independent reviewer rebuilt the simulator and plotter and matched every committed value; the deliberate metric deltas are fully explained by the G92 correction (e.g. multi_layer sim time 1733.98s → 905.47s = the planner total, to 1e-11).
    • Single source of truth grep-locked by tests/test_motion_ir_invariants.py (scans fiberpath/, fiberpath_cli/, fiberpath_api/): one math.sqrt( motion-math impl, one _detect_dialect/header parser, zero ast.literal_eval.

    The IR is now a clean lowering target for Stage 2 (#137) and Stage 3a/3b (#138/#139). Time-model calibration against real hardware remains tracked in #130.

    Closing as done.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementepicpython

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions