Thanks to visit codestin.com
Credit goes to github.com

Skip to content

WinPython 64 bit with PyPy #966

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

Closed
17 tasks done
stonebig opened this issue Apr 19, 2021 · 43 comments
Closed
17 tasks done

WinPython 64 bit with PyPy #966

stonebig opened this issue Apr 19, 2021 · 43 comments

Comments

@stonebig
Copy link
Contributor

stonebig commented Apr 19, 2021

To celebrate the arrival of PyPy on Windows 64 bit, Let see if we can build a WinPython with PyPy.

Interception course with cPython:

  • interesting spot is: PyPy + VSCode + Jupyterlab + Cython + HPy , on 64 bit, maybe pyside6-6.1
  • WinPython 2021-03: PyPy-7.3.5 for Python3.7+ VSCode + Jupyterlab + Cython, on 64 bit only
  • WinPython 2021-04: Matplotlib-3.5.0 + PySide-6.1 + HPy and performances fixes
  • WinPython 2021-05: PyPy for Python-3.8, beta seems coming this summer 2021
  • WinPython 2022-02 2022-03: PyPy for Python-3.9
  • WinPython 2022-05: PyPy for Python-3.10
  • WinPython 2023-02: PyPy for Python-3.11

so far:

  • WinPython 'dot' version; Yes but missing WPPM GUI (the Qt Problem)
  • SQLite_bro : Yes but slightly different behavior, 6x slower
  • VScode without Jupyter: ... works by updating VSCode settings per menu, to tell where pypy3.exe is
  • SQLite_bro-0.9.2 fixes PyPy compatibility
  • a small Speed-Center table (below)
  • Adapt Build System to automate PyPy builds like the cPython builds
  • SQLite-3.35.5 in PyPy-7.3.5rc1 (becoming level with CPython)
  • Numpy, Matplotlib, Pandas, scikit-learn
  • Pywinpty
  • a cython wheel (but compiling to cython slows things 2.5x, currently)
  • statsmodels (after statsmodels made a compatibility patch)
  • pyzmq fix (per Christoph Gohlke)
  • Jupyter compatibility (since May 25th morning ... to integrate in a release)

Roadblocks or Hacks :

  • Qt Stack: needs
    • COMPATIBLE PySide6-6.1 with PyPy,
    • COMPATIBLE Matplotlib-3.5.0 with PySide6-6.1 (end october june ?)

Other:

Speed-Center:

speed test (seconds) Cpython-3.9 Pypy-7.3.5 3.7.10 PyPy-7.3.6 3.8.10 nightly comment
SQLite_bro 13 85 35 seems linked to 'import' not being cached , but now SQLite-3.35.0 with math functions included, and PyPy-7.3.6 will cache imports (200x speed-up, but apparently no effect)
sudoku_norvig_for_comparison_of_complexity.py 0.09 0.51
sudoku_norvig_for_comparison_of_complexity.py (hard1) 89 42 65 python-3.10a7 = 89s, numba can't, cython = 47s
speed_basic.py (code below or there) 25.5 0.27
pyconumpy the microbench to prove or not that Pypy is a scientific option (should become good with HPy)

the Nbody experiment became good in PyPy with type freezing
at CGO ’20, February 22–26, 2020, San Diego, CA, USA

Climate Impact
image

@stonebig
Copy link
Contributor Author

stonebig commented Apr 19, 2021

build a0 (2021-04-19 'PyPy')

WinPython-3.7.10.0a0 with PyPy-3.7 v7.4.3

What shall work:

  • IDLE,
  • IDLEX,
  • WinPython Command Prompt,
  • WinPython Interpreter.exe,
  • WinPython Powershell Prompt
  • the scripts:
    • make_winpython_movable (by necessity of WinPython)
    • make_winpython_fix.bat
  • and so, it seems ... movable like any WinPython.

Areas of particular interest for testers::

  • well well, certainly lot of bugs and speed to discover,
  • help PyPy and WinPython project to iron them out
  • the fact that the demo page of SQLite_bro is not working exactly like for cpython is a first issue to dig

Next build a1:

  • SQLite3.35
  • patch SQLite_bro (L763) to avoid multi-empty tab / keep same effect (not sure it's a 'bug' of PyPy per say)
MD5 SHA-1 SHA-256 Binary Size
9bd25e501d70ceac13e3d14f7ff01673 947b16ccffb2299fe48b1b12ea70b03309015ad0 291cfc0837107be82a09a08444450ce63b4bb892603e1581bc3467d2dd73344a Winpython64-3.7.10.0dotpypya0.exe 25 063 625 Bytes

Included Package:

  • WinPython
  • sqlite_bro
  • pip-20.1.0dev

Location: https://sourceforge.net/projects/winpython/files/WinPython_3.7/3.7.10.0/alphas/

@stonebig
Copy link
Contributor Author

stonebig commented Apr 20, 2021

speed measures

  • using sqlite_bro:
pydef py_sin(s):
    "sinus function : example loading module, handling input/output as strings"
    import math as py_math
    return ("%s" %  py_math.sin(s*1));
WITH RECURSIVE
  cnt(x) AS (
     SELECT 1
     UNION ALL
     SELECT x+1 FROM cnt
      LIMIT 3000000
  )

select sum(py_sin(x))  from cnt  

to get the same number of tabs we need to replace in SQLite_bro:
https://github.com/stonebig/sqlite_bro/blob/dcbbd810d0cea2be40c5c56d02e312be350a81dd/sqlite_bro/sqlite_bro.py#L739

if cur.description is not None:
per
if cur.description is not None and len(cur.description)>0: #pypy needs the second test

  • mandelbrot (when necessary wheels in place)

@stonebig
Copy link
Contributor Author

stonebig commented Apr 20, 2021

VSCode does the sudoku with pypy3.7-v7.3.4-win64

  • echo %time% & pypy3 C:\WinP\bd37\budotpypy\wpy64-37100\notebooks\docs\Solvers_Raymond_Hettinger\python\sudoku_norvig_for_comparison_of_complexity.py
  • echo %time% & python C:\WinP\bd37\budotpypy\wpy64-37100\notebooks\docs\Solvers_Raymond_Hettinger\python\sudoku_norvig_for_comparison_of_complexity.py

image

@stonebig
Copy link
Contributor Author

stonebig commented Apr 20, 2021

speed_basic.py test

  • echo %time% & pypy3 C:\WinP\bd37\budotpypy\wpy64-37100\notebooks\speed_basic.py
  • echo %time% & python C:\WinP\bd37\budotpypy\wpy64-37100\notebooks\speed_basic.py
import time

start_time = time.time()

total = 0
for i in range(1, 10000):
    for j in range(1, 10000):
        total += i + j

print(f"The result is {total}")

end_time = time.time()
print(f"It took {end_time-start_time:.2f} seconds to compute")

@stonebig
Copy link
Contributor Author

stonebig commented Apr 20, 2021

PyPy build a1 (2021-04-20 'SQLite-0.35.5')

change from build a0:

  • SQLite-0.35.5 (math functions included)
  • sqlite-bro-0.9.2 fixes to become compatible with PyPy
  • a few clean-ups

Areas of particular interest for testers:

  • sqlite_bro-0.9.2 is much more compatible with PyPy (fullly ?)
  • well:
    • the pleasure of discovering the mythical PyPy 'JIT' Python
    • contributing bug hunting and fixing in PyPy for Windows

Next build a2:

  • modify build system, so it's no more manual work
  • wait the 64bit binary wheel problem is solved (so PyPy 7.3.5, expected in two weeks)
  • hope is PyPy 7.3.5 will include:
    • the windows 64 bit wheel naming problem fix,
    • SQLite-0.35.5 with math and json functions activated, (or may patch)
    • with a strech of luck, the 'import' performance fix. (not expected)
MD5 SHA-1 SHA-256 Binary Size
338cdc161b2bc091a9f2184621681860 81e5d38c1ccc90746ad089ce975d1cc3e834a76d 52c207f2916399a3f222b9d0b87e80f7ccf5cdcbf2a9ba40d08746b173394026 Winpython64-3.7.10.0dotpypya1.exe 25 034 421 Bytes

Included Package:

  • WinPython
  • sqlite_bro-0.9.2
  • pip-20.1.0dev

Location: https://sourceforge.net/projects/winpython/files/WinPython_3.7/3.7.10.0/alphas/

@stonebig
Copy link
Contributor Author

stonebig commented Apr 24, 2021

PyPy build a2 (2021-04-24 'automated build')

Change from build a1:

  • Infrastructure work:
    • standard automation ... and so back to the old SQLite shipped per PyPy-7.3.4
    • sha3-256 added
    • unchecked; "associate" function, or future Qt integration

Location: https://sourceforge.net/projects/winpython/files/WinPython_3.7/3.7.10.0/alphas/

Areas of particular interest for testers:

  • it works as any other WinPython, except you must type "pypy3" instead of python
  • for experts knowing what they do:
    • check the associate function, (Winpython in the windows menu)
    • look ahead on Qt integration.
MD5 SHA-1 SHA-256 Binary Size SHA3-256
a657d064fb851af79863a0deb72627b6 586ddbddf7953fb6325eb58c87acaefbb54fd93e e4b007158c382308806785ca9fcab2699e3dd166917a4f256e3ed674812ae767 Winpython64-3.7.10.0dotPyPya2.exe 24 470 818 Bytes d43b68240b527c35d2c86f65e96542d83c977bc229780ecb207ac7e74fda720b

WinPython 3.7.10.0dotPyPy

The following packages are included in WinPython-64bit v3.7.10.0dotPyPy a2.

Tools

Name Version Description

Python packages

Name Version Description
Python 3.7.10 Python programming language with standard library
cffi 1.14.5 Foreign Function Interface for Python calling C code.
greenlet 0.4.13 Lightweight in-process concurrent programming
pip 21.1 The PyPA recommended tool for installing Python packages.
readline 6.2.4.1
setuptools 56.0.0 Easily download, build, install, upgrade, and uninstall Python packages
sqlite_bro 0.9.2 a graphic SQLite Client in 1 Python file
wheel 0.36.2 A built-package format for Python
winpython 4.2.20210422 WinPython distribution tools, including WPPM

@stonebig
Copy link
Contributor Author

stonebig commented May 8, 2021

looking at Cython CI, it seems Pypy-3.7 is (8m 10 s/ 5m 18s) 35% slower than Python-3.7 on this exercise ... room for improvement

@stonebig
Copy link
Contributor Author

stonebig commented May 22, 2021

cython source wheel is compatible with PyPy, on more package, but fails to compile statsmodels extensions. so flight domain is currently constrained per:

  • jupyter_core needing pywin32
  • failing to build wheels for statsmodels, pywinpty
  • pyside6 wheel (on the road from Qt, but not there).

on PyPy3 side:

  • "import package speed-up" is only coming for 7.3.6, (to check if performance with sqlite test improves widely)
  • hpy talk or article at pycon 2021 is not yet available.
  • python-3.8 compat is slow to come

@stonebig
Copy link
Contributor Author

stonebig commented May 23, 2021

may 23rd morning status;

Flight domain is currently constrained per:

@stonebig
Copy link
Contributor Author

stonebig commented May 24, 2021

@stonebig
Copy link
Contributor Author

stonebig commented May 25, 2021

@stonebig
Copy link
Contributor Author

stonebig commented Jun 5, 2021

Flight domain is currently constrained per:

  • in "Jupyter":
    • shapely: in need for a few geograhic packages cartopy and ipyleaflet
    • orjson: missing to ipycanvas
  • "science":
  • "Deep Learning":
    • out of scope for now, need to have the rest flying.
  • "Qt": no PySide6-6.1 yet

@stonebig stonebig mentioned this issue Jun 6, 2021
6 tasks
@stonebig
Copy link
Contributor Author

stonebig commented Jun 6, 2021

milestone 1 "credibility" is now reached "WinPython 2021-03: PyPy-7.3.5 for Python3.7+ VSCode + Jupyterlab + Cython, on 64 bit only".

Next milestone 2 is about more natural "performance" vs cPython (as PyPy can perform, but you need often to tweak your code)

@DStauffman
Copy link

Hey @stonebig, what's the best place to report errors on these builds? Is it to the individual libraries? I can get matplotlib to crash the interpreter with the following script. It works with cPython but not Pypy. Changing the backend to Agg instead of the default TkAgg also works. I usually use Qt5Agg and plan to use that once Qt is integrated in.

"""Pypy crashes on plot closure."""

import unittest

#import matplotlib
#matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np

class Test_plots(unittest.TestCase):
    def setUp(self):
        self.x = np.arange(5)
        self.y = 10 * self.x
        self.figs = None

    def test_plotting1(self):
        fig = plt.figure()
        plt.plot(self.x, self.y)
        fig2 = plt.figure()
        plt.plot(self.y, self.x)
        self.figs = [fig, fig2]

    def test_plotting2(self):
        fig = plt.figure()
        plt.plot(self.x, self.y)
        fig2 = plt.figure()
        plt.plot(self.y, self.x)
        self.figs = [fig, fig2]

    def tearDown(self):
        if self.figs is not None:
            for fig in self.figs:
                plt.close(fig)

if __name__ == '__main__':
    unittest.main(exit=False)

@stonebig
Copy link
Contributor Author

You may report ithe problem on pypy with the code and crash report, asking if it's a pypy bug, a way of writing not tolerated per pypy, or an incompatibility from matplotlib or tk

@stonebig
Copy link
Contributor Author

Do it also on stackoverflow

@stonebig
Copy link
Contributor Author

hum, launched this way, it doesn't blow up with Winpython64-3.7.10.0PyPycodb4.exe

image

@stonebig
Copy link
Contributor Author

this way:
image

@stonebig
Copy link
Contributor Author

stonebig commented Jun 12, 2021

Updated Flight domain seems now currently constrained per:

@stonebig
Copy link
Contributor Author

stonebig commented Jun 19, 2021

Updated Flight domain (13% not possible packages) seems now currently constrained per:

  • in "Jupyter":
    • a pyproj binary compatibility bug ??
  • "science":
    • numba: forecast is it will remain missing till the python-3.11 (june 2022 ?)
    • pyside6 wheel on the alpha road from Qt Company, guess it will need PyPy-3.8 (sept 2021 ?)
    • solvers may need a pure python version: ecos, qldl, qpsolvers, pycosat, cvxopt , osqp, nlopt
  • "Deep Learning":
    • out of scope for now, need PyPy to have the rest flying, ep numba. (dec 2022 ?)
  • Cpython eco-system compatibility:
    • Python-3.8 compatibility to get type-ast, mypy, (alpha around september)
  • VSCode-python better compatiblity, as not super friendly with pypy3 per default

Performance (-10x to 30x) is constrained per:

  • PyPy3 team slowly removing performance problems on standard python code. Next improvement = PyPy-7.3.6 (sept 2022)
  • asking cpython library to not force systematically Cython or C-packages (like ipycanvas not forcing orjson anymore).
  • hpy Cython compatibility to get same performance

@stonebig
Copy link
Contributor Author

stonebig commented Aug 3, 2021

Update of PyPy progress, testing on PyPy3-3.8 nightly of July 29th:

  • MyPy is working, if you comment the gc.set_threshold() line (purely non-functional, used to gain 4% on cPython)
  • Black is installable, because MyPy is now installable.
  • the Sqlite test is performed in 30 seconds in PyPy3-3.8 vs 85 seconds in PyPy-7.3.6 and 13 seconds in cPython (suspecting the "import" caching improvement backported from cPython3 code)

image

... not bad

@stonebig
Copy link
Contributor Author

stonebig commented Aug 12, 2021

PyPy Nightly for Python3.8 build a0 (2021-08-12, from PyPy3-3.8 nightly of July 29th:)

Infrastructure work:

MD5 SHA-1 SHA-256 Binary Size SHA3-256
78dad874bee910c74b78fe3692d99a1d be2defd71f6da7fde270ebee3f56813b1469ee84 6fad49119e0f7753318239c7671388f450bac58d20d6cd21686ffbabda7e9cd9 Winpython64-3.8.10.0dotPyPyNighta0.exe 26 623 538 Bytes 3c5aaa75da5f3d491ee9a57112cbcdba678286b3ceb2b49c52c4de3cbf710ef6

next step:

  • correct release version (.1 vs .0)
  • integrate an msvc_runtime
  • push on the interesting new bits:
    • mypy
    • ...

@stonebig
Copy link
Contributor Author

stonebig commented Aug 28, 2021

Flight domain, as of August 28th, is currently constrained per:

... a little late to 'dreamed' roadmap speed, but momentum is growing

@stonebig
Copy link
Contributor Author

stonebig commented Aug 29, 2021

Speed-Center: (2021-12-04 version of PyPy 3.8)

speed test (seconds) Cpython-3.9 Pypy-7.3.6 3.7.12 PyPy-7.3.6 3.8.12 PyPy-7.3.8rc2 3.8.12 cPython-3.11b1 comment
SQLite_bro 13 28 28 32 12
sudoku_norvig_for_comparison_of_complexity.py 0.09 0.46 0.56 cpython-3.11.0a2 slow to start ??
sudoku_norvig_for_comparison_of_complexity.py (hard1) 89 42 50 45 89 numba can't, cython = 47s
speed_basic.py (code below or there) 25.5 0.27 0.27 24.2
pyconumpy the microbench to prove or not that Pypy is a scientific option (should become good with HPy)

the Nbody experiment became good in PyPy with type freezing
at CGO ’20, February 22–26, 2020, San Diego, CA, USA

speed_bacic.py

import time

start_time = time.time()

total = 0
for i in range(1, 10000):
for j in range(1, 10000):
total += i + j

print(f"The result is {total}")

end_time = time.time()
print(f"It took {end_time-start_time:.2f} seconds to compute")

Sqlite_Bro test: performance of 'import' and SQlite interactions

measures PyPy internal weaknesses reduction like 'import' not being cached
run this in interactive sqlite_bro

pydef py_sin(s):
    "sinus function : example loading module, handling input/output as strings"
    import math as py_math
    return ("%s" %  py_math.sin(s*1));
WITH RECURSIVE
  cnt(x) AS (
     SELECT 1
     UNION ALL
     SELECT x+1 FROM cnt
      LIMIT 3000000
  )

select sum(py_sin(x))  from cnt 

@stonebig
Copy link
Contributor Author

January 22nd:

  • new in PyPy-3.8: pandas-1.3.5 with fix, gdal, osqp

@stonebig
Copy link
Contributor Author

February 27th, 2022:

  • PyPy-3.8-7.3.8 with Python-3.8 official compatibility
  • Python-3.9-7.3.8 beta, seems on track for a Q2 official release (moving from 3.7 to 3.9 in 1 year would be awesome)

@firai
Copy link
Contributor

firai commented Apr 13, 2022

Pyside6 wheels for PyPy v7.3 (Python 3.8 edition) appear to have been released:
https://www.qt.io/blog/qt-for-python-details-on-the-new-6.3-release
https://download.qt.io/official_releases/QtForPython/pypy/

@stonebig
Copy link
Contributor Author

super ! thanks for the head-up

@stonebig
Copy link
Contributor Author

stonebig commented May 2, 2022

So, as of May 2nd 2022, let say PyPy reached a Milestone:

  • PyPy3.8-7.3.9 has now its first set of PySide6-6.3 wheels, in a WinPython release Candidate
  • PyPy3.9 is likely to be declared stable in June,
  • PyPy / Qt teams have now big 'real life' Qt packages to play with and improve.

... PyPy is keeping on its interception (and synergy) course with cPython in 2023

@stonebig
Copy link
Contributor Author

stonebig commented Aug 7, 2022

On my true 4 core new PC sudoku test, PyPy-3.8 is still 2x faster then cpython-3.11, which is only 10% faster than cpython-3.10.
... so on immediate speed-up (in 1 year):

  • the "nogil" +" python" splitting in python-made-EASY in 4, would be the best simple move forward
  • PyPy may speed-up per 20% if it gets more support, while getting clother to cpython version
  • cpython may speed-up per 20%
  • hardware do promise 20% per year at this strange speed-up again years

==> so software and hardware do split the coming improvements,
but the multi-core part of hardware is still waiting cpython/PyPy to naturally/effortlessly use it and boost by 8x for the average user.

@stonebig
Copy link
Contributor Author

stonebig commented Nov 6, 2022

humm, as of now:

  • PyPy-3.9 stable is 6 month later than hoped,
  • the benefit of PyPy team exploring ahead on jit things / having jit expertise for Python, remains,
  • the need for Hpy momentum seems necessary to get a notable (3x) benefit over cPython in typical WinPython use-cases.

So:

  • on the two benchmark that were looked at:
    • Sqlite-bro :
      • PyPy is twice slower, Hpy is necessary to get PyPy on same level as cPython,
      • SQlite integrating the math functions removes the real-life problem,
    • Sudoku:
      • PyPy is twice faster, cpython-3.11 didn't improve on speed on this,
      • cpython-3.12 may bring benefit by focussing on other optimisations, so is to follow,
      • these 2x gains are insignificant if a nice & simple thread parallelism can be implemented following Nogil or Gil-per-Thread
  • on the real life WinPython-Checker experience, PyPy feels overall slower,
  • effort may shift on pyodide / cpython-3.12 as more short term benefit.

@stonebig
Copy link
Contributor Author

PyPy for Python-3.10 is out on june 2023, 6 month after 3.9, so back to a better 9 month cycle vs 12 for cpython.
... it's now only 18 month behind cpython.

Hpy seems to be integrate after Numpy-2.0, so 2.1
... we should have a competitive PyPy around end 2024

@stonebig
Copy link
Contributor Author

humm, co-petition is catching-up:

  • cpython-3.13: copy-and-patch JIT, with multi-interpreters and free-threads,
  • mojo.

the JIT expertise of PyPy may now help to challenge/improve/avoid mistakes in cpython JIT.

@stonebig
Copy link
Contributor Author

cpython-3.13.0a4 is out:

  • it seems to give a boost of 10% versus 3.11 on pure python things, not bad,
  • it's before JIT is activated, where the added benefit is currently only 1%, hope it will go to 10%, so total boost like 3.11.

@stonebig
Copy link
Contributor Author

PyPy main idea of JIT Speed-up will be integrated via the Copy-and-patch JIT in classic cPython-3.13

@stonebig
Copy link
Contributor Author

stonebig commented Mar 13, 2024

hummm, no perceptible speed progress with python-3.13.0a5.amd64 yet: time is 35" for sudoku_norvig_for_comparison_of_complexity.py

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

No branches or pull requests

3 participants