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

GTDKeyformatter is not working #131

Closed
varunagrawal opened this issue Apr 6, 2021 · 6 comments · Fixed by #136 or #138
Closed

GTDKeyformatter is not working #131

varunagrawal opened this issue Apr 6, 2021 · 6 comments · Fixed by #136 or #138
Assignees
Labels
bug Something isn't working

Comments

@varunagrawal
Copy link
Collaborator

If I print out the graph in test_dynamics_graph.py, I get the following which doesn't have the keys correctly formatted.

Factor 0: pose factor
  keys = { 31526292608253952 31527392119881728 32087047833387008 }
isotropic dim=6 sigma=0.001

Factor 1: pose factor
  keys = { 31527392119881728 31528491631509504 32087052128354304 }
isotropic dim=6 sigma=0.001

Factor 2: twist factor
  keys = { 24207943213776896 24209042725404672 32087047833387008 33494422716940288 }
isotropic dim=6 sigma=0.001

Factor 3: twist factor
  keys = { 24209042725404672 24210142237032448 32087052128354304 33494427011907584 }
isotropic dim=6 sigma=0.001

Factor 4: twist acceleration factor
  keys = { 24209042725404672 18296968702853120 18298068214480896 32087047833387008 33494422716940288 27583448206016512 }
isotropic dim=6 sigma=0.001

Factor 5: twist acceleration factor
  keys = { 24210142237032448 18298068214480896 18299167726108672 32087052128354304 33494427011907584 27583452500983808 }
isotropic dim=6 sigma=0.001

Factor 6: wrench factor
  keys = { 24207943213776896 18296968702853120 31526292608253952 19703248369745920 }
isotropic dim=6 sigma=0.001

Factor 7: wrench factor
  keys = { 24209042725404672 18298068214480896 31527392119881728 19704347881373696 19704352176340992 }
isotropic dim=6 sigma=0.001

Factor 8: wrench factor
  keys = { 24210142237032448 18299167726108672 31528491631509504 19705451687968768 }
isotropic dim=6 sigma=0.001

Factor 9: wrench equivalence factor
  keys = { 19703248369745920 19704347881373696 32087047833387008 }
isotropic dim=6 sigma=0.001

Factor 10: torque factor
  keys = { 19704347881373696 23924273508777984 }
isotropic dim=1 sigma=0.001

Factor 11: wrench equivalence factor
  keys = { 19704352176340992 19705451687968768 32087052128354304 }
isotropic dim=6 sigma=0.001

Factor 12: torque factor
  keys = { 19705451687968768 23924277803745280 }
isotropic dim=1 sigma=0.001
@varunagrawal varunagrawal added the bug Something isn't working label Apr 6, 2021
@yetongumich
Copy link
Collaborator

which function are you using? There's a wrapped function gtd.DynamicsGraph.printGraph() which uses the GTDKeyFormatter. Try it?

@varunagrawal
Copy link
Collaborator Author

I see. It should also be compatible with NonlinearFactorGraph::print and Values::print so that it is useful for debugging.

@yetongumich
Copy link
Collaborator

I see. It should also be compatible with NonlinearFactorGraph::print and Values::print so that it is useful for debugging.

I'm wondering how it is directly bounded with the default print() function in Python. Is there a way that I can specify the keyformatter when calling the Python print()?

@varunagrawal
Copy link
Collaborator Author

I guess look at the way how GTSAM does it? I believe it takes the key formatter as a default argument so we need to figure out how to achieve that here.

@gchenfc
Copy link
Member

gchenfc commented Apr 7, 2021

python implicit print (__repr__) will call the default print function:
https://github.com/borglab/wrap/blob/5ddaff8bab6c05e8a943c94993bf496e13296dd6/gtwrap/pybind_wrapper.py#L127-L150
overriding print like in e.g. CableLengthFactor:

void print(const std::string &s = "",
const gtsam::KeyFormatter &keyFormatter =
GTDKeyFormatter) const override {
std::cout << s << "cable length factor" << std::endl;
Base::print("", keyFormatter);
}

you can use the gtdynamics formatter by default, but i guess you couldn't override nonlinearfactorgraph's print. Another annoyance is that calling NonlinearFactorGraph::print will then pass on its KeyFormatter (gtsam default key formatter) on to all its children so printing the graph will use the wrong formatter but printing out a single factor works. i.e.

****** print(fg) ******
 size: 1

Factor 0: cable length factor
  keys = { 32087052128354306 31527392119881730 }
  noise model: constrained sigmas[0];
  noise model: constrained mu[1000];


****** print(fg.at(0)) ******
 cable length factor
  keys = { q(1)2 p[1]2 }
  noise model: constrained sigmas[0];
  noise model: constrained mu[1000];

A couple potential solutions would be to:
a) make a static function print(const NonlinearFactorGraph &graph) etc
b) wrap GTDKeyFormatter

@varunagrawal
Copy link
Collaborator Author

Ah thanks for the reminder @gchenfc. Yeah the wrapper defines the __repr__ method which captures the output of .print and returns that, thus forming a bridge. This is because python's print function calls __repr__ (or __str__) on the object to print.

This is when I wish C++ supported protocol based inheritance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants