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

Move complete_graph generator to rustworkx-core #772

Merged
merged 14 commits into from
Jan 14, 2023

Conversation

enavarro51
Copy link
Contributor

This PR migrates the complete_graph generator to rustworkx-core. It's based on #758.

@enavarro51 enavarro51 changed the title Move complete graph generator to rustworkx-core Move complete_graph generator to rustworkx-core Jan 5, 2023
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.

For historical reasons we have both the mesh_graph and complete_graph generators. complete_graph is the name found in most libraries and it aliases to the implementation we had first. We need to keep this in mind when porting. it is okay to call the implementation from rustworkx-core we just need to keep the functions being aliases of each other.

src/generators.rs Show resolved Hide resolved
src/generators.rs Show resolved Hide resolved
@coveralls
Copy link

coveralls commented Jan 6, 2023

Pull Request Test Coverage Report for Build 3915862605

  • 69 of 69 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.03%) to 96.972%

Totals Coverage Status
Change from base Build 3915837413: -0.03%
Covered Lines: 13577
Relevant Lines: 14001

💛 - Coveralls

@mtreinish mtreinish added this to the 0.13.0 milestone Jan 11, 2023
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 added some comments about aliasing mesh_graph and directed_mesh_graph to avoid code duplication. After the aliases are there I think it should be good to go

Comment on lines 477 to 452
if weights.is_none() && num_nodes.is_none() {
return Err(PyIndexError::new_err(
"num_nodes and weights list not specified",
));
}
let node_len = get_num_nodes(&num_nodes, &weights);
if node_len == 0 {
return Ok(graph::PyGraph {
graph: StablePyGraph::<Undirected>::default(),
node_removed: false,
multigraph,
attrs: py.None(),
});
}
let num_edges = (node_len * (node_len - 1)) / 2;
let mut graph = StablePyGraph::<Undirected>::with_capacity(node_len, num_edges);
match weights {
Some(weights) => {
for weight in weights {
graph.add_node(weight);
let default_fn = || py.None();
let graph: StablePyGraph<Undirected> =
match core_generators::complete_graph(num_nodes, weights, default_fn, default_fn) {
Ok(graph) => graph,
Err(_) => {
return Err(PyIndexError::new_err(
"num_nodes and weights list not specified",
))
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would replace this with complete_graph(py, num_nodes, weights, multigraph) to avoid duplicate code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. Got it. It's on the way...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in af75626.

Comment on lines -553 to -525
if weights.is_none() && num_nodes.is_none() {
return Err(PyIndexError::new_err(
"num_nodes and weights list not specified",
));
}
let node_len = get_num_nodes(&num_nodes, &weights);
if node_len == 0 {
return Ok(digraph::PyDiGraph {
graph: StablePyGraph::<Directed>::default(),
node_removed: false,
check_cycle: false,
cycle_state: algo::DfsSpace::default(),
multigraph,
attrs: py.None(),
});
}
let num_edges = node_len * (node_len - 1);
let mut graph = StablePyGraph::<Directed>::with_capacity(node_len, num_edges);
match weights {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same apllies here, I'd call directed_mesh_graph(py, num_nodes, weights, multigraph)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in af75626.

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.

Awesome

@IvanIsCoding IvanIsCoding added the automerge Queue a approved PR for merging label Jan 14, 2023
@mergify mergify bot merged commit 301f6e8 into Qiskit:main Jan 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Queue a approved PR for merging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants