Skip to content

Conversation

@hayk-skydio
Copy link
Contributor

Add a symforce.slam.imu_preintegration module that provides a symbolic implementation of tangent preintegration, and generates Python and C++ runtime functions for the main update function. Also adds a lightweight Python wrapper class to maintain state and tests against GTSAM.

formatted_symbols = []
for j in range(value.shape[1]):
for i in range(value.shape[0]):
formatted_symbols.append(sm.Symbol(f"{key}[{i}, {j}]"))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aaron-skydio @bradley-solliday-skydio I think there's a bug here that we should discuss and work out

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may have addressed it here: dc80387

I'm not sure if this breaks anything with Python codegen yet. There's a decision in play here whether 1D geo vectors get generated as lists, 1D numpy arrays, or 2D numpy arrays.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah cc @nathan-skydio too, I don't think we want to generate them as lists but could see either 1d or 2d numpy arrays

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe generating 2D arrays makes the most sense given that a geo.Matrix always has the number of rows/cols defined, so I'm not sure a 1D geo.Matrix really exists (i.e. I think geo.V3.shape is (3,1), so we might want my_generated_numpy_vec3.shape to be (3,1) instead of (3,)). I don't feel super strongly one way or the other though

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I agree with that. However, in javascript it will be more awkward because it'll be an Array of Arrays or something like that, where if you really just wanted scalars and vectors it adds unnecessary complexity

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With dc80387 we can do this easily per language though right? I think it makes sense for python to use all-2d numpy arrays, since that's easy, but for JS to use 1D arrays for column vectors

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we can do 2D numpy arrays for python and use 1D arrays in JS. Just slightly odd to have different apis like that

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I lean towards just making things 2d everywhere if we want uniformity

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'm a bit torn on the uniformity vs idiomatic use. I wonder if we might just want to introduce a dependency like https://github.com/nicolaspanel/numjs

accel_cov:
gyro_cov:
accel_bias:
gyro_bias:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

populate

import gtsam
except ImportError:
logger.info("Skipping test, GTSAM not installed.")
return
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aaron-skydio curious on thoughts here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think this makes sense to skip if gtsam isn't installed, should make sure this runs in CI (where we install gtsam so we can build the benchmarks, cc @bradley-solliday-skydio ). Should probably also use unittest.skip like we do here for numba

@hayk-skydio
Copy link
Contributor Author

Another thing to discuss @aaron-skydio is that this puts the python generated code into sym.factors. This makes sense to me and matches C++, but I doubt we want it in the symforce-sym package, and also it makes it perhaps so you have to pip install -e . before you can import it (ie the build is required to iterate)

@aaron-skydio
Copy link
Member

I think it seems reasonable to put the generated python factors into symforce-sym, since we'll presumably do the same for C++ generated factor headers. Rerunning pip install -e . to update symforce-sym is something we should additionally fix though

from sym.factors.imu_preintegration_update import imu_preintegration_update


class PreintegratedImu:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have 2 quick questions if I may:

  1. Can we keep the same naming convention as GTSAM? That should make porting code over to symforce much easier.
  2. I've made a bunch of improvements to the ImuFactor, CombinedImuFactor and other parts related to these classes. I was wondering if you're using GTSAM as a code reference or reimplementing this directly from the math? Goes without saying that I am more than happy to provide reviews/help to land this feature. I am considering moving all my PhD work to using Symforce for the long term. :)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@varunagrawal have the updates you mention landed in gtsam develop?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes they have!

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@varunagrawal Oh great. I am nose down on getting this port going and comparing with current gtsam develop. Perhaps I can ping you with a question or two. =)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely! More than happy to help and see this feature landed in Symforce.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glad y'all are interested :)

We're also currently pushing on getting this usable as a factor in the optimizer and getting it merged, it might be worth coordinating and sharing the work (@bradley-solliday-skydio is working on this right now)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bradley-solliday-skydio i would love to discuss. I am working through unit testing the tangent pre-integration piece against gtsam, and finding some differences. Lmk.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@varunagrawal I pinged you on LinkedIn

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any update on this feature?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Hans! @bradley-solliday-skydio is actively working on finishing this up and we should be able to merge it soon

@bradley-solliday-skydio bradley-solliday-skydio force-pushed the imu_preintegration branch 4 times, most recently from 96d9c95 to f02ba16 Compare September 22, 2022 02:25
@bradley-solliday-skydio bradley-solliday-skydio changed the base branch from main to versioned_dev_requirements September 22, 2022 02:26
@bradley-solliday-skydio bradley-solliday-skydio changed the base branch from versioned_dev_requirements to main September 22, 2022 22:51
@bradley-solliday-skydio bradley-solliday-skydio force-pushed the imu_preintegration branch 2 times, most recently from 8972fd4 to aaabed1 Compare September 24, 2022 03:04
Add a symforce.slam.imu_preintegration module that provides a symbolic
implementation of tangent preintegration, and generates Python and C++
runtime functions for the main update function. Also adds a lightweight
Python wrapper class to maintain state and tests against GTSAM.

GitOrigin-RevId: 320a1690e2bef50bff14001408552976bfe2ee5c
@aaron-skydio
Copy link
Member

This was moved to #279, which is now merged - further work on this should be new PR(s)

@aaron-skydio aaron-skydio deleted the imu_preintegration branch March 10, 2023 23:50
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

Successfully merging this pull request may close these issues.

7 participants