Skip to content

KPS3 and KPS4 read positions and velocities from the integrator's state - #360

Draft
1-Bort-1 wants to merge 5 commits into
agent/322-one-kite-system-definition-across-the-kifrom
agent/359-kps3-and-kps4-read-positions-and-velocit
Draft

1-Bort-1 wants to merge 5 commits into
agent/322-one-kite-system-definition-across-the-kifrom
agent/359-kps3-and-kps4-read-positions-and-velocit

Conversation

@1-Bort-1

@1-Bort-1 1-Bort-1 commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

The one-point and four-point models kept their own copy of the particle positions and velocities. The solver overwrote that copy every time it evaluated the model, so after a time step the positions, the kite position, the elevation, the tether length, the reel-out speed and the logged state all came from the last state the solver tried, not from the state it accepted. Now the models keep no copy. Every getter of the state reads the accepted state of the integrator, so what you read after a step is the state the simulation actually continues from. Forces and aerodynamic quantities are not part of that state and still belong to the last evaluation, until the logged state refreshes them.

Callers do not change. s.pos, s.vel and s.vel_kite still work and now return the accepted state. They are read-only: code that wrote into s.pos to place the kite by hand calls KiteModels.set_pos_kite! instead, as the orientation test, the heading example and an older example script now do. The one-point model gains s.vel.

next_step!(kps4, integrator; set_speed=0)
kps4.pos[end-2]     # before: last trial state of the solver; now: the accepted state

Before an integrator exists (during init, find_steady_state!, or a residual! called by hand), the getters read the state the model was last initialised to or evaluated at. The model holds that state as a work buffer, written only while it has no integrator. clear! and find_steady_state! also drop the integrator, so a second init! no longer reads the previous run's state while it sets up the new one, and a trim search judges the state it solves for. next_step! takes up the integrator it is given, so stepping an existing integrator after a steady-state search still reads its accepted state.

Found on the way and fixed here: the one-point model's gravity correction of the steering used the elevation of the previous residual evaluation instead of the one being evaluated.

Results move slightly. With the default settings, after 420 steps the four-point kite's elevation differs by 1.8e-4° (height by 0.15 mm), because the wind at the start of each step is now sampled at the accepted kite height. The one-point kite's elevation differs by 5e-8° from the elevation fix. The changelog marks this as breaking.

Stacked on #327, which merges first: its system definition reads the positions this branch moves. It will conflict with the open drafts #347 and #334, which edit the same two model files.

Verification

  • Reproduced first, 5 steps after init! with the default settings: the kite position read from the model was 1.2e-6 m (one-point) and 7.8e-7 m (four-point) from the integrator's accepted state, the kite velocity 2e-5 and 1.4e-5 m/s; after the change both are 0.0
  • test/test-model-state.jl (new): the accepted-state assertions fail on the base (9 failed and 1 errored of 12 over both models). All 25 pass now. Undoing each fix fails its own assertion (steady state, stepping after it, the tether length, the work buffer, clear!, the steering elevation). The reel_out_speed assertion is the exception: it stays green without its fix, as the last trial equals the accepted speed in that run.
  • Pass on this head: test-kps3, test-kps4, test-interface, test-update-sys-state, test-initial-rates, test-azimuth, test-orientation, test-heading-steering, test-system-definition, test-steady-state-kps4, test-steady-state-robustness, bench3, bench4
  • Local full suite: PASS on this head (8 min, Julia 1.13.3, one configuration, benchmarks included)
  • GitHub's test jobs have not run on this branch. They run only on pull requests into main and this one targets the branch of Build a KiteGeometry SystemDefinition from KPS3 and KPS4 and carry it in the log #327, so they start when Build a KiteGeometry SystemDefinition from KPS3 and KPS4 and carry it in the log #327 has merged and this one targets main. The link and licence checks, the only ones that run here, pass.
  • Docs build clean · REUSE lint clean · up to date with Build a KiteGeometry SystemDefinition from KPS3 and KPS4 and carry it in the log #327
  • Allocations per step (200 steps, base → branch): one-point 3865 → 3801 B, four-point 7714 → 7865 B. Per residual call they are unchanged (2108 → 2106 B and 1933 → 1901 B); the four-point run made 746 instead of 732 residual calls on the slightly changed trajectory. The branch totals were measured on this head; the base totals and the per-call split come from the commit before it.
  • Benchmark time: not reported. The box was saturated (load 180 on 20 cores) and the benchmark run judged the conditions too unstable to compare. Reading the state now costs about 40 ns per getter call for a dynamic dispatch on the integrator, with no allocation.
  • Risk: code outside this repository that writes into s.pos or s.vel_kite now gets an error instead of silently changing a copy nobody used.

Opened by 1-Bort-1, an AI agent working for @1-Bart-1.
Closes #359 · task KiteModels.jl-359
Refs #322

1-Bort-1 and others added 3 commits November 7, 2026 15:16
Remove the pos, vel and vel_kite fields. The getters read the accepted
state of the integrator after init!, before it the state of init or of
the last call of residual!. s.pos, s.vel and s.vel_kite keep working as
read-only properties.

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>
@1-Bort-1 1-Bort-1 added the agent:running Agent task state label Nov 7, 2026
@1-Bort-1 1-Bort-1 added agent:ci Agent task state and removed agent:running Agent task state labels Nov 7, 2026
@1-Bort-1 1-Bort-1 added agent:queued Agent task state agent:running Agent task state and removed agent:ci Agent task state agent:queued Agent task state labels Nov 9, 2026
@1-Bort-1

1-Bort-1 commented Nov 9, 2026 •

Copy link
Copy Markdown
Member Author

Local full suite: PASS (5 min, Julia 1.13.3, one cell of the matrix)

@1-Bort-1 1-Bort-1 added agent:ci Agent task state agent:review Agent task state and removed agent:running Agent task state agent:ci Agent task state labels Nov 9, 2026

@1-Bort-1 1-Bort-1 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Independent review (advisory)

Verdict: APPROVE WITH COMMENTS · 5 inline, 0 off the diff

Good

  • Struct pos, vel and vel_kite are gone from both models; a search of src/ finds every remaining s.pos/s.vel read going through the getproperty route that reads the integrator's u.
  • residual! no longer reads s.pos, s.vel or s.vel_kite for its physics: KPS3 now uses locals and the src/ search shows no read on the residual path, so getters returning the accepted u cannot feed a stale state into a Newton iteration.
  • Caller read forms and getter signatures are unchanged, as #359 requires, and the read-only break is on the card and in the changelog.
  • init! sets s.integrator before the orient_euler and pitch-rate reads, and y0 is converted to Vector first, so the state_vector return assertion matches the integrator's u, confirmed by reading init!.
  • init_from_state! writes trial_y before calc_height, so the wind is sampled at the restored state, confirmed by reading the reordered lines.

Not good

  • src/KPS4.jl:768 — With a live integrator the residual no longer records its state, and exported find_steady_state! does not clear!, so calling it after init! makes above_horizon and s.pos read the old run. The trim search then judges stall on the wrong elevation, and the same gate is at src/KPS3.jl:515.
  • src/KPS4.jl:769 — reel_out_speed and unstretched_length still return s.v_reel_out and s.l_tether, written on every residual evaluation although both are integrator states. After next_step! they can give the last trial value, against #359's accepted-state requirement and the card's "every getter"; src/KPS3.jl:494 does the same.
  • src/KPS3.jl:499 — The elevation fix is named on the card, but no test reads s.beta or the steering correction, so §8's failing-before-the-fix test is missing and the fix can regress unnoticed.
  • examples/test_heading.jl:45 — The example writes the internal trial_y buffer through a hand-derived state offset, repeated at line 70 and in test/test-orientation.jl:19, instead of using one definition. This makes a work buffer the de facto way to place a kite and spreads the state layout further (§2).
  • test/test-model-state.jl:18 — New code calls deepcopy on the settings, which the Julia rules forbid and which hides what is shared; a fresh Settings object is the required form.
  • mwes/mwe_25.jl still writes s.pos[end-2][begin] = ... at six lines and now errors, though the card lists only the orientation test and heading example as migrated.
  • Issue #359 asks that allocations per step do not rise; the four-point run rose from 7714 to 7855 B, explained by more residual calls but still outside the stated check.
  • Issue #359 names test-kps3, test-kps4, bench3 and bench4 as the check; the card shows them passing only one commit before this head, with the full suite and CI still pending.
  • set_initial_rates! keeps i_kite = s isa KPS4 ? P - 2 : P and its own i0 index helper beside the new kite_particle and particle_vector, leaving two definitions of the same state layout in an opened file (§2).
  • No test covers the card's claim that clear! dropping the integrator stops a second init! reading the previous run's state, nor the pre-integrator trial_y route.
  • The new helper comments in src/KiteModels.jl:290 and src/KPS4.jl:1330 are multi-line blocks where §3 allows one line.
  • The particle_positions and particle_velocities docstrings show s::AKM while the methods accept only the KPS3/KPS4 union.

claude, rubric CLEAN_CODE.md. A different lab from the implementer
on purpose: a reviewer sharing its blind spots would not flag its mistakes.

Comment thread src/KPS4.jl Resolved
Comment thread src/KPS4.jl Resolved
Comment thread src/KPS3.jl Resolved
Comment thread examples/test_heading.jl Resolved
Comment thread test/test-model-state.jl Resolved
@1-Bort-1 1-Bort-1 added agent:queued Agent task state agent:running Agent task state and removed agent:review Agent task state agent:queued Agent task state labels Nov 9, 2026
find_steady_state! drops the integrator it would otherwise read, and
next_step! adopts the one it is given, so the trim search judges the
state it solves for. unstretched_length and reel_out_speed read the
accepted state. One definition of the particle offset in the state
vector and of placing the kite replaces the copies in the source, the
orientation test, the heading example and mwe_25.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@1-Bort-1

1-Bort-1 commented Nov 9, 2026

Copy link
Copy Markdown
Member Author

Off the diff, on 29f184a. mwe_25: fixed, no longer errors; it now stops at its own stale azimuth expectation (expects -90, gets 90), which this branch does not touch. Allocations: not changed, four-point 7714 to 7865 B per step comes from more residual calls on the shifted trajectory, per-call is unchanged, as the card says. Checks on this head: rerun, test-kps3, test-kps4, bench3 and bench4 pass, full suite running. set_initial_rates!: fixed, uses kite_particle, particle_vector and the new state_offset. clear! and trial_y route: fixed, tests added. Multi-line comments: fixed. Docstrings: fixed, now the union.

@1-Bort-1 1-Bort-1 added agent:ci Agent task state agent:review Agent task state and removed agent:running Agent task state agent:ci Agent task state labels Nov 9, 2026
@1-Bort-1 1-Bort-1 added agent:queued Agent task state agent:running Agent task state agent:ci Agent task state agent:review Agent task state and removed agent:review Agent task state agent:queued Agent task state agent:running Agent task state agent:ci Agent task state labels Nov 9, 2026

This branch has not been deployed

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

Labels

agent:review Agent task state

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant