Skip to content

Conversation

@moorepants
Copy link
Member

No description provided.

@moorepants
Copy link
Member Author

With pydy/pydy#515 the slowdown seems to be cse now, but it finishes. Adjusting the code to (similar to this PR):

def test_accelerations():

    print('Deriving the symbolic dynamics model.')
    symbolics = derive.derive_equations_of_motion()
    print(symbolics)

    rhs = symbolics.kanes_method.mass_matrix.LUsolve(symbolics.kanes_method.forcing)
    rhs =sm.Matrix(symbolics.speeds).col_join(rhs)

    print('Generating the PyDy ODE numerical function.')
    pydy_rhs = generate_ode_function(
        rhs,
        #symbolics.kanes_method.forcing,
        symbolics.coordinates,
        symbolics.speeds,
        constants=symbolics.constants,
        #mass_matrix=symbolics.kanes_method.mass_matrix,
        #coordinate_derivatives=sm.Matrix(symbolics.speeds),
        specifieds=symbolics.specifieds,
        generator='cython',
        constants_arg_type='array',
        specifieds_arg_type='array',
    )

Gives these results:

In [1]: from pygait2d.tests.test_model import test_accelerations
/home/moorepants/miniconda/envs/gait2d-dev/lib/python3.13/site-packages/pydy/codegen/c_code.py:8: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
  from pkg_resources import parse_version

In [2]: test_accelerations()
Deriving the symbolic dynamics model.
Forming positions, velocities, accelerations and forces.
Initializing Kane's Method.
Forming Kane's Equations.
States (18): [qax(t), qay(t), qa(t), qb(t), qc(t), qd(t), qe(t), qf(t), qg(t), uax(t), uay(t), ua(t), ub(t), uc(t), ud(t), ue(t), uf(t), ug(t)]

Specifieds (9): [Fax(t), Fay(t), Ta(t), Tb(t), Tc(t), Td(t), Te(t), Tf(t), Tg(t)]

Constants (43): [g, ma, ia, xa, ya, mb, ib, lb, xb, yb, mc, ic, lc, xc, yc, md, id, xd, yd, hxd, txd, fyd, me, ie, le, xe, ye, mf, if, lf, xf, yf, mg, ig, xg, yg, hxg, txg, fyg, kc, cc, mu, vs]
Generating the PyDy ODE numerical function.
lambdifying the equations of motion
PyDy evaluation time: 0.0033768770008464344
Lambdify evaluation time: 0.11875866299669724
Autolev evaluation time: 0.0054086649979581125

PyDy may only be slightly faster than Autolev because the autolev function also computes the ground reaction forces and the stick figure points.

@moorepants
Copy link
Member Author

I also just discovered that I had added an undocumented feature to SymPy ode_function_generator: `linear_sys_solver='sympy`` which gives nice performance, i.e. much shorter code generation and faster numerical evaluation.

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