Repository navigation
Add load_state and init!(s; initial_state) to continue a simulation - #336
Merged
Merged
Conversation
ufechner7
force-pushed
the
load_sys_state
branch
4 times, most recently
from
October 12, 2026 20:19
bcc289a to
d68c688
Compare
- load_state(filename) reads a SysState and the meta data that save_state wrote - init! takes the keyword initial_state (KPS4) and continues from it: positions, velocities, tether length, reel-out speed and KCU state are restored, the accelerations are calculated from the residual, and the integrator continues at the time of the state - parking_wind_dir.jl continues from its saved state if LOAD_SYS_STATE is true Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The example scripts now save integrator.t as SysState.time, so init! continues at initial_state.time instead of one time step later. parking_wind_dir.jl sets the time of the loaded SysState back to the start of the last time step, which update_sys_state! needs to calculate the rates. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ufechner7
force-pushed
the
load_sys_state
branch
from
October 12, 2026 20:25
d68c688 to
f32e32e
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Restart initialization omits important actuator and winch state, mishandles turbulent-wind time, and enables loading a nonexistent file by default.
3 open findings
What changed in this PR
Extends KPS4 state persistence to support resuming simulations.
Changes:
- Adds
load_stateand KPS4init!(...; initial_state). - Adds restart coverage and documentation.
- Updates the parking example to optionally resume a saved state.
| File | Description |
|---|---|
src/KPS4.jl |
Restores KPS4 simulation state. |
src/KiteModels.jl |
Adds loading and initialization APIs. |
test/test-update-sys-state.jl |
Tests state loading and continuation. |
examples_3d/parking_wind_dir.jl |
Demonstrates simulation restart. |
docs/src/functions.md |
Lists load_state. |
CHANGELOG.md |
Documents the new functionality. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
init_from_state! moves from KPS4.jl to KiteModels.jl and takes the velocities directly from the SysState, since KPS3 has no vel field; both models use the same state vector and residual convention. The restart test runs for both models; for KPS3 with a tolerance of 1e-6, because with the default of 1e-3 a turning KPS3 is only accurate to about half a metre and the restarted solver takes different steps. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…mments - update_sys_state! stores the rate limited set speed and the brake state of the winch in var_13 and var_14; init! restores them together with the set speed and set torque. Saved during a winch ramp, the tether length after one more second differs by 0.3 mm instead of 0.5 m from the uninterrupted simulation. - parking_wind_dir.jl starts at zero and saves the state if LOAD_SYS_STATE is true but the state file does not exist yet. - load_state docstring: missing fields keep the SysState defaults, which are zero except for the orientation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Calculate it from the velocities of the particles with calc_pitch_rate instead of setting it to zero. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 12, 2026
# Conflicts: # CHANGELOG.md
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1-Bart-1
approved these changes
Oct 17, 2026
1 of 2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Based on
main. It was stacked on #335, which is merged now, andmainhas been merged into this branch.What
load_state(filename)reads a file written bysave_state. It returns a newSysStateand the meta data dict.Xandspring_force.ArgumentError.init!(s; initial_state)(KPS3 and KPS4) continues a simulation from aSysState.update_sys_state!in the free fieldsvar_13andvar_14. Saved during a winch ramp, the tether length after one more second differs by 0.3 mm from the uninterrupted run, instead of 0.5 m without them.SysState, so they are computed from the residual. This gives the solver a consistentyd0.cmq) is computed from the particle velocities by the new internalcalc_pitch_rate, instead of starting at zero.next_step!uses the change of the pitch angle over the last step instead, so the two differ by O(dt), here about 0.0025 rad/s at 20 Hz. This only affects the first step after loading.initial_state.time, which must be the time of the state (integrator.twhen it was saved). ASysStatefromupdate_sys_state!holds the start time of the last step instead; the example scripts saveintegrator.t.examples_3d/parking_wind_dir.jl: withLOAD_SYS_STATE = true, the script continues fromoutput/sys_state_parking_wind_dir.yamlinstead of starting at zero, and does not save the state. If the file does not exist yet, it starts at zero and saves it.Limitations
Testing
New testsets in
test/test-update-sys-state.jl:load_state:NaNs andFloat32vectors.UNUSED_FIELDS_KPS3loads back and keeps the defaults for the excluded fields.init! from a loaded state, for KPS4 and KPS3: a steered kite is saved after 40 steps (KPS3 withUNUSED_FIELDS_KPS3), then the original and a restarted model each run 20 more steps.Float32rounding).rtol=1e-4.calc_pitch_rateof the original withinrtol=1e-4(YAML rounding), and the original's pitch rate within 10%.Float64state, so it is not missing state.All testsets in that file pass.
parking_wind_dir.jlwas run in the viewer withLOAD_SYS_STATE = trueand works.🤖 Generated with Claude Code