Skip to content

Batch GGV constraint Jacobians through one vectorized 3DOF evaluation - #173

Merged
raorjun merged 18 commits into
mainfrom
claude/project-thread-qin29u-batched-jac
Nov 26, 2026
Merged

raorjun merged 18 commits into
mainfrom
claude/project-thread-qin29u-batched-jac

Conversation

@raorjun

@raorjun raorjun commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Stack: based on main now that #172, #171 and #164 have merged.

What

Before: SLSQP built each GGV constraint Jacobian by finite differences, one scalar model call per unknown. That was about 85% of a GGV slice.

After: the constraint Jacobians come from engines/dynpy/jacobian.py, which takes SciPy's 2-point steps exactly and hands every column point to model.evaluate_batch before any column is read. The 3DOF QSS model evaluates those rows as arrays: aero, loads, kinematics per unique rack, tires, load transfer and slip slopes. Each row matches row-by-row evaluate bit for bit, so the solver takes the same path and the output does not change. Other fidelities get a row-by-row evaluate_batch until they have their own vectorized path.

Full GGV on 4 cores goes from 192 s to 67 s. One slice (index 6) goes from 58 s to 20 s.

How to check

  • python -m pytest -n auto tests, ruff check ., and make typecheck all pass locally.
  • tests/test_dynpy_batch.py (25 tests) covers:
    • batch rows against scalar evaluate, with shared and distinct racks, steering input, unloaded corners and no aero;
    • the 6/10/14 DOF fallback and bad-input rejection;
    • AeroMap.wrench_batch and the batched slip slopes;
    • forward_difference_jacobian against SciPy's approx_derivative bit for bit: interior, step flip at a bound, narrow boxes forward and backward, and clipping;
    • a GGV boundary solve with batching against one with batching refused.
  • Running python -m simulations.envelope.ggv.ggv_generation on this branch and on main produces byte-identical ggv_first_principles.csv, ggv_track_performance_profile.csv and ggv_track_velocity_profile.csv.
  • On the stacked branch (with Speed up GGV: cheaper cross product, one worker per slice #164, Generate lap-evaluation GGVs across worker processes #171 and Close GGV boundary equations on every CPU #172 merged in): full suite 1262 passed, 23 skipped; ruff check . and make typecheck clean.

Notes

np.cross spent most of its time in moveaxis bookkeeping on 3-vectors and
4x3 corner arrays. engines/dynpy/vector.cross uses the same component
formulas, so results are bitwise identical. One speed slice drops from
57.5 s to 52.0 s on one core; the full GGV run from 189.2 s to 176.5 s on
4 cores with identical CSVs.

The GGV pool was capped at 4 workers for 9 independent slices. It now uses
one worker per slice up to the core count.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
It showed the cross product is bitwise identical to np.cross on the CI runner.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
make lap-eval-qss solved its nine GGV speed slices serially, which was
almost all of its wall time. The envelope workflow already solves the
same slices in spawned workers through parallel.py, but the lap path
caps drive power on both the envelope parameters and the DynPy vehicle,
so it could not call generate_ggv_from_vehicle as is.

Split parallel.py so callers can hand workers already projected
envelope parameters and an event power cap, and route the lap path
through it. Worker count stays the envelope rule: one per slice, at
most four and at most the CPU count. Slices share no solver state, so
the result is bit-identical to the serial solve; a test pins that on a
two-speed lap envelope.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The lateral limit coasts, so total wheel torque sits on zero, where the
drive and brake distributions switch. SLSQP's finite differences straddle
that kink and float rounding decides how, which left up to 5e-5 rad/s^2 on
the nearly lifted inside rear's spin balance. CI's runners landed past the
test's 1e-5 tolerance while local runs did not.

Polish each accepted boundary with bounded Newton steps on each side of the
kink, letting the boundary value move by about the residual. Seeded 1e-12
start nudges that reproduce CI's failure now close to about 1e-10.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SLSQP's finite-difference Jacobians were about 85% of a GGV slice, one
scalar model call per column. The constraint Jacobians now come from
engines/dynpy/jacobian.py, which takes SciPy's 2-point steps exactly and
hands every column point to model.evaluate_batch first. The 3DOF QSS
batch (aero, loads, kinematics per rack, tires, load transfer) matches
row-by-row evaluate bit for bit, so the solve takes the same path.

Full GGV: 192 s to 67 s on 4 cores, CSVs byte-identical to main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#171 kept the envelope's four-worker cap and moved worker choice into
ggv_worker_count. This branch removes that cap, so the merge applies
the uncapped rule there: one process per slice, up to the CPU count.
The #171 worker-count test and both docs now state that rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keeps both new imports in ggv_generation.py: the batched Jacobian
helper from this branch and vector.cross from #164.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@raorjun
raorjun changed the base branch from main to claude/project-thread-qin29u November 24, 2026 18:55
@raorjun
raorjun marked this pull request as ready for review November 24, 2026 19:01

@rhorvath02 rhorvath02 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed the current revision; no actionable code findings. Current CI checks pass. Please preserve the stack order: #172 → #171 → #164 → #173.

Validation scope: focused tests were checked during review, but I did not independently rerun the full vehicle/GGV regression. The PR reports byte-identical GGV outputs. Before merging the final integrated stack, please retain or refresh that comparison on the final revisions, checking envelope and track outputs against the baseline.

@raorjun
raorjun added this pull request to stack #175 November 26, 2026 16:35
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…hread-qin29u after #172 landed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…batched-jac after #172 landed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The four conflicts are #164's own edits on top of #171's lines, which main
now holds as one squash commit; #164's side is kept. Nothing else on main
touches those files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Base automatically changed from claude/project-thread-qin29u to main November 26, 2026 17:00
The two conflicts are #173's own edits on #164's lines, which main now
holds as one squash commit; #173's side is kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@raorjun
raorjun merged commit 999dc84 into main Nov 26, 2026
6 checks passed
@raorjun
raorjun deleted the claude/project-thread-qin29u-batched-jac branch November 26, 2026 17:06
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.

3 participants