Skip to content

Migrate from numba to Cython#133

Open
Cadair wants to merge 6 commits into
sunpy:mainfrom
Cadair:cython
Open

Migrate from numba to Cython#133
Cadair wants to merge 6 commits into
sunpy:mainfrom
Cadair:cython

Conversation

@Cadair

@Cadair Cadair commented Jun 11, 2026

Copy link
Copy Markdown
Member

fixes #39

I'd like someone to verify the performance delta here, from the speed the test suite runs this seems to be a good chunk faster than numba.

@Cadair Cadair force-pushed the cython branch 2 times, most recently from 5adc401 to 9f7849d Compare June 11, 2026 15:17
@Cadair Cadair requested a review from STBadman June 11, 2026 15:18
@Cadair Cadair added the Run publish Run publish CI on this PR. label Jun 11, 2026
@STBadman

Copy link
Copy Markdown
Contributor

For a standard non-trivial PFSS extrapolation using the sample_data gong map i get a 50-100% increase in runtime with this cython implementation vs the current numba release unfortunately. I will try to reproduce the test speed up you saw and see if we can understand the difference.

Timing test log for this PR with Cython :

(.sunkit-magex-cython) (base) sbadman@si393685:~/1_RESEARCH/GIT_REPOS/sunkit-magex$ ipython
Python 3.13.14 (main, Jun 11 2026, 12:30:58) [GCC 11.4.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 9.14.1 -- An enhanced Interactive Python. Type '?' for help.
Tip: IPython supports combining unicode identifiers, eg F\vec<tab> will become F⃗, useful for physics equations. Play with \dot \ddot and others.

In [1]: import sunkit_magex; print(sunkit_magex.__version__)
   ...: 
   ...: import sunpy.map
   ...: from sunkit_magex import pfss
   ...: 
   ...: gong_fname = pfss.sample_data.get_gong_map()
   ...: gong_map = sunpy.map.Map(gong_fname)
   ...: 
   ...: nrho = 35
   ...: rss = 2.5
   ...: pfss_in = pfss.Input(gong_map, nrho, rss)
1.1.1.dev31+g9ff89ff6b

In [2]: %%timeit
   ...: pfss_out = pfss.pfss(pfss_in)
   ...: 
   ...: 
1.61 s ± 679 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

And with sunkit_magex 1.1.0 with current Numba implementation

(py312) sbadman@si393685:~$ ipython
Python 3.12.3 | packaged by conda-forge | (main, Apr 15 2024, 18:38:13) [GCC 12.3.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.25.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import sunkit_magex; print(sunkit_magex.__version__)
   ...: 
   ...: import sunpy.map
   ...: from sunkit_magex import pfss
   ...: 
   ...: gong_fname = pfss.sample_data.get_gong_map()
   ...: gong_map = sunpy.map.Map(gong_fname)
   ...: 
   ...: nrho = 35
   ...: rss = 2.5
   ...: pfss_in = pfss.Input(gong_map, nrho, rss)
1.1.0

In [2]: %%timeit
   ...: pfss_out = pfss.pfss(pfss_in)
   ...: 
   ...: 
879 ms ± 87 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

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

Labels

Run publish Run publish CI on this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Investigate compiling code rather than recommending numba for performance

2 participants