Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@moorepants
Copy link
Member

This adds a new ODEFunctionGenerator that uses symjit as sympy->numeric code generator and compiler. symjit does not support iterable of iterables as function arguments and it can only output flat arrays, so a fair amount of input/output conversion is needed that slows down both the code generation and the numerical evaluation. Replacing symbols in the equations of motion does not seem to slow symjit's code generation which is clearly very fast but the numeric manipulation and type conversion does slow down the evaluation. If symjit can manage some things faster internally to manage similar inputs that lambdify accepts, then symjit may have equal evaluation speed to the Cython generation code and generate extremely faster.

Here is the benchmark run with 16 pendulum links, 100 integration steps, and 2 second duration.

bin/benchmark_pydy_code_gen.py 16 100 2
benchmark-results

This needs a bit more tidying and management of the optional dependency before merging.

@moorepants
Copy link
Member Author

Here is the benchmark up to 24 links:

benchmark-results

The benchmark script gives the same settings to all generators such that they generate the full mass matrix and full forcing vector and use the same linear system solver (numpy.linalg.solve()). The integration is LSODA (default in PyDy).

@Peter230655
Copy link
Contributor

You state symjit >= 2.5.0 is required, so I guess, you added the 'high speed version'.
If so, I'd like to test it. Can I add it from anaconda?
Thanks!

@moorepants
Copy link
Member Author

You state symjit >= 2.5.0 is required

I just made it the latest release. It may work with older versions.

@Peter230655
Copy link
Contributor

At the very bottom of this: siravan/symjit#3
there is described a way to make symjit considerably faster.
image
I have not seen this im the documentation, yet.
I use it in my comparisons.

@moorepants
Copy link
Member Author

Using the undocumented apply method:
benchmark-results

@moorepants
Copy link
Member Author

Doesn't look like symjit 2.5 is available for Python 3.9 from conda forge.

@Peter230655
Copy link
Contributor

Using the undocumented apply method: benchmark-results

Just so I am very clerar: Did you use numerical or symbolic inversion here?
Thanks!

@moorepants
Copy link
Member Author

Just so I am very clerar: Did you use numerical or symbolic inversion here?

I don't think I will answer, so that you read the code here :)

@moorepants moorepants marked this pull request as ready for review September 28, 2025 05:23
@Peter230655
Copy link
Contributor

Just so I am very clerar: Did you use numerical or symbolic inversion here?

I don't think I will answer, so that you read the code here :)

I read it for 30 min, but still not clear. :-((

@moorepants moorepants merged commit 35e58a3 into pydy:master Sep 28, 2025
17 checks passed
@moorepants moorepants deleted the symjit-generator branch September 28, 2025 07:00
@moorepants
Copy link
Member Author

moorepants commented Sep 28, 2025

Just as a record this is lambdify and symjit using linear_sys_solver='numpy' and cython using linear_sys_solver='sympy':

benchmark-results

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