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

Add functions to parse node link JSON #1091

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

mtreinish
Copy link
Member

This commit adds the missing functionality to parse node link json and generate rustworkx graph objects from it. This adds two new functions parse_node_link_json_str() to parse a node link json string and parse_node_link_json_file() to parse a node link json file from a path.

Partial #840

This commit adds the missing functionality to parse node link json and
generate rustworkx graph objects from it. This adds two new functions
parse_node_link_json_str() to parse a node link json string and
parse_node_link_json_file() to parse a node link json file from a path.

Partial Qiskit#840
@coveralls
Copy link

coveralls commented Feb 16, 2024

Pull Request Test Coverage Report for Build 7937155302

Details

  • -11 of 125 (91.2%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.04%) to 96.529%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/json/node_link_data.rs 23 25 92.0%
src/json/mod.rs 84 93 90.32%
Totals Coverage Status
Change from base Build 7880161745: -0.04%
Covered Lines: 16854
Relevant Lines: 17460

💛 - Coveralls

@mtreinish mtreinish added this to the 0.15.0 milestone Feb 21, 2024
Copy link
Collaborator

@IvanIsCoding IvanIsCoding left a comment

Choose a reason for hiding this comment

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

I think this is a great addition. The code is very succint and I think we leverage serde well.

My main concern is with the function naming. Maybe we could have rustworkx.parse_node_link_json for the string case and rustworkx.node_link_json_from_file for the file case? I just found parse_node_link_json_str a name that leaves a bad taste in the mouth

I also left a comment about the NetworkX round-trip test. If the test passes, I wonder how fast it will be compared to the current NetworkX.

Comment on lines +11 to +12
rustworkx.parse_node_link_json_file
rustworkx.parse_node_link_json_str
Copy link
Collaborator

Choose a reason for hiding this comment

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

I really dislike the name of the functions. Maybe we can come up with alternatives? They feel ugly

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I wasn't happy with them either tbh. I'll switch them to your suggested parse_node_link_json and node_link_json_from_file those are better names.

self.assertEqual(new.weighted_edge_list(), graph.weighted_edge_list())
self.assertEqual(new.attrs, graph.attrs)

def test_round_trip_with_file(self):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Overall this is super cool! Do you think we should add a round trip (optional) test where we write from NetworkX and them import it in Rustworkx?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, that's simple enough to add.

Copy link
Member Author

Choose a reason for hiding this comment

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

This was a good call to add a test for this. The parser is overly strict because it's assuming there was always an id field for edges which networkx doesn't always populate in it's node link json. This isn't required in the format, so I'll tweak the parser to make it optional.

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.

None yet

3 participants