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

Add the "Python 3.6 + Anaconda 5.2 EXPERIMENTAL!" mode of PythonTutor (recent feature) #10

Closed
Naereen opened this issue Feb 20, 2021 · 13 comments · Fixed by #11
Closed

Comments

@Naereen
Copy link
Contributor

Naereen commented Feb 20, 2021

Hello there @kikocorreoso,
I noticed that your extension only recognizes the following mode of using http://PythonTutor.com/:
'python2', 'python3', 'java', 'javascript', 'typescript', 'ruby', 'c', 'c++'
But a recent new feature is "Python 3.6 + Anaconda 5.2 EXPERIMENTAL!".

It's very useful because it provides a teaching/debugging environment that supports lots of scientific packages, including numpy, scipy, etc (of course, no displaying of matplotlib, it gives this error and is a known missing features):

ImportError: libGL.so.1: cannot open shared object file: No such file or directory

Do you think you could update your extension and allow a "anaconda" mode?
By reading the code of this extension, it would probably be easy!

  • I can try to hack it myself, I don't think it would give any issue, but I won't be able to publish the package to pypi etc, so it would be simpler if you could try it.
  • If you don't have time but are willing to merge a pull request, I can try to hack it myself, send a PR and let you merge and republish your package to pypi!

Thanks in advance! Regards from France, @Naereen

@Naereen
Copy link
Contributor Author

Naereen commented Feb 20, 2021

Using this code as an example, I get the following iframe:

<iframe width="800" height="500" frameborder="0" src="http://pythontutor.com/iframe-embed.html#code=%23%20https%3A//docs.scipy.org/doc/scipy/reference/tutorial/integrate.html%0A%0Ax%20%3D%204%0Aprint%28%22Hello%20world!%22%20*%20x%29%0A%0Aimport%20numpy%20as%20np%0A%0AI%20%3D%20np.sqrt%282/np.pi%29*%2818.0/27*np.sqrt%282%29*np.cos%284.5%29%20-%204.0/27*np.sqrt%282%29*np.sin%284.5%29%29%0A%0Aprint%28I%29%0A%0Aimport%20scipy.integrate%20as%20integrate%0Aimport%20scipy.special%20as%20special%0Aresult%20%3D%20integrate.quad%28lambda%20x%3A%20special.jv%282.5,x%29,%200,%204.5%29%0Aprint%28result%29%0A%0AI%20%2B%3D%20np.sqrt%282*np.pi%29%20*%20special.fresnel%283/np.sqrt%28np.pi%29%29%5B0%5D%0Aprint%28I%29%0A%0Aprint%28abs%28result%5B0%5D-I%29%29%0A&codeDivHeight=400&codeDivWidth=350&cumulative=false&curInstr=0&heapPrimitives=nevernest&origin=opt-frontend.js&py=py3anaconda&rawInputLstJSON=%5B%5D&textReferences=false"> </iframe>

The interesting part is py=py3anacondain the URL!

From what I can read on the code

if args.lang[0].lower() in ['python2', 'python3',

# Setup the language URL param

it should be easy to add this py3anaconda language code in the "whitelist" that you wrote!
I'll try to hack this on my local installation of the magic, and reload my notebook.

@Naereen
Copy link
Contributor Author

Naereen commented Feb 20, 2021

For reproducibility, here is a ~1min GIF showing what I did before trying to add support for this py3anaconda environment:
Peek 21-02-2021 00-55

@Naereen
Copy link
Contributor Author

Naereen commented Feb 21, 2021

Here is the durty hack I just wrote:

tutormagic.py: 140,141c140,141
<             if args.lang[0].lower() in ['python2', 'python3', 
<                                         'java', 
---
>             if args.lang[0].lower() in ['python2', 'python3', 'py3anaconda',
>                                         'java',
152c152
<                     "'typescript', 'ruby', 'c', 'c++'".format(args.lang[0]))
---
>                     "'typescript', 'ruby', 'c', 'c++', 'py3anaconda'".format(args.lang[0]))
177a178,179
>         elif lang == "py3anaconda":
>             url += "py=py3anaconda"

@Naereen
Copy link
Contributor Author

Naereen commented Feb 21, 2021

And here is a demo showing that it works!

Peek 21-02-2021 01-10

@kikocorreoso
Copy link
Owner

I was not aware of the py36anaconda option. From the pythontutor.com web page it says 'unsopported'. I can include it here from your PR #11 but take into account this could break your code at any moment (from 3rd parties I don't manage, pythontutor.com).

As a general advice, you shouldn't rely on 'unsupported' stuff.

@Naereen
Copy link
Contributor Author

Naereen commented Feb 22, 2021

Hi again,
Well I think in the context of PythonTutor, unsupported means that the claim

Get live help for free in the Python tutoring Discord chat room
is not covering py3anaconda.

As a general advice, you shouldn't rely on 'unsupported' stuff.
I agree, but if I were rigorous, I would take it to the next level: especially for teaching activities, we shouldn't rely on closed-source online stuff! Imagine I build all my course using some visualizations on PythonTutor, and it's unreachable (or taken down) the week when I'm teaching... or just if I don't have WiFi in the room where I'm teaching...

I'll keep in mind the tiny lolviz Jupyter IPython extension, as it allows basic but nice illustrations of simple data-structures and pointers. It's far from close to PyTutor but well it can help.

@kikocorreoso
Copy link
Owner

As a general advice, you shouldn't rely on 'unsupported' stuff.

I agree, but if I were rigorous, I would take it to the next level: especially for teaching activities, we shouldn't rely on closed-source online stuff! Imagine I build all my course using some visualizations on PythonTutor, and it's unreachable (or taken down) the week when I'm teaching... or just if I don't have WiFi in the room where I'm teaching...

When I started this package pythontutor was opensource. I don' know why now it isn't anymore 😞

I'll keep in mind the tiny lolviz Jupyter IPython extension, as it allows basic but nice illustrations of simple data-structures and pointers. It's far from close to PyTutor but well it can help.

I didn't know about lolviz. It seems quite nice!!!! This extension mixed with other of my proof-of-concept jupyter extension called pizarra-nb could be quite interesting. pizarra-nb is not polished and was a hack I made as a proof of concept but I see potential there.

@Naereen
Copy link
Contributor Author

Naereen commented Feb 22, 2021

I think PythonTutor's author was tired of maintaining as open source, as his website is used by millions of users I can expect the number of issues to be large.
And the last documentation I read on v5-unity and v4-cokapi indicates that all the serverside setup is difficult to reproduce (I read something like: "all this is hardwired for my own server, I can't help if you want to reproduce it").
I completely understand the desire to just remove it from GitHub.

@Naereen
Copy link
Contributor Author

Naereen commented Feb 22, 2021

Regarding lolviz, it could even be nicer if parrt/lolviz#4 and parrt/lolviz#27 get merged!

@Naereen
Copy link
Contributor Author

Naereen commented Feb 22, 2021

Hm your https://github.com/kikocorreoso/pizarra-nb is awesome!
I've been using and helping develop the more complete https://tableaunoir.github.io/ tool for the last 6 months, but pizarra-nb is interesting as it is right in the notebook.

Did you know about RISE which allows to turn classical notebook in live slideshow (live as in I can type and execute code, in any kernel) ? RISE has a tiny and unknown feature that is it includes a chalkboard and a "pen" tool to write on any slide! See https://rise.readthedocs.io/en/stable/customize.html#enable-chalkboard-capabilities

@Naereen
Copy link
Contributor Author

Naereen commented Mar 4, 2021

@kikocorreoso any update?

@kikocorreoso
Copy link
Owner

It is merged and you can install it from PyPI using pip.

Thanks.

@Naereen
Copy link
Contributor Author

Naereen commented Mar 6, 2021

Oh great, thanks @kikocorreoso !
I'll try it out by upgrading from pip.

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

Successfully merging a pull request may close this issue.

2 participants