How to use C++ Backend with Python Optimization API #368
-
The SymForce diagram in the README implies that it is possible to use the C++ Backend — i.e., to use runtime C++ code for factors as produced by Thanks! (And thanks also for the work you put into this project - it's very nice.) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
I'm not sure if there's a full example of this unfortunately. Looking at our examples folder I see examples of using the python optimizer with python factors and examples of using the C++ optimizer with C++ factors, but I don't think we have an example of using C++ factors with they python optimizer (though this would be nice to have if you make one!). If you wanted to do this, I believe you would have to pybind wrap the C++ factor yourself so that it's callable from python, then create a NumericFactor with the wrapped function, then pass the NumericFactor to the python optimizer. Note that the "python optimizer" is just a wrapped version of the C++ optimizer though, so if you're trying to reduce solve time while still kicking off the optimization from python, it would likely make the most sense to pass your C++ factor to the C++ optimizer directly inside a pybind wrapped function. E.g. pybind wrap a helper function which takes your optimization problem inputs as an argument, builds your C++ factors and runs the C++ optimizer, and then returns the optimization result. |
Beta Was this translation helpful? Give feedback.
-
I will say that this isn't something we've done much at all, and I can't really say whether or in what cases you'll get better performance from doing this than using python-generated factors, possibly compiled with numba |
Beta Was this translation helpful? Give feedback.
I'm not sure if there's a full example of this unfortunately. Looking at our examples folder I see examples of using the python optimizer with python factors and examples of using the C++ optimizer with C++ factors, but I don't think we have an example of using C++ factors with they python optimizer (though this would be nice to have if you make one!).
If you wanted to do this, I believe you would have to pybind wrap the C++ factor yourself so that it's callable from python, then create a NumericFactor with the wrapped function, then pass the NumericFactor to the python optimizer.
Note that the "python optimizer" is just a wrapped version of the C++ optimizer though, so if you're trying t…