Skip to content

Fix dynamic library loading in cli runner#4871

Merged
hoodmane merged 4 commits intopyodide:mainfrom
hoodmane:scipy-cli-runner
Jun 19, 2024
Merged

Fix dynamic library loading in cli runner#4871
hoodmane merged 4 commits intopyodide:mainfrom
hoodmane:scipy-cli-runner

Conversation

@hoodmane
Copy link
Member

@hoodmane hoodmane commented Jun 18, 2024

All dependent libs should be loaded as globals. We should try to use this to simplify some of the logic in dynload.ts. Most likely what needs to happen is we need to inspect the wheel at build time to determine which libraries are "leaves" that are not dependencies of anything else and add this list to the package metadata.

Resolves #3865.

  • Update changelog
  • Add a test

@hoodmane hoodmane changed the title NFC minor code cleanup in dynload.ts Fix dynamic library loading in cli runner Jun 18, 2024
All dependent libs should be loaded as globals. We should try  to use this to
simplify some of the logic in dynload.ts. Most likely what needs to happen is we
need to inspect the wheel at build time to determine which libraries are
"leaves" that are not dependencies of anything else and add this list to the
package metadata.
@ryanking13
Copy link
Member

Thanks @hoodmane. I am okay with this approach as a temporary fix, but I'll try to investigate why the upstream fix (#3865 (comment)) is not working for us...

@hoodmane hoodmane added this to the 0.26.2 milestone Jun 19, 2024
@hoodmane hoodmane merged commit c319cc7 into pyodide:main Jun 19, 2024
@hoodmane hoodmane deleted the scipy-cli-runner branch June 19, 2024 00:10
@agriyakhetarpal
Copy link
Member

agriyakhetarpal commented Jun 21, 2024

Thanks, @hoodmane! I tried this with statsmodels to see if this resolves the issue there – it did not, sadly: https://github.com/agriyakhetarpal/statsmodels/actions/runs/9615408856/job/26522486623#step:3:6991. The missing symbol is pow_dd (though I earlier faced an error for pow_di). It's great that this works for s_cmp, though...

@hoodmane
Copy link
Member Author

hoodmane commented Jun 21, 2024

Perhaps there are several bugs =( could you give a minimal reproduction of the stats models problem? A single .py file I can run that will crash in a new issue would be great. I'll look into it next.

@agriyakhetarpal
Copy link
Member

Yes, I shall open a new issue for this – I'll have to investigate how to provide a minimal enough reproducer, please hold on :)

@hoodmane
Copy link
Member Author

It doesn't have to be that small, if you can give me a single file that does it that would be good enough for me.

@hoodmane
Copy link
Member Author

Also @agriyakhetarpal can you check it against #4876? Since that changes this same code again.

@ryanking13
Copy link
Member

ryanking13 commented Jun 22, 2024

pow_dd symbol comes from openblas.so and probably it is not loaded for some reason. @agriyakhetarpal Could you share us wheels that are used when testing statsmodels (including scipy, numpy)? Probably some of them are not linked correctly.

hoodmane added a commit to hoodmane/pyodide that referenced this pull request Jul 24, 2024
All dependent libs should be loaded as globals. We should try  to use this to
simplify some of the logic in dynload.ts. Most likely what needs to happen is we
need to inspect the wheel at build time to determine which libraries are
"leaves" that are not dependencies of anything else and add this list to the
package metadata.

This should be removed eventually, because it is a bug somewhere else in the
dynamic loader that dependents need to be global.
@agriyakhetarpal
Copy link
Member

Sorry for the late response over here, @ryanking13 and @hoodmane, but I did spend some time on this a while ago – and the problem has now subsided with either #5011 or #5031 having been merged. I have no issues when running the statsmodels tests using the Pyodide xbuildenv. Once we have 0.27 stable out and cibuildwheel updates to it internally, we can look at testing WASM wheels for statsmodels without the Node.js runner/script. The pow_dd unresolved symbol came from SciPy 1.12.0 (from a scipy.special shared object that I can't recall the name of while typing this comment), which was breaking the import statsmodels statement itself. I'll update the recipe for statsmodels to include a patch based on statsmodels/statsmodels#9270, since it also fixes a few import errors a bit deeper into some modules, besides fixing the tests. I will take a glance at scikit-image, next. :)

Side note: we should really have an option to use any Pyodide version (>0.22, perhaps) in cibuildwheel using an environment variable or Pyodide-specific configuration for it in pyproject.toml in [tool.cibuildwheel.pyodide].

@agriyakhetarpal
Copy link
Member

And scikit-image works, too! PR linked above. In this one, unlike for statsmodels, I haven't checked which shared object in SciPy was the cause of the trouble, but I can do so if someone wants me to.

lagru added a commit to scikit-image/scikit-image that referenced this pull request Sep 15, 2024
…sting (#7525)

This PR follows up on changes made in gh-7350. Here's a small, point-wise summary noting the changes here:

- It updates the Emscripten/Pyodide CI job added in gh-7350 and removes the workaround JavaScript-based test suite file, since we fixed the `s_cmp` OpenBLAS unresolved symbol coming from SciPy upstream, having updated SciPy in-tree in Pyodide (see pyodide/pyodide#4719, pyodide/pyodide#5012, pyodide/pyodide#5031, and more). This should make the testing slightly cleaner than before, and the test suite now runs till the end without any Pyodide fatal errors being reported.
The [Pyodide xbuildenv](https://github.com/pyodide/pyodide/releases/tag/0.27.0a2) can now be used to set up a virtual environment in which the tests can be run in the same way they were before.
The [`pyodide-build` tool](https://github.com/pyodide/pyodide-build) has been unvendored from the Pyodide repository and now infers the Pyodide version from the releases, downloading the relevant files from the GitHub release. Hence, the `PYODIDE_VERSION` environment variable is no longer required.
- There were some tests that have been failing on 32-bit platforms, which were last discussed quite a while ago: #3091. They surprisingly passed in a WASM 32-bit environment here without issues, which is great. I have updated the skipping conditions to accommodate this.
- There's a known problem with the pytest bytecode generation when running the tests with the xbuildenv interpreter – I disabled the pytest internal cache plugin to fix that, but ignoring the warning (pypa/cibuildwheel#1966 (comment)) works equally as well. Please let me know if there is a preference. :)

Additional context

- Pyodide CI support was first discussed in gh-7265.
- At the time of writing, Pyodide 0.27alpha2 is used in the CI job; once 0.27 stable comes out (should be soon) and `cibuildwheel` updates to it, that (plus this PR) will help unblock another PR that I had opened a while back: gh-7440. I can rebase that PR when ready.
- pyodide/pyodide#4871 (comment)

---

Co-authored-by: Lars Grüter <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue when running some scipy.sparse.linalg code inside Pyodide venv

3 participants