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 barabasi_albert_graph random graph functions #1007

Merged
merged 4 commits into from
Oct 18, 2023

Conversation

mtreinish
Copy link
Member

This commit adds new random graph functions to rustworkx and rustworkx-core to implement a random graph generator using the Barabási–Albert preferential attachment method. It takes an input graph (defaulting to a star graph) and then extends it to a given size.

This commit adds new random graph functions to rustworkx and
rustworkx-core to implement a random graph generator using the
Barabási–Albert preferential attachment method. It takes an input graph
(defaulting to a star graph) and then extends it to a given size.
@mtreinish mtreinish added this to the 0.14.0 milestone Oct 17, 2023
@coveralls
Copy link

coveralls commented Oct 17, 2023

Pull Request Test Coverage Report for Build 6567441488

  • 136 of 137 (99.27%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.02%) to 96.546%

Changes Missing Coverage Covered Lines Changed/Added Lines %
rustworkx-core/src/generators/random_graph.rs 64 65 98.46%
Totals Coverage Status
Change from base Build 6563426324: 0.02%
Covered Lines: 15680
Relevant Lines: 16241

💛 - Coveralls

@mtreinish mtreinish requested a review from enavarro51 October 17, 2023 14:56
@enavarro51
Copy link
Contributor

I'll take a look at this.

Copy link
Contributor

@enavarro51 enavarro51 left a comment

Choose a reason for hiding this comment

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

A few minor changes and a couple of questions.

rustworkx-core/src/generators/random_graph.rs Outdated Show resolved Hide resolved
src/random_graph.rs Outdated Show resolved Hide resolved
src/random_graph.rs Outdated Show resolved Hide resolved
n,
m,
seed,
initial_graph.map(|x| x.graph),
Copy link
Contributor

Choose a reason for hiding this comment

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

Not exactly sure what this line is doing.

Copy link
Member Author

Choose a reason for hiding this comment

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

Option<T>.map() is just syntactical sugar and this is the equivalent of

match initial_graph {
    Some(graph) => Some(graph.graph),
    None => None,
}

Basically the type for initial_graph is Option<PyGraph> but the rustworkx-core function needs Option<StablePyGraph> so I'm using a map here to pass the inner .graph attribute if initial graph is set.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, got it. Thanks.

src/random_graph.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@enavarro51 enavarro51 left a comment

Choose a reason for hiding this comment

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

LGTM.

@enavarro51 enavarro51 added the automerge Queue a approved PR for merging label Oct 18, 2023
@mergify mergify bot merged commit a424009 into Qiskit:main Oct 18, 2023
26 checks passed
@mtreinish mtreinish deleted the albert-graphs branch October 23, 2023 16:07
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.

3 participants