Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrapper for derivative.cpp #17

Open
thowell opened this issue Jan 22, 2021 · 8 comments
Open

wrapper for derivative.cpp #17

thowell opened this issue Jan 22, 2021 · 8 comments

Comments

@thowell
Copy link

thowell commented Jan 22, 2021

Awesome work!! Would love to use these packages for model-based control, is there functionality for derivatives implemented anywhere in the Lyceum ecosystem?

@klowrey
Copy link
Contributor

klowrey commented Feb 26, 2021

I'm actually working on it now to jive well with Lyceum, but it's a little challenging to still retain efficiency with auto-diff. Shouldn't be too long now, however.

copying the code from the derivative.cpp example to just use MuJoCo.jl is feasible as well, but doesn't benefit from the extended ecosystem.

@thowell
Copy link
Author

thowell commented Apr 2, 2021

Any progress on this? If you can give me some pointers, I might be able to implement this functionality.

@klowrey
Copy link
Contributor

klowrey commented Apr 3, 2021

The tricky part is the interaction between an AbstractEnv and MJSim, since sometimes one or the other needs the differentiation. To handle it I'm using ChainRulesCore.jl composites to manually handle what fields we're differentiating for.

If you just wanted a port of derivative.cpp from the mujoco sample code, I have that around here as well but that's if you're working more with MuJoCo rather than the Lyceum interface.

@klowrey
Copy link
Contributor

klowrey commented Apr 9, 2021

Any progress on this? If you can give me some pointers, I might be able to implement this functionality.

What use case did you need derivatives for? You mention mode based control so that could be as simple as derivatives for mj_forward / mj_inverse, or if you wanted generality that would be like differentiating through the Lyceum Api.

It would be nice to know if some other work flow so I'm not missing use cases as I'm trying to get autodiff to play well.

@thowell
Copy link
Author

thowell commented Apr 9, 2021

just the basic derivatives, this would be for the mj_forward and mj_inverse. we want to do model-predictive control (e.g., using iterative LQR)

@klowrey
Copy link
Contributor

klowrey commented Apr 17, 2021

https://gist.github.com/klowrey/b9ba2e7194e4aa30bd12ee9cc393bc72 here is a port of the derivative.cpp code to julia. it includes the analytical way of checking between inverse and forward and should be the same as derivative.cpp.

as a note, sometimes the Julia threading overhead is larger than pthreads/c++ so depending on your application you may want to run it single threaded and parallelize with other means.

If you're using ILQG from https://github.com/baggepinnen/DifferentialDynamicProgramming.jl I'd love to know how it turns out. I never had much luck with iLQG for complex models; MPPI often worked better and the reward function was easier to debug, all without needing derivatives.

I was converting lyceum to be automatically differentiable in order to use it through Neural ODE frameworks, which is an adjecent idea to trajectory optimization.

@mfogelson
Copy link

It seems like some functions are missing from MuJoCo.MJCore, like mju_quatIntegrate. so I cant run get_acceljac

@klowrey
Copy link
Contributor

klowrey commented May 3, 2021

I made a branch of this repo titled quat for those functions, but have not merged it into master to avoid potential breakings.

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

No branches or pull requests

3 participants