Skip to content

Conversation

@d-miketa
Copy link
Contributor

Addresses #1516: JSON roundtrip is broken whenever the graph contains deleted (or contracted) nodes.

This leaves just the GraphML format as incapable of a clean round-trip.

@coveralls
Copy link

coveralls commented Oct 16, 2025

Pull Request Test Coverage Report for Build 21502772359

Details

  • 53 of 69 (76.81%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.06%) to 94.167%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/json/mod.rs 28 32 87.5%
src/json/node_link_data.rs 25 37 67.57%
Totals Coverage Status
Change from base Build 21501003099: -0.06%
Covered Lines: 18388
Relevant Lines: 19527

💛 - Coveralls

@IvanIsCoding
Copy link
Collaborator

I will take a look at this during the weekend. Thanks for sending the fix for an issue you found!

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.

Excellent test cases! I have no doubt this works, I just left some comments on what should be improved in Rust.


id_mapping.insert(node_id, idx);
// Mark this index as used (remove from tmp_nodes)
tmp_nodes.retain(|&n| n != idx);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can lead to quadratic behaviour, we are looping through all tmp_nodes to delete the index.

Please use https://docs.rs/hashbrown/latest/hashbrown/struct.HashSet.html instead

self.assertEqual(g.node_indices(), gprime.node_indices())
self.assertEqual(g.edge_list(), gprime.edge_list())
self.assertEqual(g.nodes(), gprime.nodes())
self.assertEqual(dict(g.edge_index_map()), dict(gprime.edge_index_map()))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Of course you copied examples that don't use it but: https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertDictEqual

This just has a nicer error message, in case someone ever introduces a bug

@IvanIsCoding
Copy link
Collaborator

Also, you'll need to solve some minor conflicts with #1510

@IvanIsCoding IvanIsCoding mentioned this pull request Dec 15, 2025
@IvanIsCoding IvanIsCoding added this pull request to the merge queue Jan 30, 2026
Merged via the queue into Qiskit:main with commit c94e03f Jan 30, 2026
37 checks passed
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.

3 participants