Skip to content

Conversation

IvanIsCoding
Copy link
Collaborator

This is an unusual update, after many years rand got a major update. In the past, mostly rand_pcg got minor updates and to be honest we never really bumped it.

One of the main changes is moving rand::distributions to rand_distr and making some distributions return Result<Dist, E> for invalid arguments. So we need to catch some errors, despite the fact that with our current code they never happen.

Also, maybe this PR makes rand easier to work with WASM/Emscripten for #703. rand not compiling in WASM is what prompted me to check there was a rand update in the first place.

@IvanIsCoding IvanIsCoding requested a review from mtreinish May 9, 2025 02:50
@IvanIsCoding
Copy link
Collaborator Author

Just confirming that this update does, in fact, unblock rustworkx-core from compiling to WASM with emscripten:

➜  rustworkx-core git:(wasm-rand) cargo build --target wasm32-unknown-emscripten
   Compiling getrandom v0.3.2
   Compiling libm v0.2.15
   Compiling num-traits v0.2.19
   Compiling rand_core v0.9.3
   Compiling rand_chacha v0.9.0
   Compiling rand_pcg v0.9.0
   Compiling rand v0.9.1
   Compiling num-integer v0.1.46
   Compiling num-complex v0.4.6
   Compiling rand_distr v0.5.1
   Compiling ndarray v0.16.1
   Compiling rustworkx-core v0.17.0 (/home/ivan/Projects/rustworkx-dev/rustworkx-core)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 6.12s

For wasm32-unknown-unknown there is another thing we need to change (enabling the js feature of getrandom). But this is much better than we were with rand 0.8!

@IvanIsCoding IvanIsCoding added the dependencies Pull requests that update a dependency file label May 9, 2025
@coveralls
Copy link

coveralls commented May 9, 2025

Pull Request Test Coverage Report for Build 14929102910

Details

  • 24 of 28 (85.71%) changed or added relevant lines in 5 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 95.236%

Changes Missing Coverage Covered Lines Changed/Added Lines %
rustworkx-core/src/token_swapper.rs 5 6 83.33%
rustworkx-core/src/generators/random_graph.rs 11 14 78.57%
Totals Coverage Status
Change from base Build 14916993103: 0.0%
Covered Lines: 18733
Relevant Lines: 19670

💛 - Coveralls

@IvanIsCoding
Copy link
Collaborator Author

Just confirming that

cargo +nightly check --target wasm32-unknown-emscripten 

At least passes now. Of course there will be other quirks of Pyodide and emscripten to figure out, but at least we can compile and test something

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.

Overall this LGTM. I just have some minor issue with the error handling around the random distribution creation from fixed values. It shouldn't ever come up in practice, but I think the potential errors being returned are misleading in the unlikely chance there was a bug in rand_distr that caused Uniform(0., 1.) to return an Err.

@IvanIsCoding IvanIsCoding requested a review from mtreinish May 9, 2025 12:36
@IvanIsCoding
Copy link
Collaborator Author

Ok, I changed rustworkx-core to panic and rustworkx to returna runtime error. I think it should be good to go.

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.

LGTM, thanks for updating the errors

@mtreinish mtreinish added this pull request to the merge queue May 10, 2025
Merged via the queue into Qiskit:main with commit 5a0f6b7 May 10, 2025
31 checks passed
@IvanIsCoding IvanIsCoding deleted the update-rand branch May 17, 2025 18:00
SILIZ4 pushed a commit to SILIZ4/rustworkx that referenced this pull request Jul 4, 2025
* Update rand crates in rustworkx-core

* Update rand crates in rustworkx for Python

* Incorporate PR feedback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants