borglab / gtsam

GTSAM is a library of C++ classes that implement smoothing and mapping (SAM) in robotics and vision, using factor graphs and Bayes networks as the underlying computing paradigm rather than sparse matrices.
http://gtsam.org
Other
2.47k stars 742 forks source link

Add ExpressionFactor to Python Wrapper. #1756

Open Luke20000429 opened 1 month ago

Luke20000429 commented 1 month ago

Feature

Add ExpressionFactor to Python Wrapper so that users don't have to manually calculate the derivatives of custom factors.

Motivation

I am building some custom factors with gtsam Python. Looks like I cannot call gtsam.ExpressionFactor due to "no Attribute" error. Because there are quite a lot of nonlinear constraints. It will make my work much easier if AD can be included in gtsam python.

Alternatives

Any other way to use AD in gtsam python when building custom factors?

ProfFan commented 1 month ago

CustomFactor are really just normal Python code so you can use any Python-based AD code to write stuff. However that also means GTSAM types cannot be used.

We have previously considered wrapping ExpressionFactors but no one in the team has any bandwidth to do it. I did a preliminary investigation on doing it, and I think it's doable, so if you want to give it a try, please do :)

Luke20000429 commented 1 month ago

Will that be easier if I just wrap the NumericDerivative to Python?

ProfFan commented 3 weeks ago

@Luke20000429 Actually you are probably right, if numerical derivative works for you that is the easiest!