Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISAM2: Add variables before computing delta #1707

Merged
merged 3 commits into from
Aug 25, 2024
Merged

ISAM2: Add variables before computing delta #1707

merged 3 commits into from
Aug 25, 2024

Conversation

varunagrawal
Copy link
Collaborator

@varunagrawal varunagrawal commented Jan 8, 2024

Fixes #301

A gtsam::ValuesKeyDoesNotExist error is thrown from the function nonlinearFactors_.error(theta_).
The issue is that nonlinearFactors_.error(theta_) is computed as an argument to DoglegOptimizerImpl::Iterate, where a factor with the new key exists but theta_ has not been updated with the new key-value pairs yet.

It is a simple quirk that Dogleg requires the updated Values since it needs them to compute the delta update via the dogleg point.

The issue in ISAM2::update is that the delta update is computed first to check for relinearization before the new factors and Values are added. The delta update calls the above nonlinearFactors_.error(theta_) method with missing keys in theta_ leading to the exception.

Thus the fix is to add in the new variables newTheta with addVariable(newTheta) before the call to updateDelta(updateParams.forceFullSolve);. AFAIAA this step is to do with fluid relinearization and shouldn't affect the LM path since we call addVariable(newTheta) before the actual update step in both the LM and Dogleg cases.

Update: Piggybacking on this PR to also fix #1672.

@varunagrawal varunagrawal added the bugfix Fixes an issue or bug label Jan 8, 2024
@varunagrawal varunagrawal requested a review from dellaert January 8, 2024 01:24
@varunagrawal varunagrawal self-assigned this Jan 8, 2024
@varunagrawal varunagrawal added the quick-review Quick and easy PR to review label Jan 8, 2024
@varunagrawal varunagrawal requested a review from ProfFan May 30, 2024 18:56
Copy link
Member

@dellaert dellaert left a comment

Choose a reason for hiding this comment

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

Touching the internals of iSAM2 needs a bit more explanation. So, two requests:

  • Outline the changes you made in iSAM2, and say why they were needed for the Dogleg path, and why the don't disturb the LM path. Just a matter of providing your understanding in the MR for tracking and reviewing purposes.
  • if the test was grabbed from an external contributor, you might want to add comments in the code to that effect and also a link to the issue.

@varunagrawal
Copy link
Collaborator Author

@dellaert I updated the PR comment to reflect the understanding behind the fix.

About the unit test, @kvmanohar22 was kind enough to create a script illustrating the problem, but I came up with the unit test for it based on my understanding of his script and debugging the issue. His script is instead based on the SFM SmartFactor example you wrote, so I am a bit tangled up about the credit assignment here.

@varunagrawal varunagrawal requested a review from dellaert June 25, 2024 22:22
@varunagrawal varunagrawal requested review from dellaert and removed request for ProfFan and dellaert August 23, 2024 00:16
@varunagrawal varunagrawal requested a review from dellaert August 25, 2024 20:42
Copy link
Member

@dellaert dellaert left a comment

Choose a reason for hiding this comment

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

Awesome, thanks both!

@varunagrawal varunagrawal merged commit 38a7ad7 into develop Aug 25, 2024
31 checks passed
@varunagrawal varunagrawal deleted the fix-301 branch August 25, 2024 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Fixes an issue or bug quick-review Quick and easy PR to review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rot2::fromCosSin normalizes when header indicates it should not Bug while using dogleg optimizer
2 participants