Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 1996 vertcat #2208

Closed
wants to merge 8 commits into from
Closed

Issue 1996 vertcat #2208

wants to merge 8 commits into from

Conversation

valentinsulzer
Copy link
Member

Description

Avoids doing vertcat in the casadi solver, since vertcat is slow (because of the way the 2D arrays are stored in casadi).
Instead, does horzsplit so that both x (differential variables) and z (algebraic variables) are a list (of length len(t)) of vectors (of length num_diff_states and num_alg_states), then vertcats these item-by-item but does not re-concatenate to create the whole sol.y vector. Each sol.y[:,idx] is then accessed as an entry in a list of arrays. This is faster than actually doing sol.y[:,idx] from a 2D matrix in casadi.

This doesn't make a big difference for the standard solving with np.linspace(0,3600,100), but becomes important when there are more time points (e.g. 1000, 10000) e.g. with a shorter period - in those cases, vertcat was taking up to 20% of the solve time.

Fixes #1996

Type of change

Please add a line in the relevant section of CHANGELOG.md to document the change (include PR #) - note reverse order of PR #s. If necessary, also add to the list of breaking changes.

  • New feature (non-breaking change which adds functionality)
  • Optimization (back-end change that speeds up the code)
  • Bug fix (non-breaking change which fixes an issue)

Key checklist:

  • No style issues: $ flake8
  • All tests pass: $ python run-tests.py --unit
  • The documentation builds: $ cd docs and then $ make clean; make html

You can run all three at once, using $ python run-tests.py --quick.

Further checks:

  • Code is commented, particularly in hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

@kratman kratman deleted the issue-1996-vertcat branch March 19, 2024 18:08
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.

Casadi vertcat is slow if using larger number of time steps
1 participant