Repository navigation
KPS3 and KPS4 read positions and velocities from the integrator's state - #360
Conversation
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>
|
Local full suite: PASS (5 min, Julia 1.13.3, one cell of the matrix) |
1-Bort-1
left a comment
There was a problem hiding this comment.
Independent review (advisory)
Verdict: APPROVE WITH COMMENTS · 5 inline, 0 off the diff
Good
- Struct
pos,velandvel_kiteare gone from both models; a search ofsrc/finds every remainings.pos/s.velread going through thegetpropertyroute that reads the integrator'su. residual!no longer readss.pos,s.velors.vel_kitefor its physics: KPS3 now uses locals and thesrc/search shows no read on the residual path, so getters returning the accepteducannot 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!setss.integratorbefore theorient_eulerand pitch-rate reads, andy0is converted toVectorfirst, so thestate_vectorreturn assertion matches the integrator'su, confirmed by readinginit!.init_from_state!writestrial_ybeforecalc_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 exportedfind_steady_state!does notclear!, so calling it afterinit!makesabove_horizonands.posread the old run. The trim search then judges stall on the wrong elevation, and the same gate is atsrc/KPS3.jl:515.src/KPS4.jl:769—reel_out_speedandunstretched_lengthstill returns.v_reel_outands.l_tether, written on every residual evaluation although both are integrator states. Afternext_step!they can give the last trial value, against #359's accepted-state requirement and the card's "every getter";src/KPS3.jl:494does the same.src/KPS3.jl:499— The elevation fix is named on the card, but no test readss.betaor 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 internaltrial_ybuffer through a hand-derived state offset, repeated at line 70 and intest/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 callsdeepcopyon the settings, which the Julia rules forbid and which hides what is shared; a freshSettingsobject is the required form.mwes/mwe_25.jlstill writess.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!keepsi_kite = s isa KPS4 ? P - 2 : Pand its owni0index helper beside the newkite_particleandparticle_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 secondinit!reading the previous run's state, nor the pre-integratortrial_yroute. - The new helper comments in
src/KiteModels.jl:290andsrc/KPS4.jl:1330are multi-line blocks where §3 allows one line. - The
particle_positionsandparticle_velocitiesdocstrings shows::AKMwhile the methods accept only theKPS3/KPS4union.
claude, rubric CLEAN_CODE.md. A different lab from the implementer
on purpose: a reviewer sharing its blind spots would not flag its mistakes.
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>
|
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. |
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.velands.vel_kitestill work and now return the accepted state. They are read-only: code that wrote intos.posto place the kite by hand callsKiteModels.set_pos_kite!instead, as the orientation test, the heading example and an older example script now do. The one-point model gainss.vel.Before an integrator exists (during
init,find_steady_state!, or aresidual!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!andfind_steady_state!also drop the integrator, so a secondinit!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
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.0test/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). Thereel_out_speedassertion is the exception: it stays green without its fix, as the last trial equals the accepted speed in that run.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,bench4s.posors.vel_kitenow 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-359Refs #322