New SymPy shell based on JupyterLite and Pyodide

229 views
Skip to first unread message

ivan....@gmail.com

unread,
May 9, 2022, 11:20:50 PM5/9/22
to sympy
Hi All,

Context: Thanks to developments in the JavaScript world, we can now run Python in the browser. See the projects emscripten, Pyodide, and JupyterLite/Pyolite for more about this. Essentially, modern web browsers are capable of running the real CPython interpreter, and not only that but most pure-Python packages can be imported and run without issues!

Several SymPy users proposed the idea of using this new functionality to create a new SymPy shell that runs in the browser. I'm happy to announce this idea is now a reality. Navigate to this URL https://www.sympy.org/en/shell.html to check it out.

Some notes, in point form, about this project:
  • based on latest version of SymPy (the version on pypi)
  • initial load takes between 15 and 30 seconds (on desktop)
  • running commands is very fast after initial load
  • supports modern web browsers like Firefox and Chrome
  • works on some mobile browsers (more testing needed)

Many thanks to Jeremy Tuloup who showed how the JupyterLite REPL can be customized to create a SymPy shell.

The new SymPy shell on the sympy.org website is an experiment that allows us to test the new JupyterLite-based REPL and iron out any edge cases, with the goal of eventually using the same approach on https://live.sympy.org/ (which has been becoming increasingly difficult to maintain and keep up to date).

I invite you all to try out the new shell by running your favorite SymPy calculations (see bit.ly/sympyjstest for examples). If you encounter problems, bugs, or other unexpected behavior during testing, please add a comment to this issue: https://github.com/sympy/sympy.github.com/issues/176


 - Ivan


PS: For more background info about this work, see this initial discussion here and PRs 169 and 174.



Aaron Meurer

unread,
May 10, 2022, 1:41:31 PM5/10/22
to sy...@googlegroups.com
This is great to see. Thank you so much for working on this. I hope we can iron out the kinks with this, but in many ways, it is already better than the previous iteration of SymPy Live.

By the way, once we have the main SymPy Live working, we should investigate if there is an extension we can add to the docs to enable execution there. We had to remove the old SymPy Live extension from the dev docs when we moved to the new theme, and once we completely replace SymPy Live with the jupyterlite version, we will shut down the App Engine version that was in the docs. 

Aaron Meurer

--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/46a09c63-31bd-4e1d-9257-0644074baaacn%40googlegroups.com.

David Bailey

unread,
May 10, 2022, 5:07:48 PM5/10/22
to sy...@googlegroups.com
--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/46a09c63-31bd-4e1d-9257-0644074baaacn%40googlegroups.com.

I tried a simple indefinite integral  - integrate(sin(x**3),x). This displayed beautifully, but I discovered that I could not click on the command I'd just entered to alter it. I guess this is a limitation of the implementation, but I thought I'd point this out.


David

Aaron Meurer

unread,
May 10, 2022, 6:14:22 PM5/10/22
to sy...@googlegroups.com
> I tried a simple indefinite integral - integrate(sin(x**3),x). This displayed beautifully, but I discovered that I could not click on the command I'd just entered to alter it. I guess this is a limitation of the implementation, but I thought I'd point this out.

I think this is intentional behavior. JupyterLite is designed to work
more like an interactive console like IPython rather than the
notebook. You can go back to a previous command using the up arrow. It
would be good if it could add buttons to do this for mobile. I think
that is on their TODO list.

Aaron Meurer

>
>
> David
>
> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/0fc77786-06d8-a34e-c945-e82fd583766b%40dbailey.co.uk.

David Bailey

unread,
May 11, 2022, 5:29:30 AM5/11/22
to sy...@googlegroups.com
On 10/05/2022 23:14, Aaron Meurer wrote:
> I think this is intentional behavior. JupyterLite is designed to work
> more like an interactive console like IPython rather than the
> notebook. You can go back to a previous command using the up arrow. It
> would be good if it could add buttons to do this for mobile. I think
> that is on their TODO list.
>
Thanks Aaron - yes the arrow keys let you find a previous command and
resubmit it with alterations, but of course, if the alterations are just
typos, you end up with a 'notebook' cluttered with rubbish.

Also, there doesn't seem to be a way of saving a 'notebook' other than
on paper. I thought at least I could save the page (in Firefox), but
when I reload it, it just reloads in the initial state - all the work
has gone.

I'm sure these issues are hard to deal with because the browser api
maybe does not cooperate, but I'd have thought it makes the result more
like a SymPy demo than a tool that could be used seriously.

David

Ivan Savov

unread,
May 11, 2022, 7:41:31 AM5/11/22
to sy...@googlegroups.com
Also, there doesn't seem to be a way of saving a 'notebook' other than
on paper. I thought at least I could save the page (in Firefox), but
when I reload it, it just reloads in the initial state - all the work
has gone.
 
I'm aware of the need for some way to share the results of a SymPy session. The old live shell at live.sympy.org offers the thumbtack button (), which encodes the session commands into a URL querystring. The new shell already supports the evaluation of such saved session commands, see examples: simple, multiline, longer.
It's on the TO-RESEARCH list to figure out how to implement -like functionality for creating exporting saved sessions in the new shell (possibly with a custom jupyter REPL extension). See here.
 
- Ivan

Aaron Meurer

unread,
May 11, 2022, 4:21:07 PM5/11/22
to sy...@googlegroups.com
You can run JupyterLite with a full blown Jupyter Lab here
https://jupyterlite.readthedocs.io/en/latest/_static/lab/index.html.
It includes SymPy. It seems to offer persistence. It's not really
clear to me where the files are stored but they must be stored
somewhere because when I reload the page the notebooks are all still
there, and I even have some notebooks from when I tried it 7 months
ago that are still there.

The SymPy Live shell is just designed to be a mini "try sympy" shell
that you can use on the SymPy website. We'd also like to add something
using it to the docs so you can easily run the documentation examples
(similar to the existing SymPy Live extension in the docs).

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/e30fcacf-6fa6-a786-c359-eb64f6db7468%40dbailey.co.uk.

Chris Smith

unread,
May 14, 2022, 5:31:24 PM5/14/22
to sympy
Ivan, this is really nice! Thanks.

/c

Reply all
Reply to author
Forward
0 new messages