It's because I didn't have fastcache installed.... After installing
it, by default I got:
certik@redhawk:~/repos/symengine/benchmarks(py)$ python kane2.py
Setup
Converting to SymEngine...
SymPy Jacobian:
Total time: 0.123499155045 s
SymEngine Jacobian:
Total time: 0.00305485725403 s
Speedup: 40.43x
(I am running some longer calculation at the same time, so the timing
is a bit different, but it got faster.)
But bigger cache doesn't seem to affect it, as you noted:
certik@redhawk:~/repos/symengine/benchmarks(py)$
SYMPY_CACHE_SIZE=50000 python kane2.py
Setup
Converting to SymEngine...
SymPy Jacobian:
Total time: 0.121557950974 s
SymEngine Jacobian:
Total time: 0.00302696228027 s
Speedup: 40.16x
More interestingly, I can now differentiate the actual bicycle
expression. So far I just took one element on the right hand side
vector, and differentiate with respect to q5. I substitute for symbols
first (in both SymPy and SymEngine). This is what I got:
certik@redhawk:~/repos/symengine/benchmarks(py)$ python kane3.py
Converting to SymPy...
Converting to SymEngine...
Done.
Subs
Eval initial expression
-14960.1119361
-14960.111936127382563475771853345057230700491739739146860248076 +
0.00000000000000000000000000000000000000000000000000000000000000*I
SymPy diff:
Total time: 3.90587186813 s
SymEngine diff:
Total time: 0.0883350372314 s
Speedup: 44.22x
Subs
Eval derivative
-31789.936485
-31789.936484889832248148585748003998439133612431284784993412159 +
0.00000000000000000000000000000000000000000000000000000000000000*I
Converting SymPy derivative to SymEngine...
Subs
Eval derivative
-31789.936485
-31789.936484889832248148585748003998439133612431284784993279022 +
0.00000000000000000000000000000000000000000000000000000000000000*I
The floating point numbers are calculated by substituting integers for
the symbols and evaluating. The shorter number is using machine double
precision, the longer number is using MPC (evaluates in complex plane,
to make sure we don't get any negative values under square roots).
They both agree as you can see. The initial expression number I
checked against sympy (substituting the numbers using sympy and
evaluating using sympy). For the derivatives, currently I just the
sympy derivative to symengine to evaluate as a floating point, since
sympy is just too slow (it's been running for 30 minutes -- it's stuck
at the .n() method in sympy). The SymEngine evaluation is immediate
for double precision and a fraction of a second for the MPC. But the
conversion between symengine and sympy works well and I tested the
initial expression in both, so I think this part works. And the fact
that sympy derivative calculated using sympy and converted to
symengine and symengine derivative agrees I think proves with pretty
high confidence that things work.
Now the next step is to calculate the whole jacobian and again test
that we get the same expression. It's very important to spend time and
check the numerical evaluation of the expression, since there could be
bugs in symengine. I just fixed one here:
https://github.com/sympy/symengine/pull/556 (it was giving me
different numbers for the initial expression, but now they agree).
This was a bug in subs, but there could be a bug in the derivative as
well.
After we get the same expressions, we can start benchmarking. I can
start profiling the derivative code in C++ and see if it is possible
to speed it up. I can also implement cache in symengine, though I
don't know if it would speed up anything here. Still, even if we only
get 45x speedup, then instead of 4 minutes, the whole bicycle should
take 5s. So I think that's a big deal. I will also try to benchmark
this against other software like Sage to get an idea how we are doing.
Ondrej
>
https://groups.google.com/d/msgid/sympy/CAP7f1AhavPNhXzdhUDUVH1ihgDgbc4FbdmRPBHrMW9HQ4ijZDA%40mail.gmail.com.