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 hyperbolic random graph model generator #1196

Merged
merged 12 commits into from
May 22, 2024

Conversation

SILIZ4
Copy link
Contributor

@SILIZ4 SILIZ4 commented May 18, 2024

This adds a generator for the hyperbolic random graph model. There are two issues I wasn't able to solve:

  1. The model is only defined for undirected graphs. Since any graph structure works with the generator, I used the Data trait and return an error (runtime) when the graph is directed. It's clear to me that it should be a compile error, but I'm not familiar enough with traits and petgraph.
  2. I wasn't able to add LaTeX in the rustworkx-core documentation and so it feels incomplete.

Related to #150. This is my first contribution and I'm very open to suggestions.

SILIZ4 and others added 5 commits May 18, 2024 10:36
…kit#1195)

In the recently merged Qiskit#1192 a new generic DAG longest_path function was
added to rustworkx-core. However, the trait bounds on the function were
a bit tighter than they needed to be. The traits were forcing NodeId to
be of a NodeIndex type and this wasn't really required. The only
requirement that the NodeId type can be put on a hashmap and do a
partial compare (that implements Hash, Eq, and PartialOrd). Also the
IntoNeighborsDirected wasn't required because it's methods weren't ever
used. This commit loosens the traits bounds to facilitate this. At the
same time this also simplifies the code structure a bit to reduce the
separation of the rust code structure in the rustworkx crate using
longest_path().
@coveralls
Copy link

coveralls commented May 18, 2024

Pull Request Test Coverage Report for Build 9189895728

Details

  • 90 of 93 (96.77%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.001%) to 96.504%

Changes Missing Coverage Covered Lines Changed/Added Lines %
rustworkx-core/src/generators/random_graph.rs 69 72 95.83%
Totals Coverage Status
Change from base Build 9189887003: 0.001%
Covered Lines: 16868
Relevant Lines: 17479

💛 - Coveralls

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.

Overall this is looking pretty good! I wouldn't worry to much about the petgraph's traits, this seems to make sense to me.

I don't have much to comment on Hyperbolic Random Graphs as it is not our core area of expertise, but I did add some comments about floating-point arithmetic:

  • Intsead of multiplying cosh(a)*cosh(b), I'd look for (cosh(a + b) - cos(a - b))/2 as this can might be able to boost the accuracy. Same applies for sinh. Check with https://herbie.uwplse.org/ if you want to be sure
  • I'd also be careful with comparisons involving floats

Lastly, our pure Rust documentation doesn't support LaTex as we'd need to add KaTeX with something like https://docs.rs/rustdoc-katex-demo/0.1.5/rustdoc_katex_demo/. So you can leave it as is and we'll figure it out later

rustworkx-core/src/generators/random_graph.rs Outdated Show resolved Hide resolved
src/random_graph.rs Outdated Show resolved Hide resolved
rustworkx-core/src/generators/random_graph.rs Outdated Show resolved Hide resolved
rustworkx-core/src/generators/random_graph.rs Outdated Show resolved Hide resolved
rustworkx-core/src/generators/random_graph.rs Outdated Show resolved Hide resolved
rustworkx-core/src/generators/random_graph.rs Outdated Show resolved Hide resolved
rustworkx-core/src/generators/random_graph.rs Outdated Show resolved Hide resolved
@SILIZ4
Copy link
Contributor Author

SILIZ4 commented May 20, 2024

I believe I have fixed everything that was talked about. I don't see how to rewrite this version of the hyperbolic distance in a numerical friendly way. That said, I generalized the code to allow for any valid dimension of the hyperbolic space. To do so, it was easier to change the coordinate system and as a bonus, the hyperbolic distance has a more numerical friendly expression.

@SILIZ4
Copy link
Contributor Author

SILIZ4 commented May 21, 2024

I have no idea why Coverall now fails. Do you know why that is?

@IvanIsCoding
Copy link
Collaborator

I have no idea why Coverall now fails. Do you know why that is?

I think an update broke our CI, I'll try to fix it

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 think this is good to go

@IvanIsCoding IvanIsCoding added the automerge Queue a approved PR for merging label May 22, 2024
@IvanIsCoding IvanIsCoding merged commit c039731 into Qiskit:main May 22, 2024
28 of 30 checks passed
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