Python advice for debugging complex datatypes and serialization with networkx objects

Viewed 82

finally getting around to improving my debugging skills now that I'm volunteering on projects regularly--I know, a bit late, but better than never(?).

This is my issue branch. I don't have the issue to show you because it's in Jira and only authorized team members can access the team's Jira account.

Right now I'm finding it hard to "see" the way complex code works from within pdb. Granted, reading docs on other underlying libraries is of course, helpful, but putting everything together to have a better intuition about the underlying processes are still challenging for me.

I'm dealing with one very large, customized datatype:

  1. an OWL file (you can see it here) as input into this function that first turns the OWL file into an networkx object by way of Owlready2
  2. makes tweaks some additional tweaks to the networkx object's nodes, edges, and their attributes,
  3. and then transforms the networkx object into a pickled file.

I'm working on an issue involving step 2.

Apparently, OWL files allow there to be the equivalent of an edge (properties I think?), but it's more like a static type in code we can't change/or customize once made, so attributes can't be saved in its native format--even though the equivalent node objects can. So as a work-around to preserve metadata, edge attributes are stored in the two nodes adjacent to a given edge, after the conversion to networkx, this python script identifies node attribute pairs attached to a given edge type that qualifies to move the node pair's shared attribute to their edge and then delete the attributes from the node pair.

The specific functions are set_edge_properties(G) starting on line 246 and remove_edge_properties_from_nodes(G, to_remove) on line 320. We suspect that the issue is in the generator assigned between lines 334 and 338, where node is not getting deleted based on the to_remove dictionary. Actually, the breakpoints weren't suppose to show up in this branch, I had branched of the issue branch so I could keep this code clean of breakpoints while I figured out how to better use the tool.

Any help or guidance on how I could effectively debug this better and break down this code into something more manage-able that I could actually write a test for would be greatly appreciated.

0 Answers
Related