0
autodiff_diagram = diagram.ToAutoDiffXd()
autodiff_context = autodiff_diagram.CreateDefaultContext()
autodiff_plant = autodiff_diagram.GetSubsystemByName("plant")

Let's say I want to have a bunch of random initializations and run optimization over the same autodiff diagram (computational graph) each time. What's the cleanest way to do so?

I tried looking in the pydrake docs for "zero gradient" and similar things. I found some references to "DiscardGradient" but there was no actual result in the docs for that. As a side note, it would be helpful to have a meta-learning advice on how to navigate the Drake docs/code to answer this type of question myself, I am having trouble doing that.

user3180
  • 1,369
  • 1
  • 21
  • 38

1 Answers1

0

I think you’re looking for initializeAutoDiff, and the associated methods. For your meta question, using google to search (e.g. autodiff site:drake.mit.edu) sometimes finds things that the search functionality in doxygen/sphinx does not.

If you want to run many simulations like this, you might want to do that in parallel. Most every system in Drake should be thread-safe given that you use one context per thread. You can take a look at how we implement MonteCarloSimulation for an example of that.

Russ Tedrake
  • 4,703
  • 1
  • 7
  • 10