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

Added Mesh and Grid graph generator #191

Merged
merged 9 commits into from
Nov 13, 2020
Merged

Added Mesh and Grid graph generator #191

merged 9 commits into from
Nov 13, 2020

Conversation

darknight009
Copy link
Contributor

@darknight009 darknight009 commented Nov 8, 2020

#150 Adds both directed and undirected versions of Mesh and Grid graph generators.
This PR doesn't add test cases for Grid generator as it is unclear how the weights will be passed for the grid. As a multidimensional array or a flattened array?
@mtreinish Please let me know how to proceed with that

@coveralls
Copy link

coveralls commented Nov 8, 2020

Pull Request Test Coverage Report for Build 361925241

  • 145 of 153 (94.77%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.02%) to 94.476%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/generators.rs 145 153 94.77%
Totals Coverage Status
Change from base Build 358636494: 0.02%
Covered Lines: 2805
Relevant Lines: 2969

💛 - Coveralls

@mtreinish
Copy link
Member

@darknight009 thanks for pushing this. Hmm, I hadn't thought about that, but I'd probably just go with a flattened array. It's consistent with the other generator methods and easier to deal with. We just need to make sure it's documented the order it's used, row major or column major.

Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

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

Thanks for pushing the update. From a quick pass through the code looks good, I left a few initial comments inline mostly around docs cleanups and some edge case handling. But, I haven't dug through each line in depth yet. Besides the docs failure (which I outlined how to fix inline I think). Can you also add an example with the graphviz visualization to the docs? It's kind of nice for the generator documentation to visualize the graph so people can see them in the documentation. Basically something like: https://github.com/Qiskit/retworkx/blob/master/src/generators.rs#L50-L72

/// Generate a directed grid graph. The edges propagate towards right and
/// bottom direction if ``bidirectional`` is ``false``
///
//// :param int rows: The number of rows to generate the graph with.
Copy link
Member

Choose a reason for hiding this comment

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

This should fix the failing docs build I think:

Suggested change
//// :param int rows: The number of rows to generate the graph with.
/// :param int rows: The number of rows to generate the graph with.

/// If number of nodes(rows*cols) is greater than length of
/// weights list, extra nodes with None weight are appended
///
/// :returns: The generated star graph
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// :returns: The generated star graph
/// :returns: The generated grid graph

/// :param bidirectional: A parameter to indicate if edges should exist in
/// both directions between nodes
///
/// :returns: The generated star graph
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// :returns: The generated star graph
/// :returns: The generated grid graph

src/generators.rs Show resolved Hide resolved
Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

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

This LGTM, there are 2 inline suggestions that were basically just errors that cargo clippy reported. I should probably add a CI job with it to catch things like this in the future. But after those are fixed this should be ready to go. Thanks for updating the docs.

let mut node_cnt = num_nodes;

for weight in weights {
if node_cnt <= 0 {
Copy link
Member

Choose a reason for hiding this comment

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

I ran cargo clippy on the PR locally and it flagged this. Since node_cnt is a usize it can't ever be less than 0, so they suggested replacing this with:

Suggested change
if node_cnt <= 0 {
if node_cnt == 0 {

let mut node_cnt = num_nodes;

for weight in weights {
if node_cnt <= 0 {
Copy link
Member

Choose a reason for hiding this comment

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

I ran cargo clippy on the PR locally and it flagged this. Since node_cnt is a usize it can't ever be less than 0, so they suggested replacing this with:

Suggested change
if node_cnt <= 0 {
if node_cnt == 0 {

src/generators.rs Show resolved Hide resolved
Fixes Rust Lint error where <0 check was implemented on a usize variable
Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

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

Great, thanks for the update

@mtreinish mtreinish merged commit d6ee63d into Qiskit:master Nov 13, 2020
@darknight009 darknight009 deleted the trasp_gen branch November 13, 2020 16:55
@mtreinish
Copy link
Member

@darknight009 just an fyi thanks to your work on this PR we were able to speed up qiskit-terra's coupling map construction in: Qiskit/qiskit#5469

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