Skip to content

Support for WASM (rustworkx for Python in the browser)  #703

Open
@IvanIsCoding

Description

@IvanIsCoding
Collaborator

What is the expected enhancement?

CPython 3.11 will add support for WASM. It would be nice for us to be able to run in WASM, as it would allow us to run in the browser along other Python libraries.

To accomplish that, we would need to build our library for the wasm32-unknown-emscripten Rust target. Setting up Emscripten is the biggest challenge for this, but should be doable with cross.

Activity

added this to the 0.13.0 milestone on Oct 18, 2022
IvanIsCoding

IvanIsCoding commented on Oct 18, 2022

@IvanIsCoding
CollaboratorAuthor

Also, if we compile to WASM we could use JupyterLite to build an interactive on-line tutorial that runs entirely on the browser and doesn't depend on Binder or external tools.

IvanIsCoding

IvanIsCoding commented on Oct 25, 2022

@IvanIsCoding
CollaboratorAuthor

First challenge to take note: rand_pcg::Pcg64 is not available in WASM, we will probably have to fallback to Pcg32 in WASM

error[E0432]: unresolved import `rand_pcg::Pcg64`
  --> src/layout/random.rs:16:5
   |
16 | use rand_pcg::Pcg64;
   |     ^^^^^^^^^^-----
   |     |         |
   |     |         help: a similar name exists in the module: `pcg64`
   |     no `Pcg64` in the root

error[E0432]: unresolved import `rand_pcg::Pcg64`
  --> src/layout/spring.rs:30:5
   |
30 | use rand_pcg::Pcg64;
   |     ^^^^^^^^^^-----
   |     |         |
   |     |         help: a similar name exists in the module: `pcg64`
   |     no `Pcg64` in the root

error[E0432]: unresolved import `rand_pcg::Pcg64`
  --> src/random_graph.rs:28:5
   |
28 | use rand_pcg::Pcg64;
   |     ^^^^^^^^^^-----
   |     |         |
   |     |         help: a similar name exists in the module: `pcg64`
   |     no `Pcg64` in the root

removed this from the 0.13.0 milestone on May 10, 2023
jtpio

jtpio commented on Dec 10, 2023

@jtpio

Also, if we compile to WASM we could use JupyterLite to build an interactive on-line tutorial that runs entirely on the browser and doesn't depend on Binder or external tools.

That would be great!

One way to do this would be to try to get rustworkx on Emscripten Forge (like conda-forge but for emscripten) by adding a new recipe to the repo: https://github.com/emscripten-forge/recipes

The package would then be available for use with the Xeus Python kernel for JupyterLite: https://github.com/jupyterlite/xeus-python-kernel/

Otherwise for Pyodide support that would mean opening a new PR on the repo to add the package: https://github.com/pyodide/pyodide. And waiting for a new Pyodide release.

Either way it would indeed be nice to be able to try the library directly in the browser!

IvanIsCoding

IvanIsCoding commented on Dec 10, 2023

@IvanIsCoding
CollaboratorAuthor

Also, if we compile to WASM we could use JupyterLite to build an interactive on-line tutorial that runs entirely on the browser and doesn't depend on Binder or external tools.

That would be great!

One way to do this would be to try to get rustworkx on Emscripten Forge (like conda-forge but for emscripten) by adding a new recipe to the repo: https://github.com/emscripten-forge/recipes

The package would then be available for use with the Xeus Python kernel for JupyterLite: https://github.com/jupyterlite/xeus-python-kernel/

Otherwise for Pyodide support that would mean opening a new PR on the repo to add the package: https://github.com/pyodide/pyodide. And waiting for a new Pyodide release.

Either way it would indeed be nice to be able to try the library directly in the browser!

That is very interesting! I wans't aware of that. I remember someone created a conda-forge recipe for us: https://github.com/conda-forge/rustworkx-feedstock. So we could look into creating an emscript-forge recipe as well.

One of the biggest challenges though is that wasm32-unknown-emscripten is the first architecture that our code hasn't compiled to. So we will need to make sure rustworkx-core and rustworkx work with it first

sorin-bolos

sorin-bolos commented on Apr 29, 2025

@sorin-bolos

I'm interested in having this feature and I'm available to put in the work

IvanIsCoding

IvanIsCoding commented on Apr 30, 2025

@IvanIsCoding
CollaboratorAuthor

I'm interested in having this feature and I'm available to put in the work

I was taking a look at https://github.com/sorin-bolos/rustworkx/pull/1/files, I think for rand_pcg using features to detect the platform is fine.

But for rayon, really it should have a fallthrough. There's a discussion in rayon-rs/rayon#1155. If we need to patch each use of rayon in rustworkx and rustworkx-core the PR will become unmergeable. We need to make it default to single threaded by default somehow.

IvanIsCoding

IvanIsCoding commented on Apr 30, 2025

@IvanIsCoding
CollaboratorAuthor
IvanIsCoding

IvanIsCoding commented on May 9, 2025

@IvanIsCoding
CollaboratorAuthor

Two things:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requesthelp wantedExtra attention is needed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @jtpio@mtreinish@IvanIsCoding@sorin-bolos

    Issue actions

      Support for WASM (rustworkx for Python in the browser) · Issue #703 · Qiskit/rustworkx