symforce-org / symforce

Fast symbolic computation, code generation, and nonlinear optimization for robotics
https://symforce.org
Apache License 2.0
1.41k stars 145 forks source link

Debug option to print inputs and outputs of all factors #220

Open aaron-skydio opened 2 years ago

aaron-skydio commented 2 years ago

Is your feature request related to a problem? Please describe. It's often useful to print out the inputs and outputs of a factor for debugging purposes. Primarily just the residual, although the error could also be useful. Linearization may also be useful, but not as commonly and will be very verbose.

Describe the solution you'd like A flag in the optimizer params, or possibly a compile-time option

Probably the best place for this is in sym::Factor. Could instead generate something into the residuals themselves, but that introduces a dependency from generated functions to spdlog (possibly behind a compile-time option, but still). This would also mean we'd need some way to capture inputs bound in at factor creation time, as opposed to stored in the Values. It's possible we want to eliminate any performance advantage of doing this, and say everything should always be in the Values, or we may want to implement #42 and make this part of that.

Describe alternatives you've considered Additional options would be to print outputs for some factors, but printing for all would be useful and less work. At some point we may want both.

We could instead implement an option to extract all the (linearized?) factors from an Optimizer/Linearizer, but I think this will be more friendly? Not sure