pyodide: scipy.integrate.dblquad gives very wrong result even for the simplest integrations

🐛 Bug

Using the pyodide kernel, the scipy.integrate.dblquad gives very wrong results even for the simplest integrations. The integrations are correct outside of pyodide.

To Reproduce

Enter the following code into jupyterlite

import scipy
print(scipy.__version__)
print(pyodide.__version__)

unit_square_area = scipy.integrate.dblquad(lambda y,x: 1, 0, 1, lambda x: 0, lambda x: 1)
assert abs(unit_square_area[0]-1) < unit_square_area[1], 'Unit square area calculated using scipy.integrate.dblquad of {} (+- {}) is too far from 1.0'.format(unit_square_area[0], unit_square_area[0])

Expected behavior

accurate result. pass above test.

Tested Environments

  • pyodide.__version__: ‘0.25.0’ with scipy.__version__: ‘1.11.2’ and jupyterlite: ‘0.3.0’
  • pyodide.__version__: ‘0.23.0’ with scipy.__version__: ‘1.9.3’ and jupyterlite: ‘0.1.0’
  • Independent of browser. Happens in Edge (Version 124.0.2478.105 (Official build) (64-bit) and Firefox (115.11.0esr (64-bit)) and Chrome.
  • Any other relevant information:

Additional context

Related issues (unclear if related, sound similar):

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 26 (9 by maintainers)

Commits related to this issue

Most upvoted comments

I was looking for information about how scipy for pyodide is built to get a better idea about what @hoodmane means with his comment on Fortran compilers. This explains how that works right now: https://github.com/hoodmane/pyodide/blob/main/packages/scipy/info.md

I don’t think I’m ready to give up my life to dig through that and I now understand why no one else is. Fell free to close this as won’t fix.

And thank you for pyodide. Using it as part of jupyter-lite is an awesome environment that allows us to collaborate with others in the following way:

  1. we provide notebooks with templates for specific calculations
  2. we provide environment to execute calculations
  3. user provides compute power to execute them
  4. user doesn’t need any know-how
  5. no one relies on a third party

The only other environment I could imagine serving this use-case is javascript, but I much prefer doing numerics in Python.

Thanks again for the report @lorin-kazaz. The fix for this will go into Pyodide 0.26.2

Updated to the latest version of jupyter-lite with pyodide 0.26.2 and double integration works as expected! I’m so happy. Thank you guys.

I am not finished as we are still hunting for a small bug somewhere but https://github.com/scipy/scipy/pull/21201 gives identical results for both inner_const and inner_quad and the original dblquad problem above. I don’t know what I did to fix it but I guess I wrote it in a safe way. It should be ready in a few days.

EDIT: QUADPACK is now in C.

I don’t think I’m ready to give up my life to dig through that and I now understand why no one else is. Fell free to close this as won’t fix.

Ehem… is this thing on? Hi everyone, I’m one of the scipy folks translating the fortran code (scipy/scipy#18566), one lowercase character at a time. I will eventually get to QUADPACK but one thing we are desperately missing is folks to test the translations. Because after some time, you get blinded by all that SCREAMCASE FORTRAN CODE. Hence if you are familiar with any particular domain that uses these jurrasicPACK codebase we would love to get your input.

My schedule (albeit constantly disrupted by my daily work)

  • id_dist for scipy.linalg.interpolative
  • PROPACK
  • ARPACK
  • ODRPACK
  • MINPACK
  • QUADPACK
  • if I am alive up to this point, I’ll reconsider my life

PROPACK and ARPACK is way too important for us, (segfaults, decade-long open issues etc.) so I’d stick to those as the immediate next ones but if you think quadpack is more urgent, we can move it up.

I suppose we have solved the problem at hand. We do have an interest in a well working SciPy in Pyodide, though. I have looked up what all the *PACKs do. I think I am familiar enough with MINPACK and QUADPACK to help understand the results. With work and multiple little kids, my time is quite limited, but a bit of testing like we have done here should be possible. Do you need some contact info?

I don’t think I’m ready to give up my life to dig through that and I now understand why no one else is. Fell free to close this as won’t fix.

Ehem… is this thing on? Hi everyone, I’m one of the scipy folks translating the fortran code (https://github.com/scipy/scipy/issues/18566), one lowercase character at a time. I will eventually get to QUADPACK but one thing we are desperately missing is folks to test the translations. Because after some time, you get blinded by all that SCREAMCASE FORTRAN CODE. Hence if you are familiar with any particular domain that uses these jurrasicPACK codebase we would love to get your input.

My schedule (albeit constantly disrupted by my daily work)

  • id_dist for scipy.linalg.interpolative
  • PROPACK
  • ARPACK
  • ODRPACK
  • MINPACK
  • QUADPACK
  • if I am alive up to this point, I’ll reconsider my life

PROPACK and ARPACK is way too important for us, (segfaults, decade-long open issues etc.) so I’d stick to those as the immediate next ones but if you think quadpack is more urgent, we can move it up.

How valuable would it be for us if lfortran were used to compile quadpack in pyodide?

I don’t really want to do a gradual switch I’d rather just wait until it can compile everything. In particular I think it will be very hard to match the f2c abi to the lfortran one. But I’d love to have people experimenting with just one library to see how it goes.

How reasonable would it be for us to test lfortran (instead of f2c) in pyodide?

Dunno try it and find out? Last I checked there was a minor problem with -fPIC. It should be an easy fix but the code just looked already right the last time I looked into it.

https://github.com/lfortran/lfortran/issues/550

I should at least be able to hack recursion into working with the current system in the meantime.

I suppose this fix will end up in pyodide 0.26.1 as indicated by the milestone https://github.com/pyodide/pyodide/milestone/24 Then we have to check https://github.com/jupyterlite/pyodide-kernel/blob/v0.3.1/README.md for a version of jupyterlite-core that uses a version of jupyterlite-pyodide-kernel that uses a version of pyodide 0.26.1 or greater, and then we have to check when https://github.com/jupyterlite/demo/blob/main/requirements.txt uses said jupyterlite-core version.

Is that right?

These functions are hard to figure out even with fortran knowledge and a general understanding of this corner of the maths. They come (am speculating here) straight from an era when structured programming was an abstract fad from those fancy bros from comp sci departments, far removed from the needs of real work that needs doing 😃. And an “implicit save” ( == making local variables static, at a compiler’s discretion) was very much not new even back then 😃.

Feel free to ping me on these scipy needs btw. I can’t tell heads from tails in the JS world, but (some) scipy usages I may have some idea.