Skip to content

Topic/aba second order derivatives#2891

Open
shubhamsingh91 wants to merge 4 commits into
stack-of-tasks:develfrom
shubhamsingh91:topic/aba-second-order-derivatives
Open

Topic/aba second order derivatives#2891
shubhamsingh91 wants to merge 4 commits into
stack-of-tasks:develfrom
shubhamsingh91:topic/aba-second-order-derivatives

Conversation

@shubhamsingh91

@shubhamsingh91 shubhamsingh91 commented May 19, 2026

Copy link
Copy Markdown
Contributor

Thanks for taking the time to make and fill out this pull request!

Description

This PR (discussed in #2691) adds the second-order derivatives of the unconstrained Articulated Body Algorithm as derived in this paper (https://ieeexplore.ieee.org/abstract/document/10449483).
The specific algorithm is from Eq~46 from the paper, and more details can be found in Fig.13. Note that this algorithm uses the rnea-second-order-derivatives, which were contributed previously as a part of #1860.

Paper can be accessed directly on researchGate.

Output of timings-derivatives:

  Benchmark                                                        Time             CPU   Iterations
  --------------------------------------------------------------------------------------------------
  DerivativesFixture/FORWARD_KINEMATICS_Q_V_A                   3688 ns         3687 ns       189116
  DerivativesFixture/FORWARD_KINEMATICS_DERIVATIVES             4792 ns         4792 ns       152272
  DerivativesFixture/RNEA                                       5254 ns         5250 ns       132336
  DerivativesFixture/COMPUTE_RNEA_DERIVATIVES                  22267 ns        22267 ns        31468
  DerivativesFixture/COMUTE_RNEA_SECOND_ORDER_DERIVATIVES     164514 ns       164474 ns         4248
  DerivativesFixture/COMPUTE_ABA_SECOND_ORDER_DERIVATIVES    3486243 ns      3486084 ns          203
  DerivativesFixture/COMPUTE_RNEA_FD_DERIVATIVES              406536 ns       406510 ns         1724
  DerivativesFixture/ABA_LOCAL                                 13172 ns        13166 ns        51339
  DerivativesFixture/COMPUTE_ABA_DERIVATIVES                   49715 ns        49713 ns        14036
  DerivativesFixture/COMPUTE_ABA_DERIVATIVES_NO_Q_V_TAU        41965 ns        41963 ns        16760
  DerivativesFixture/COMPUTE_ABA_FD_DERIVATIVES               946073 ns       946021 ns          741
  DerivativesFixture/COMPUTE_M_INVERSE_Q                       10507 ns        10500 ns        66520
  DerivativesFixture/COMPUTE_M_INVERSE                          5036 ns         5036 ns       139458
  DerivativesFixture/COMPUTE_CHOLESKY_M_INVERSE                17365 ns        17364 ns        40261

Checklist

  • I have run pre-commit run --all-files or pixi run lint
  • I have performed a self-review of my own code
  • I have commented my code where necessary
  • I have made corresponding changes to the doxygen documentation
  • I have added tests that prove my fix or feature works
  • I have updated the CHANGELOG or added the "no changelog" label if it's a CI-related issue
  • I have updated the README credits section

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋 Hi,
This is a reminder message to assign an extra build label to this Pull Request if needed.
By default, this PR will be build with minimal build options (URDF support and Python bindings)
The possible extra labels are:

  • build_collision (build Pinocchio with coal support)
  • build_casadi (build Pinocchio with CasADi support)
  • build_autodiff (build Pinocchio with CppAD support)
  • build_codegen (build Pinocchio with CppADCodeGen support)
  • build_extra (build Pinocchio with extra algorithms)
  • build_mpfr (build Pinocchio with Boost.Multiprecision support)
  • build_sdf (build Pinocchio with SDF parser)
  • build_accelerate (build Pinocchio with APPLE Accelerate framework support)
  • build_all (build Pinocchio with ALL the options stated above)

Thanks.
The Pinocchio development team.

@jorisv

jorisv commented May 19, 2026

Copy link
Copy Markdown
Contributor

Hello @shubhamsingh91,

Thanks for the contribution. Can you add in your PR message a description of this contribution content ?
Also, did you use any AI tools to write some part of this PR ?

@jcarpent

Copy link
Copy Markdown
Contributor

Thanks a lot @shubhamsingh91 for this very nice and helpful contribution. Will be highly useful for the entire community.

@shubhamsingh91
shubhamsingh91 force-pushed the topic/aba-second-order-derivatives branch from 43fdba2 to e314065 Compare May 23, 2026 00:47
@shubhamsingh91

shubhamsingh91 commented May 23, 2026

Copy link
Copy Markdown
Contributor Author

@jorisv Yes! i ported over the core algorithm from my own implementation in a separate Pinocchio fork, a while back. I used Claude code to write some parts and formatting.
Could you apply the build_all label since this is a new templated algorithm?

@shubhamsingh91
shubhamsingh91 marked this pull request as ready for review May 23, 2026 01:02
@shubhamsingh91
shubhamsingh91 force-pushed the topic/aba-second-order-derivatives branch 2 times, most recently from 380522e to 09a177f Compare May 23, 2026 13:31
shubhamsingh91 added a commit to shubhamsingh91/pinocchio that referenced this pull request May 23, 2026
The per-column forward sweep in ComputeABASecondOrderDerivatives was
recomputing q-dependent quantities (jdata via jmodel.calc, liMi, oMi,
J_cols, and the leaf body inertia in world frame) on every one of the
3*nv iterations, even though they only depend on q and are already
populated by the preceding computeABADerivatives and
ComputeRNEASecondOrderDerivatives calls.

Restrict the per-column forward visitor to the acceleration-dependent
work only: propagate data.oa[i] with zero gravity at the root, write
ddJ_cols = oa x J_cols, reset data.oYcrb[i] to the cached leaf value
(which the backward sweep then composites in place), and compute
data.of[i] = oYcrb[i] * oa. The leaf body inertia is cached once in
oYcrb_leaf before the loop, since the backward sweep mutates
data.oYcrb on each per-column iteration.

For humanoidRandom (nv=32) this drops ComputeABASecondOrderDerivatives
median from ~2765us to ~2524us (~9 percent faster).

Refs: stack-of-tasks#2891
@shubhamsingh91

Copy link
Copy Markdown
Contributor Author

@AjSat @jorisv @jcarpent , I am ready for the review!

@shubhamsingh91
shubhamsingh91 force-pushed the topic/aba-second-order-derivatives branch from 718c42a to 6f3ee4b Compare July 4, 2026 00:48
Add ComputeABASecondOrderDerivatives, which evaluates the second-order
partial derivatives of the Articulated Body Algorithm with respect to
the joint configuration, velocity and torque. The four non-trivially
non-zero tensors d2ddq_dqdq, d2ddq_dvdv, d2ddq_dqdv and d2ddq_dtaudq
are also added to Data so the algorithm has matching scratch storage,
and they are wired into the equality operator and serialization.

The algorithm reuses computeABADerivatives and
ComputeRNEASecondOrderDerivatives, then applies the chain-rule identity
from Singh & Wensing, IEEE T-RO 2023
(https://ieeexplore.ieee.org/abstract/document/10449483) via a single
Direct Matrix Multiplication with -M^-1, producing all four output
tensors in one pass.

Storage conventions follow the existing SO RNEA tensors: rows index
the output joint-acceleration component, columns index the inner
derivative variable, and pages index the outer derivative variable.

Refs: stack-of-tasks#2691
Validate ComputeABASecondOrderDerivatives on the humanoidRandom model
by comparing each of the four output tensors against a finite-difference
reference built from computeABADerivatives at perturbed q and v, and
also check that the Data-member overload agrees with the explicit
4-tensor output overload.

Refs: stack-of-tasks#2691
Time ComputeABASecondOrderDerivatives alongside the existing
COMUTE_RNEA_SECOND_ORDER_DERIVATIVES entry in
benchmark/timings-derivatives.cpp.

Refs: stack-of-tasks#2691
@shubhamsingh91
shubhamsingh91 force-pushed the topic/aba-second-order-derivatives branch from 6f3ee4b to 17deb0e Compare July 9, 2026 00:48
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.

3 participants