Skip to content

added: xs_0 and as_0 args in NonLinModelDAE constructor for initial guesses - #445

Merged
franckgaga merged 10 commits into
mainfrom
warmstart_alg
Sep 14, 2026
Merged

franckgaga merged 10 commits into
mainfrom
warmstart_alg

Conversation

@franckgaga

@franckgaga franckgaga commented Sep 14, 2026

Copy link
Copy Markdown
Member

Warm-starting states and algebraic variable for DAEs

This PR introduces two new keyword arguments in NonLinModelDAE constructor:

  • xs_0=zeros(nx): initial guess (optimization warm-start) for the states.
  • as_0=zeros(na): initial guess (optimization warm-start) for the algebraic variables.

It currently allows providing an initial guess for the the state and the algebraic variable when simulating in open-loop. These guesses are only used at the discrete time $k=0$, that is, just after construction of NonLinModelDAE or after initstate!(model::NonLinModelDAE, u, d) is called. After $k=0$, the values computed at the previous time steps are used since it is assumed that they represent better guesses. I will use the value of these two arguments for the upcoming closed-loop functionalities.

This is particularly important for the algebraic variables of DAEs. I experienced it myself by playing with some famous DAE models. This PR covers the suggestion of @baggepinnen here.

The function setstate!(obj, x) now supports scalar x

It allows call like setstate!(model, 0), and also sim! with arguments like x_0=0 or x̂_0=0.

It allows providing an initial guess (or warm-start) for the algebraic variable when simulating in open-loop. I will use the value of this argument for the upcoming closed-loop functionalities.

This is particularly important for DAEs, I experienced it myself by playing with some famous DAE models.
@franckgaga franckgaga changed the title added: as_0 argument in NonLinModelDAE constructor added: as_0 argument in NonLinModelDAE constructor for initial guess Sep 14, 2026
@franckgaga franckgaga changed the title added: as_0 argument in NonLinModelDAE constructor for initial guess added: xs_0 and as_0 argument in NonLinModelDAE constructor for initial guesses Sep 14, 2026
@franckgaga franckgaga changed the title added: xs_0 and as_0 argument in NonLinModelDAE constructor for initial guesses added: xs_0 and as_0 args in NonLinModelDAE constructor for initial guesses Sep 14, 2026
This is needed to reset the warm-starting strategy for `NonLinModelDAE` simulations.

It's also now possible to send `x_0=nothing` to `sim!`. It will automatically compute the steady-state for the `LinModel` case.
It will reset the warm-start strategy before starting the loop for simulations of `NonLinModelDAE` plant models. Note that it also compute the steady-state for the `LinModel` case, but the results is overwritten by the next `setstate!(plant, x_0)` line.
It allows call like `setstate!(model, 0)`, or `sim!` with arguments `x_0=0` or `x̂_0=0`.
@franckgaga
franckgaga merged commit 200089d into main Sep 14, 2026
17 checks passed
@franckgaga
franckgaga deleted the warmstart_alg branch September 14, 2026 21:00
@codecov-commenter

codecov-commenter commented Sep 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.92%. Comparing base (440a5d7) to head (a15a3bc).
⚠️ Report is 11 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #445      +/-   ##
==========================================
+ Coverage   96.87%   96.92%   +0.04%     
==========================================
  Files          28       28              
  Lines        6628     6656      +28     
==========================================
+ Hits         6421     6451      +30     
+ Misses        207      205       -2     
Flag Coverage Δ
unittests 96.92% <100.00%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

2 participants