Passing "complicated" types as arguments #2135
Unanswered
nickbianco
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am following up from my discussion board entry at #1870, where I have successfully created a project where (in some cases) I can take derivatives through Simbody with Enzyme. This seems promising, but now I've encountered some new roadblocks as I try to take derivatives through more complicated function calls which are more relevant for my intended use case.
Below is a minimum working example based on my sandbox project for testing Simbody derivatives with Enzyme. This example, like most of the calculations I care about, require calling functions that take a Simbody
SimTK::State
as an argument.SimTK::State
primarily holds the values of state variables for a multibody system (e.g., coordinate values and speeds) at a given time point of a simulation. It also holds quantities that are the result of advancing the multibody system through all calculations needed to perform each time step of a simulation (e.g., coordinate accelerations, kinematic constraint errors, etc.).In practice, will need to take the derivative of a value (e.g., kinetic energy, as in the example below) with respect to one or more of the quantities in the
SimTK::State
. For example, I might wantdKEdu0
, whereu0
is the first coordinate speed in theSimTK::State
:double u0 = getU()[0]
.What is the best practice for taking such a derivative? I tried to follow this example on the website about using "complicated" types as arguments, but I'm not sure how Enzyme interprets cases where something a
SimTK::State
is passed as a shadow argument. I am able to run the example below, but only when passingLLDEnzymeLooseTypeFlags
and the derivative does not match the expected analytical derivative value.I've tried a few other things (e.g., wrapping the function call I needed with a custom class method that takes only the duplicated arguments I want), but for brevity's sake, I will stop here for now. I will keep digging, but any guidance would be appreciated!
Beta Was this translation helpful? Give feedback.
All reactions