-
Notifications
You must be signed in to change notification settings - Fork 195
Graph6 DiGaph6 Sparse6 support #1500
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
base: main
Are you sure you want to change the base?
Conversation
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left many comments:
- We control all the code, please don't
panic!orunwrap. ReturnResult<T, E>. - Python tests live in
tests/. We only use#[cfg(test)]inrustworkx-core. Either migrate the tests or remove them - For universal functions, please use
_rustworkx_dispatch. We don't need Python modules forgraph6,digraph6, andsparse6.
Please take a look at https://github.com/Qiskit/rustworkx/blob/main/CONTRIBUTING.md, especially for formatting, tests, and adding type annotations.
tests/test_graph6.py
Outdated
|
|
||
| def test_read_graph6_file(self): | ||
| """Test reading a graph from a graph6 file.""" | ||
| with tempfile.NamedTemporaryFile(mode="w", delete=False) as fd: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see why the whole test couldn't exist within the with statement. I'd rather not have a os.remove statement and let tempfile deal with it
Example:
| with tempfile.NamedTemporaryFile() as fd: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use tempfile now
tests/test_graph6.py
Outdated
| content = f.read() | ||
| self.assertEqual(content, "C~") | ||
| finally: | ||
| os.remove(path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment for all occurrences
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
| def test_write_and_read_triangle(self): | ||
| g = rx.PyGraph() | ||
| g.add_nodes_from([None, None, None]) | ||
| g.add_edges_from([(0, 1, None), (1, 2, None), (0, 2, None)]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or the directed equivalent.
https://www.rustworkx.org/dev/apiref/rustworkx.generators.complete_graph.html works as well for n=3
| with self.assertRaises(rx.Graph6ParseError): | ||
| rx.parse_graph6_size(bad_hdr) | ||
|
|
||
| def test_overflow(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A comment explaining this test would be great, especially bitwise manipulations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commented
tests/test_sparse6.py
Outdated
| self.assertEqual(g2.num_edges(), g.num_edges()) | ||
|
|
||
|
|
||
| if __name__ == '__main__': # pragma: no cover |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not necessary, you can remove it from all files. we use stestr python -m unittest also handles it AFAIK in our release
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
| @@ -0,0 +1,48 @@ | |||
| features: | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please read https://docs.openstack.org/reno/latest/user/usage.html#editing-a-release-note for the correct format of release notes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
used reno to generate one with nox -e docs compatible doc
src/graph6.rs
Outdated
| DiGraph(DiGraph), | ||
| } | ||
|
|
||
| let wrapped = std::panic::catch_unwind(|| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not use std::panic::catch_unwind. If you need to return an error use, Result as a return type with Err. Not panic! or unwrap.
This will likely break with WASM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
rustworkx/digraph6.py
Outdated
| @@ -0,0 +1,30 @@ | |||
| """digraph6 format helpers. | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now, this wrapper is pointless:
- For writing, see for the correct pattern
rustworkx/rustworkx/__init__.py
Line 2285 in 7318a80
def write_graphml(graph, path, /, keys=None, compression=None): - For reading, if the file format contains the hint: use the same pattern from . If it doesn't, then just have two functions
Line 1248 in 7318a80
pub fn read_graphml<'py>( digraph_read_graph6andgraph_read_graph6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed graph6.py, digraph6.py, sparse6.py and use a write_graph6 function in init with _rustworkx_dispatch
src/digraph6.rs
Outdated
|
|
||
| #[pyfunction] | ||
| #[pyo3(signature=(digraph, path))] | ||
| pub fn digraph_write_graph6_file(digraph: Py<crate::digraph::PyDiGraph>, path: &str) -> PyResult<()> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just call the methods that write to file *_write_graph6, *_write_sparse6, etc. For methods that write to string, use to_str or from_str.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The naming is now graph_write_graph6 digraph_write_graph6
|
Thanks @IvanIsCoding for all the suggestion |
https://github.com/Qiskit/rustworkx/issues/1496