rustworkx
rustworkx copied to clipboard
Support for WASM (rustworkx for Python in the browser)
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
.
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.
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
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!
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/recipesThe 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