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

HyperSpy on pyodide (and jupyterlite) #3255

Merged
merged 11 commits into from Nov 8, 2023

Conversation

ericpre
Copy link
Member

@ericpre ericpre commented Nov 4, 2023

Required changes to get HyperSpy to work on pyodide: https://ericpre.github.io/jupyterlite-hyperspy
@CSSFrancis 😃

Progress of the PR

  • Make numba and numexpr optional,
  • Fallback to synchronous dask scheduler (dask.get) on pyodide, because dask.threaded doesn't exist - pyodide currently doesn't support threading,
  • Replace dill by cloudpickle - dill doesn't work on pyodide,
  • [n/a] update docstring (if appropriate),
  • [n/a] update user guide (if appropriate),
  • add an changelog entry in the upcoming_changes folder (see upcoming_changes/README.rst),
  • Check formatting changelog entry in the readthedocs doc build of this PR (link in github checks)
  • add tests,
  • ready for review.

Copy link

codecov bot commented Nov 4, 2023

Codecov Report

Attention: 21 lines in your changes are missing coverage. Please review.

Comparison is base (b685684) 80.78% compared to head (ad43ad2) 80.82%.

Additional details and impacted files
@@                  Coverage Diff                   @@
##           RELEASE_next_major    #3255      +/-   ##
======================================================
+ Coverage               80.78%   80.82%   +0.04%     
======================================================
  Files                     140      140              
  Lines                   20360    20395      +35     
  Branches                 4820     4825       +5     
======================================================
+ Hits                    16447    16485      +38     
+ Misses                   2840     2834       -6     
- Partials                 1073     1076       +3     
Files Coverage Δ
hyperspy/_components/bleasdale.py 100.00% <100.00%> (ø)
hyperspy/_components/exponential.py 82.35% <100.00%> (ø)
hyperspy/_components/expression.py 98.42% <100.00%> (+0.07%) ⬆️
hyperspy/_components/gaussian.py 97.33% <100.00%> (ø)
hyperspy/_components/gaussian2d.py 100.00% <ø> (ø)
hyperspy/_components/gaussianhf.py 96.22% <100.00%> (ø)
hyperspy/_components/logistic.py 100.00% <100.00%> (ø)
hyperspy/_components/lorentzian.py 97.29% <100.00%> (ø)
hyperspy/_components/polynomial.py 77.77% <100.00%> (ø)
hyperspy/_components/power_law.py 94.44% <ø> (ø)
... and 12 more

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ericpre ericpre force-pushed the pyodide branch 2 times, most recently from 3e554fb to 1cc70f9 Compare November 4, 2023 20:46
@ericpre ericpre added the run-packaging Run workflow to test packaging label Nov 5, 2023
@ericpre ericpre added run-packaging Run workflow to test packaging and removed run-packaging Run workflow to test packaging labels Nov 5, 2023
@CSSFrancis
Copy link
Member

@ericpre Super cool! Let me know if you want me to test anything or review.

@ericpre
Copy link
Member Author

ericpre commented Nov 5, 2023

@CSSFrancis, if you can have a look, that would be great! Now that numba is optional, we can also test python 3.12 without to wait for numba supporting it and I will follow up with a PR to add python 3.12!

@ericpre ericpre mentioned this pull request Nov 5, 2023
6 tasks
Copy link
Member

@francisco-dlp francisco-dlp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM other than the comments above.

hyperspy/_signals/lazy.py Show resolved Hide resolved
hyperspy/component.py Show resolved Hide resolved
hyperspy/decorators.py Show resolved Hide resolved
hyperspy/misc/export_dictionary.py Show resolved Hide resolved
hyperspy/_components/expression.py Show resolved Hide resolved
@CSSFrancis CSSFrancis mentioned this pull request Nov 7, 2023
57 tasks
@ericpre
Copy link
Member Author

ericpre commented Nov 7, 2023

I have tried to use the following code to generate a file with a saved custom component to dumps the class and I can't even saved the file:

import hyperspy.api as hs
from hyperspy.component import Component

class CustomComponent(Component):

    def __init__(self, p1=1, p2=2):
        Component.__init__(self, ('p1', 'p2'))

        self.p1.value = p1
        self.p2.value = p2

        self.p1.grad = self.grad_p1
        self.p2.grad = self.grad_p2

    def function(self, x):
        p1 = self.p1.value
        p2 = self.p2.value
        return p1 + x * p2

    def grad_p1(self, x):
        return 0

    def grad_p2(self, x):
        return x


s = hs.signals.Signal1D(range(10))
m = s.create_model()

c = CustomComponent()
m.append(c)
m.store('a')

import hyperspy
version = hyperspy.__version__
s.save(f"hs{version}_custom_component.hspy")

It seems that saving custom component is broken., but surprisingly, the code is covered according to codecov...

@francisco-dlp
Copy link
Member

@ericpre, would you like to fill a bug report for the pickling issue that you report above. I wonder if traits is to blame.

@francisco-dlp francisco-dlp merged commit 3aa9f7b into hyperspy:RELEASE_next_major Nov 8, 2023
13 of 21 checks passed
@ericpre ericpre deleted the pyodide branch November 8, 2023 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
run-packaging Run workflow to test packaging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants