Speed of VPython 7 vs. GlowScript VPython

813 views
Skip to first unread message

Bruce Sherwood

unread,
Oct 8, 2017, 7:16:16 AM10/8/17
to VPython-users
In the GlowScript forum a user asked whether there are any tricks for speeding up programs that involve calculations of the motions of a large number of particles, such as in this gas program:


In thinking about the question, I made a copy of this program and timed the animation of 1000 spheres, with rate(150000), and found that each loop cost about 135 ms in GlowScript VPython.

Next I ran the same program using true Python (VPython 7) and found that each loop cost about 500 ms. This is presumably due to the fact that JavaScript (to which GlowScript VPython compiles) is inherently faster than Python (Python is interpreted, JavaScript is compiiled).

Then I did the same with the gas program from the suite of programs distributed with Classic VPython, which used numpy for speed.  Running in Classic VPython, a loop costs about 1000 ms. Running in VPython 7 a loop costs about 800 ms. I'm deeply puzzled why the numpy version is slower in VPython 7 (800 ms)  than the non-numpy version (500 ms); this doesn't make sense. But whatever mistake I've made, it's clear that for multiparticle VPython programs GlowScript VPython is significantly faster than VPython that uses installed Python.

Of course speed isn't everything. GlowScript VPython doesn't have access to the big world of Python modules. But at least as far as raw speed is concerned, the lack of numpy in the GlowScript environment isn't an issue.


Matt Craig

unread,
Oct 9, 2017, 12:46:05 PM10/9/17
to VPython-users
Hi Bruce,

Do you have a link to the numpy version you wrote? 

Matt

Bruce Sherwood

unread,
Oct 9, 2017, 1:40:07 PM10/9/17
to VPython-users
I attach 4 versions of the gas program, in the form I used for timing purposes. 

I found various mistakes in my measurements, both stupid and subtle. Here are my final results for this multiparticle gas model:

ClassicGasNoNumpy.py:       2.3 milliseconds per loop
ClassicGasNumpy.py:            0.6 ms
Gas.py (VPython 7):               5.5 ms
GasNumpy.py: (VPython 7):   1.3 ms
Gas.py (GlowScript):              0.12 ms (this uses the code from Gas.py; just change the start of the program for GlowScript use)

Summary for this particular (but representative) example program:

1) Use of the numpy module with true Python increases the speed by a factor of 4.

2) Classic is 2 times faster than VPython 7. This is presumably due to the fact that the Classic visual module is mostly written in (fast) C++, whereas most of VPython 7 (except for the vector class) is written in (slow) Python. The vector class was speeded up by using Cython, and the other major component of the vpython module is a candidate for similar treatment, which would likely bring it close to the speed of Classic VPython. I might have thought that the fact that Classic VPython has to do all of the rendering in the CPU, using OpenGL, might have been compensated for in VPython 7 by offloading the rendering to WebGL, but that's not the case.

3) GlowScript VPython is 5 times faster than ClassicGasNumpy and 20 times faster than ClassicGasNoNumpy.

4) GlowScript VPython is 10 times faster than VPython 7 without numpy and 40 times faster than VPython 7 without numpy.


ClassicGasNoNumpy.py
ClassicGasNumpy.py
GasNumpy.py
Gas.py

Bruce Sherwood

unread,
Oct 9, 2017, 3:19:54 PM10/9/17
to VPython-users
Correction:. The last sentence should of course read "4) GlowScript VPython is 10 times faster than VPython 7 with numpy and 40 times faster than VPython 7 without numpy."

--
You received this message because you are subscribed to the Google Groups "VPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Bruce Sherwood

unread,
Oct 9, 2017, 9:49:34 PM10/9/17
to VPython-users
I'll add that the time for VPython 7 is the same whether running from IDLE or in a Jupyter notebook.

Bruce

John

unread,
Oct 12, 2017, 8:51:40 AM10/12/17
to VPython-users
I tried profiling the Gas.py code in a Jupyter Notebook to see what the bottlenecks in the code execution were. The results of the profile indicated that the Gas.py simulation was spending 70 percent of the time in the checkCollisions routine. The checkCollisions routine has an embedded for loop and it is slow in pure python.

    for i in range(Natoms):
        ai = apos[i]
        for j in range(i+1, Natoms) :
            aj = apos[j]
            dr = ai - aj
            if mag2(dr) < r2: hitlist.append([i,j])

This code was speeded up by Bruce using Numpy which gave a 12X improvement in the execution speed of checkCollisions according the the profiler results. I also checked to see if this embedded for loop could be speeded up using Numba or Cython. I found that the Numba speedup was also around 12X for the checkCollisions routine and the Cython speedup was around 28X for checkCollisions routine. I put the test notebooks on binder so that you can try it out for yourself.


The four notebooks are Gas.ipynb , GasNumpy2.ipynb, GasNumba.ipynb and GasCython.ipynb and I added the cell magic %%prun at the beginning of the cell to profile the code in the cell.

%%prun
from vpython import *

I get the following results for the Cummulative time for checkCollisions routine which is where the biggest bottleneck is.

Gas.ipynb                     checkCollisions  runtime   = 6 ms
GasNumpy2.ipynb        checkCollisions  runtime   = 0.498 ms
GasNuma.ipynb            checkCollisions  runtime   = 0.544
GasCython.ipynb          checkCollisions  runtime   = 0.212

John

Bruce Sherwood

unread,
Oct 12, 2017, 11:01:09 AM10/12/17
to VPython-users
That's very interesting, John. Thanks for the data.

Bruce

Bruce Sherwood

unread,
Oct 12, 2017, 11:19:54 AM10/12/17
to VPython-users
John, do you have numbers for the overall speeds, not just for the checkCollisions portion of the code?

What intrigues me is that GlowScript VPython (which is actually JavaScript) is 20 times faster than the same code in classic Python (using Chrome), if one doesn't apply Numpy or Numba or Cython, all of which are quite effortful for non-expert programmers. (I'm assuming that VPython 7 will eventually get cythonized to approach the speed of Classic VPython.) It's amusing that a language originally aimed just at improving a web page (JavaScript) turns out to be a serious computational language. A tremendous amount of work has gone into optimizing the JavaScript compiler.

Bruce

John

unread,
Oct 12, 2017, 1:33:41 PM10/12/17
to VPython-users
Bruce, just go to the link I provided for the notebooks on  binder and execute the notebooks to get all the timing data.


The computers on binder are quite fast and the notebooks there run faster than the python kernel running on my local machine. The profile data of the python code at the end of the gas simulation provides all the timing data you would need. The routines listed at the top of the profile output are taking the most compute time and so are the places to try to optimize first with cython or numba to improve performance. In the case of the Gas.py file the checkCollisions routine was a significant bottleneck. Also in Gas.py the vpython.cyvector.mag2  routine was being called in checkCollisions 4950000
times so it took up over 30 percent of checkCollisions execution time. So trying to improve something like cyvector.mag2 to run faster in cython would improve performance since it it gets called often. 

If you look at this blog post about cython you can see that even cython code can be improved.


I used the code from "Raw Pointers" in this article in  the GasCython.ipynb notebook which gave the best cython performance improvement. I also provided the memview_bench notebook from this article in the binder notebook link if you want to try running it also.

Your timing output in Gas.py is still in the code as well at the  other notebooks so you can still see the results at the end of the simulation in the notebook on binder.

John

Bruce Sherwood

unread,
Oct 13, 2017, 11:14:13 AM10/13/17
to VPython-users
When I look at the total times at mybinder.com instead of the times in just the costly routine I see this:

Gas 7.4 ms (I had measured 5.5 on my own computer, 2.3 in Classic, and 0.12 in GlowScript)
Cython2 2.5 ms 
Numpy2 1.1 ms
Numba 1.5 ms

Interesting that Cython2 is actually slower than either Numpy2 or Numba when I measure the whole loop contents.

For me, the interesting thing is that the "simple" code (Gas; no numpy or numba or cython) runs 20 times faster in GlowScript VPython than in Classic VPython (presumably we can speed up VPython 7 to match Classic VPython). This particular gas example is sophisticated code even in its simple form, so one could argue that someone capable of writing such code in Python is capable of invoking numpy or numba of cython, but this requires significant additional effort. 

I find even numpy quite hard to use, and I welcome an environment that runs at near-machine speed without special coding. The big limitation of course is that the GlowScript environment doesn't provide access to the big world of Python modules. Many Python modules are written in Python, which means that in principle the RapydScript-NG Python-to-JavaScript transpiler used in GlowScript VPython could be used to build JavaScript versions of such modules, which could be invoked in GlowScript VPython programs.

Bruce

John

unread,
Oct 13, 2017, 1:38:09 PM10/13/17
to VPython-users
Oops, I made an error in the GasCython files. I was doing twice as much looping in checkCollisions than was needed. I changed the code from

    for i in range(n_samples):
        for j in range(n_samples):

to 

    for i in range(n_samples):
        for j in range(i+1,n_samples):

Now the GasCython and GasCython2 code matches that of the other files for these embedded loops. WIth this change the cython code run checkCollisions routine faster and the output plots look the same for all test files.. I will note that GasCython should run faster than GasCython2. The GasCython file contains cython with raw pointers and the GasCython2 contains cython code with memviews. The checkCollisions routine in GasCython runs 4X faster than in GasCython2 so GasCython is expected to perform better than GasCython2.

I put these changes on binder so the Cython versions now run faster. and now get the following results.

https://beta.mybinder.org/v2/gh/jcoady/Gas/master

Cython     0.8 ms
Cython2   1.3 ms 

I think that python programmers are aware that python is slow and that if you want to speed up your code you need to profile it to see what the bottlenecks are and try to fix those bottlenecks with things like numpy, cython or numba.

John

Bruce Sherwood

unread,
Oct 15, 2017, 8:20:16 AM10/15/17
to VPython-users
But wouldn't a Python programmer be pleased to get high performance without having to use numpy or numba or cython? Moreover, the RapydScript-NG speed is an order of magnitude faster even than the Cython speed. I get with your updated Cython example 1.0 ms per loop, and with GlowScript VPython I get 0.12 ms per loop. Presumably one could get to GlowScript speed by rewriting the functions in C and calling them from Python, but then the program is hardly a Python program.

What I'm glimpsing is that RapydScript-NG offers the possibility of being able to consider Python to be a fast-execution language instead of a slow-execution language. Currently a huge disadvantage is not having access to the large world of Python modules, but as I pointed out, RapydScript-NG could be used to compiled pure Python modules to JavaScript. Also, there are many similarities between C/C++ and JavaScript, so perhaps conversion of C/C++ Python modules could also be automated or semi-automated. Another issue is that I do not have a sense of how complete or compliant RapydScript-NG is with respect to standard Python. It certainly has improved rapidly in the last year in this respect. Yet another issue is that for security reasons reading and writing data files is problematic in a browser-based environment; perhaps this could be addressed by using nodejs, which can run outside a browser.

I admit that my remarks are highly speculative, but surely it's worth pursuing the possibility of removing the least desirable feature of Python, its slowness.

Bruce

John

unread,
Oct 16, 2017, 12:40:19 AM10/16/17
to VPython-users
I tried using pypy on checkCollisions routine on my computer and found that I get a performance similar to Numba version of checkCollisions. The jupyter notebook has a pypy cell magic so you are able to run pypy code in a notebook cell if you have pypy installed on your machine. I did this for python 2.7 on my Windows machine. It might be worthwhile exploring pypy as an option to speed up vpython. According to this article pypy works for python 3.5.3 including asyncio functionality.


 Recall that python 3.5.3 was the minimum version that vpython required to run in no-notebook mode. But according to pypy website, pypy for python 3.5.3 only currently works on Linux. So if you have a Linux machine to try it out on, it might worth running vpython on pypy in no notebook mode to see what kind of speedup it can get. You could pip install vpython in pypy's site-packages directory  with no dependencies flag set so that it doesn't also install jupyter. Then you would also require pypy version of numpy from pypy website and also pip install autobahn and you should be able to run in no-notebook mode on a Linux machine.

I wasn't able to get vpython working in a notebook cell using pypy on my machine because installing vpython under pypy site-packages directory returned a compile error when installing the Jupyter dependencies. I was only able to test out generic python code in a pypy cell magic in a Jupyter Notebook and saw a 12X performance improvement in the tests I ran. Maybe if you install vpython in pypy 2.7 on your Windows machine you won't encounter the compile problem that I got when installing jupyter under pypy and if it installs correctly then you could test out vpython in a jupyter notebook running using pypy as the kernel instead of the ipython python 2.7 kernel.

John

John

unread,
Oct 17, 2017, 2:29:44 PM10/17/17
to VPython-users
I was able to install pypy an a linux machine and configure Jupyter Notebook to recognize it as a kernel. With this addition the PyPy kernel appeared in the list of kernels in Jupyter Notebook just like the other kernels like VPython and Python3 etc. Next I was able to open the Gas.ipynb in a Jupyter Notebook and then inside the notebook I switched kernels from VPython to PyPy and found that it ran around 10X faster. The performance of running Gas using PyPy kernel on my machine was similar or better than running GasNumpy or GasNumba using VPython kernel but without having to modify the code in Gas.ipynb,  To install PyPy as a kernel option for Jupyter Notebook follow these instructions.


Step 1: Download PyPy and install pypy on your machine


Step 2: Add the installed path to pypy on your machine to your PATH environment variable

Step 3: Add pip to PyPy from the terminal window

            pypy -m ensurepip

Step 4: pip install ipykernel to pypy

            pypy -m pip install ipykernel

Step 5:  Add pypy kernel to Jupyter Notebook

            pypy -m ipykernel install --user --name pypy --display-name "Python (PyPy)"

If these steps were successful, then you should see the PyPy kernel as one of the available kernels in the Jupyter Notebook

    jupyter notebook 

then click the "file" button in the notebook and you should see "Python (PyPy)" as a kernel that you can use. Select PyPy to create a PyPy notebook. Then in the cell of the notebook type.

import sys
sys.version

and execute the cell. It should indicate that it is using PyPy.

To run VPython under pypy requires first installing numpy from pypy using the instructions provided


Also  pip install Vpython into PyPy site-packages directory with --no-deps flag.

pypy -m pip install --no-deps vpython

Lastly, I needed to modify vpython in pypy site-packages directory to use the pure python version of vector.py and not the cython version.

Following these instructions will allow you to run VPython notebooks using the PyPy kernel in the Jupyter Notebook.

John

Bruce Sherwood

unread,
Oct 17, 2017, 3:24:51 PM10/17/17
to VPython-users
That's great, John!

Bruce

John

unread,
Oct 17, 2017, 5:14:32 PM10/17/17
to VPython-users
The only change I needed to make to VPython to get it to work with PyPy in a Jupyter Notebook was to import pure python vector. The import code of vector in vpython.py now looks like

import sys
try:
    if 'PyPy' in sys.version:
        from .vector import *
    else:
        from .cyvector import *
        v = vector(0,0,0)
except:
    from .vector import *

and similarly the import of vector in shapespath.py now looks like

import sys
try:
    if 'PyPy' in sys.version:
        from .vector import vector, mag, norm
    else:
        from .cyvector import vector, mag, norm
        v = vector(0.,0.,0.)
except:
    from .vector import vector, mag, norm

That's all the changes that I required in vpython code for VPython to work with the PyPy kernel.

John

On Tuesday, October 17, 2017 at 12:24:51 PM UTC-7, Bruce Sherwood wrote:
That's great, John!

Bruce

Bruce Sherwood

unread,
Oct 20, 2017, 8:50:58 PM10/20/17
to VPython-users
It's unfortunate that Python 3 versions of PyPy are currently available only for Linux. Sigh.

Bruce

John

unread,
Feb 24, 2018, 1:10:37 PM2/24/18
to VPython-users
It looks like the Python 3 versions of PyPy are now available for more than just Linux .


I found that it worked for Linux . If someone can check that it works for Mac OS X that would be great. The instructions to add pypy3 as a kernel for the jupyter notebook were:

Step 1: Download PyPy and install pypy3 on your machine. (PyPy 3.5.3 compatible)


Step 2: Add the installed path to pypy3 on your machine to your PATH environment variable

Step 3: Add pip to PyPy from the terminal window

            pypy3 -m ensurepip

Step 4: pip install notebook to pypy3

            pypy3 -m pip install notebook

Step 5:  Add pypy3 kernel to Jupyter Notebook

            pypy3 -m ipykernel install --user --name pypy3 --display-name "Python3 (PyPy)"

If these steps were successful, then you should see the PyPy kernel as one of the available kernels in the Jupyter Notebook

    jupyter notebook 

then click the "file" button in the notebook and you should see "Python3 (PyPy)" as a kernel that you can use. Select PyPy to create a PyPy notebook. Then in the cell of the notebook type.

import sys
sys.version

and execute the cell. It should indicate that it is using PyPy.


I tried it on my windows machine but it failed to compile ipykernel. I know it works on Linux but maybe someone can test it out for Mac OS X .

John

Steve Spicklemire

unread,
Feb 25, 2018, 7:59:09 AM2/25/18
to vpytho...@googlegroups.com, Steve Spicklemire
Hi John,

I tried it on OS X 10.12.6, and everything “worked” but when I try to launch a Pypy kernel I get the following. It appears some of the needed ipykernel machinery didn’t get installed. Have you seen this one?

[I 07:56:07.208 NotebookApp] Accepting one-time-token-authenticated connection from ::1
[I 07:56:11.370 NotebookApp] Creating new notebook in
[I 07:56:11.843 NotebookApp] Kernel started: cb60cd0b-e3ad-415f-abcd-fa2e09a783dd
[I 07:56:13.185 NotebookApp] Adapting to protocol v5.1 for kernel cb60cd0b-e3ad-415f-abcd-fa2e09a783dd
[I 07:56:24.375 NotebookApp] Starting buffering for cb60cd0b-e3ad-415f-abcd-fa2e09a783dd:78770192c6f94845bec7e7c3fd1441fc
[I 07:56:24.680 NotebookApp] Kernel shutdown: cb60cd0b-e3ad-415f-abcd-fa2e09a783dd
[I 07:56:28.672 NotebookApp] Creating new notebook in
[I 07:56:28.913 NotebookApp] Kernel started: 4e837202-a0f7-4e8c-8611-443fce979139
/Users/steve/pypy3-v5.10.0-osx64-2/bin/pypy3: No module named ipykernel_launcher
[I 07:56:31.912 NotebookApp] KernelRestarter: restarting kernel (1/5), new random ports
/Users/steve/pypy3-v5.10.0-osx64-2/bin/pypy3: No module named ipykernel_launcher
[I 07:56:34.923 NotebookApp] KernelRestarter: restarting kernel (2/5), new random ports
/Users/steve/pypy3-v5.10.0-osx64-2/bin/pypy3: No module named ipykernel_launcher
[I 07:56:37.930 NotebookApp] KernelRestarter: restarting kernel (3/5), new random ports
/Users/steve/pypy3-v5.10.0-osx64-2/bin/pypy3: No module named ipykernel_launcher
[W 07:56:38.957 NotebookApp] Timeout waiting for kernel_info reply from 4e837202-a0f7-4e8c-8611-443fce979139
[I 07:56:40.940 NotebookApp] KernelRestarter: restarting kernel (4/5), new random ports
> --
> You received this message because you are subscribed to the Google Groups "VPython-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to vpython-user...@googlegroups.com.

John

unread,
Feb 25, 2018, 11:07:10 AM2/25/18
to VPython-users
No I haven't seen that error. Check which version of ipykernel and notebook you are using under conda.

conda list

mayber try upgrading to the latest version.

conda update ipykernel
conda update notebook

I think the current version for ipykernel is 4.8.2 and for notebook it is 5.4.

Try run the notebook again after upgrading.

jupyter notebook

and then check if you can create a notebook with a pypy3 kernel.

Also try the command again to install the ipykernel.

pypy3 -m ipykernel install --help

pypy3 -m ipykernel install --user --name pypy3 --display-name "Python3 (PyPy3)"


John

John

unread,
Feb 25, 2018, 11:20:05 AM2/25/18
to VPython-users
Googling the error "No module named ipykernel_launcher", the advise seems to be to uninstall ipykernel and reinstall is again.



so make sure you have the latest version

pypy3 -m pip show ipykernel

it should be 4.8.2

also try

conda list

conda update ipykernel

John

On Sunday, February 25, 2018 at 4:59:09 AM UTC-8, Steve Spicklemire wrote:

Steve Spicklemire

unread,
Feb 25, 2018, 12:08:08 PM2/25/18
to vpytho...@googlegroups.com, Steve Spicklemire
Thanks John,


> On Feb 25, 2018, at 11:20 AM, John <john...@shaw.ca> wrote:
>
> Googling the error "No module named ipykernel_launcher", the advise seems to be to uninstall ipykernel and reinstall is again.
>
> https://github.com/udacity/aind2-dl/issues/9

Yes, I had seen this advise and tried it.

>
> https://groups.google.com/a/continuum.io/forum/#!topic/anaconda/6OkNtiJmq0A

I’m not running anaconda here, but I did find this as well and tried it already.

>
> so make sure you have the latest version
>
> pypy3 -m pip show ipykernel
>
> it should be 4.8.2

Indeed:

(vsci3) aluminum:~ steve$ pypy3 -m pip show ipykernel
Name: ipykernel
Version: 4.8.2
Summary: IPython Kernel for Jupyter
Home-page: http://ipython.org
Author: IPython Development Team
Author-email: ipyth...@scipy.org
License: BSD
Location: /Users/steve/pypy3-v5.10.0-osx64-2/site-packages
Requires: ipython, jupyter-client, tornado, traitlets
(vsci3) aluminum:~ steve$

>

> also try
>
> conda list
>
> conda update ipykernel

My viritualenv version of ipykernel (which is running jupyter notebook) is also 4.8.2

(vsci3) aluminum:~ steve$ pip show ipykernel
Name: ipykernel
Version: 4.8.2
Summary: IPython Kernel for Jupyter
Home-page: http://ipython.org
Author: IPython Development Team
Author-email: ipyth...@scipy.org
License: BSD
Location: /Users/steve/vsci3/lib/python3.6/site-packages
Requires: jupyter-client, ipython, traitlets, tornado
(vsci3) aluminum:~ steve$

So it’s pretty mysterious!

Ah, figured it out. You evidently have to run the pypy version of jupyter:

~/pypy3-v5.10.0-osx64-2/bin/jupyter notebook

Then it works:

'3.5.3 (7a22aa3bd5bf, Dec 25 2017, 17:11:18)\n[PyPy 5.10.0 with GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)]’

-steve

John

unread,
Feb 25, 2018, 2:50:04 PM2/25/18
to VPython-users
If you are using a virtual environment then there are additional flags you can set when executing "ipykernel install" command. See

pypy3 -m ipykernel install --help

I think you need to set the PREFIX flag to something like.

pypy3 -m ipykernel install --user --name pypy3 --prefix "/Users/steve/pypy3-v5.10.0-osx64-2" --display-name "Python3 (PyPy)" 

see if that works.

Also you can try running pypy3 in no_notebook mode. Install vpython under pypy3.

pypy3 -m pip install vpython

then try running a vpython no_notebook program.

pypy3  my_no_notebook_vpython_file.py

Also try running the Gas.py program that Bruce provided a link to early in this thread with pypy3 and see how the performance improves and compare it to the glowscript-vpython version.

John

Steve Spicklemire

unread,
Feb 25, 2018, 4:22:42 PM2/25/18
to vpytho...@googlegroups.com, Steve Spicklemire
FYI, see below. I’ll try the no_notebook & Gas.py experiments.

aluminum:~ steve$ pypy3 -m ipykernel install --user --name pypy3 --prefix "/Users/steve/pypy3-v5.10.0-osx64-2" --display-name "Python3 (PyPy)"
Traceback (most recent call last):
File "/Users/steve/pypy3-v5.10.0-osx64-2/lib-python/3/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/Users/steve/pypy3-v5.10.0-osx64-2/lib-python/3/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/Users/steve/pypy3-v5.10.0-osx64-2/site-packages/ipykernel/__main__.py", line 3, in <module>
app.launch_new_instance()
File "/Users/steve/pypy3-v5.10.0-osx64-2/site-packages/traitlets/config/application.py", line 658, in launch_instance
app.start()
File "/Users/steve/pypy3-v5.10.0-osx64-2/site-packages/ipykernel/kernelapp.py", line 480, in start
return self.subapp.start()
File "/Users/steve/pypy3-v5.10.0-osx64-2/site-packages/ipykernel/kernelspec.py", line 176, in start
prefix=opts.prefix, display_name=opts.display_name)
File "/Users/steve/pypy3-v5.10.0-osx64-2/site-packages/ipykernel/kernelspec.py", line 133, in install
path, kernel_name=kernel_name, user=user, prefix=prefix)
File "/Users/steve/pypy3-v5.10.0-osx64-2/site-packages/jupyter_client/kernelspec.py", line 324, in install_kernel_spec
raise ValueError("Can't specify both user and prefix. Please choose one or the other.")
ValueError: Can't specify both user and prefix. Please choose one or the other.

Steve Spicklemire

unread,
Feb 25, 2018, 4:39:01 PM2/25/18
to vpytho...@googlegroups.com, Steve Spicklemire
Hmm. when I try the no-notebook version I get the following.

aluminum:~ steve$ pypy3 foo.py
Traceback (most recent call last):
File "foo.py", line 1, in <module>
from vpython import *
File "/Users/steve/pypy3-v5.10.0-osx64-2/site-packages/vpython/__init__.py", line 37, in <module>
from .no_notebook import *
File "/Users/steve/pypy3-v5.10.0-osx64-2/site-packages/vpython/no_notebook.py", line 148, in <module>
__server = HTTPServer(('', __HTTP_PORT), serveHTTP)
File "/Users/steve/pypy3-v5.10.0-osx64-2/lib-python/3/socketserver.py", line 440, in __init__
self.server_bind()
File "/Users/steve/pypy3-v5.10.0-osx64-2/lib-python/3/http/server.py", line 138, in server_bind
socketserver.TCPServer.server_bind(self)
File "/Users/steve/pypy3-v5.10.0-osx64-2/lib-python/3/socketserver.py", line 454, in server_bind
self.socket.bind(self.server_address)
OSError: [Errno 48] Address already in use

I’m not running any other servers so this seems pypy3 specific. The same python file runs fine in no_notebook mode with cpython (3.6).

Also, the tests I’ve tried with pypy3 in jupyter notebook (with vpython) have worked OK.

I moved the code from Gas.py into a notebook and got:

0.5550979999999996 ms per loop

with the same source, using CPython I get:

5.573568999999999 ms per loop

So it appears to be a 10x improvement. Wow.

When I tried the numpy version I get:

(vsci3) aluminum:~ steve$ python ~/Downloads/GasNumpy.py
Traceback (most recent call last):
File "/Users/steve/Downloads/GasNumpy.py", line 127, in <module>
b = 2*dot(rrel,vrel)
TypeError: Argument 'A' has incorrect type (expected vpython.cyvector.vector, got numpy.ndarray)

Maybe my version of numpy?

>>> numpy.version.full_version
'1.13.3'

-steve

John

unread,
Feb 25, 2018, 6:01:32 PM2/25/18
to VPython-users
The pypy download webpage has instructions for installing standard nump y for pypy. It suggests

pypy3 -m pip install cython numpy
So it looks like cython is also required.

What is the timing on your machine for gas.py running in glowscript. How does it compare with pypy.

John

unread,
Feb 26, 2018, 3:18:47 PM2/26/18
to VPython-users
The error says you can't specify both --user and --prefix . So I assume you removed --user and tried 

pypy3 -m ipykernel install --name pypy3 --prefix "/Users/steve/pypy3-v5.10.0-osx64-2" --display-name "Python3 (PyPy)" 

After performing this command can you now just run

jupyter notebook 

and then switch between pypy3 kernel and vpython kernel in the notebook without an error or do you need to run jupyter notebook from pypy3 directory.

John

John

unread,
Mar 9, 2018, 1:48:01 PM3/9/18
to VPython-users
If you use VPython version 7.4.1 then you will find that pypy3 now works in no-notebook mode. Now you can get a 10X speed up in the Gas.py test program using pypy3 in either no-notebook or notebook mode on a  Mac OSX or Linux machine. The steps to install pypy3 and get vpython working in no-notebook mode are as follows.

Step 1: Download PyPy and install pypy3 on your machine. (PyPy 3.5.3 compatible)


Step 2: Add the installed path to pypy3 on your machine to your PATH environment variable

Step 3: Add pip to pypy3 from the terminal window

            pypy3 -m ensurepip

Step 4: pip install vpython to pypy3     (VPython version 7.4.1 or greater)

            pypy3 -m pip install vpython

Step 5: Run the Gas.py program in no-notebook mode using pypy3

            pypy3 Gas.py

You should see a 10X speed improvement over just running it with regular python in no-notebook mode.

            python Gas.py

John

Bruce Sherwood

unread,
Mar 11, 2018, 5:59:50 PM3/11/18
to VPython-users
That's very cool, John!

Alas, PyPy apparently is not well supported on Windows.

Bruce
Reply all
Reply to author
Forward
0 new messages