A GUI for sympy

1,292 views
Skip to first unread message

Sam Magura

unread,
Aug 2, 2011, 10:58:41 PM8/2/11
to sy...@googlegroups.com
Hi folks,

I wanted to share a sympy-related project that I have been working on. It is a pretty standard notebook interface, and will seem really familiar if you've used Mathematica or similar CAS front-ends. I've borrowed a lot of code from the earlier Symbide project. I'm calling it sympy notebook.

My main goal for this project is to make sympy feel like a more "traditional" CAS, in terms of user interface. I hope that doing so will not only be useful for existing users, but will also get more people using sympy, especially those who are less technically-minded. To do this, I've started by creating an interface that lets you work on small sections of code at a time, edit previously entered code, and save your work. Expressions and plots are displayed graphically. A major improvement over Symbide is that cells can be cut, copied, and pasted. Future releases should emphasize that sympy notebook is more than a Python console. I've documented current features and features I want add on the GitHub wiki

- To clone my repository, use g...@github.com:smagura/sympy-notebook.git
- And, pull from my fork of sympy (g...@github.com:smagura/sympy.git) if you want LaTeX printing to work. 

It would be great to get feedback on this. Thanks.

Sam Magura

Aaron Meurer

unread,
Aug 2, 2011, 11:40:24 PM8/2/11
to sy...@googlegroups.com
Hi.

I'll look at this and report what I think about it, but I just want to
note that people should use the following urls to clone. The ones you
gave are the ssh urls, and are for you only.

sympy-notebook: git://github.com/smagura/sympy-notebook.git
sympy fork: git://github.com/smagura/sympy.git

Aaron Meurer

> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/sympy/-/0IdGgLDEnfsJ.
> To post to this group, send email to sy...@googlegroups.com.
> To unsubscribe from this group, send email to
> sympy+un...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/sympy?hl=en.
>

Aaron Meurer

unread,
Aug 3, 2011, 12:51:23 AM8/3/11
to sy...@googlegroups.com
According to the wiki, Pyglet is an optional dependency, but it does
not work without it (it fails with an ImportError).

Aaron Meurer

Sam Magura

unread,
Aug 3, 2011, 2:07:34 PM8/3/11
to sy...@googlegroups.com

Aaron Meurer

unread,
Aug 6, 2011, 4:53:56 AM8/6/11
to sy...@googlegroups.com
So I've literally spent the entire time since you wrote the first
message trying to compile gtk on my computer, and I've finally given
up and I just tried this on a Linux laptop that I had laying around.

gtk is basically impossible to install on Mac OS X, and it's a rather
unfortunate choice of GUI platform. Installing QT (for IPython's
qtconsole) was relatively easy, as they have a binary distribution
(see https://github.com/sympy/sympy/wiki/Installing-the-IPython-qtconsole-in-Mac-OS-X).

But getting now to the program itself, the interaction is a little
awkward. I don't know why everyone wants to use Shift-Enter for
execution all the time, but I personally don't like it.

Why did you write your own parser? Does sympify() not satisfy your needs?

How do you get the LaTeX output? I could only get the string printer
(indeed, I couldn't even get the pretty printer to work, unless I
typed pprint(expr)?

Have you considered using the new IPython with the kernel
architecture? It's supposedly very easy to use with a GUI. See
http://mail.scipy.org/pipermail/ipython-dev/2011-August/008057.html.

I typed "pprint(Integral(1/x, x))" and executed it, then I saved the
notebook. Then I tried opening it, but it just printed (to the
console) "Could not read file". I can upload the file if you cannot
reproduce.

Aaron Meurer

On Wed, Aug 3, 2011 at 12:07 PM, Sam Magura <srma...@gmail.com> wrote:
> Thanks for the heads up.
> Fixed: https://github.com/smagura/sympy-notebook/commit/778ebb3f7c82d9dcd41663c1e11d4a7de221531c
>

> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To view this discussion on the web visit

> https://groups.google.com/d/msg/sympy/-/4Uhyuewi_ssJ.

Aaron Meurer

unread,
Aug 6, 2011, 4:58:14 AM8/6/11
to sy...@googlegroups.com
I just tried plotting, and it works pretty well. The only thing that
is less than ideal is that to manipulate the plot, it has to open in a
new window.

Aaron Meurer

Aaron Meurer

unread,
Aug 6, 2011, 5:04:28 AM8/6/11
to sy...@googlegroups.com
> I typed "pprint(Integral(1/x, x))" and executed it, then I saved the
> notebook.  Then I tried opening it, but it just printed (to the
> console) "Could not read file".  I can upload the file if you cannot
> reproduce.
>

Oh sorry, that was me being stupid and trying to open
sympy-notebook.py instead of new-notebook.snb. Ignore this.

Aaron Meurer

Sam Magura

unread,
Aug 7, 2011, 11:06:23 AM8/7/11
to sy...@googlegroups.com
Thanks for looking over it Aaron.

- Executing: I will add a setting eventually that lets you use Enter rather than Shift+Enter.

- Pretty printing: Are you sure you were using my sympy fork?
--- I will set unicode pretty printing to be enabled by default

- Parser: Almost everything in ./parsing is straight from Symbide. I'm sure it needs some clean-up. The main thing it does that sympify() can't do is detect undefined variables, and then define them as symbols.

- IPython kernel: Though that is a cool example, I don't think it is right for this project. 
--- Parsing: I think special IPython shorthand syntax could make automatic symbol definition much more difficult. http://ipython.org/ipython-doc/stable/interactive/reference.html#automatic-quoting
--- Execution: I'm currently working on an execution model that lets the user kill the process that is doing the execution without losing their namespace (all the variables set in that session.)  I think using IPython would complicate this; features like output caching are going to break when moving execution to a new process.

- Plotting: Agreed. That's something I want to work on.

- GTK: That's too bad that it's hard to get GTK working on Mac. This application claims to have GTK and PyGTK compiled for you: http://0install.net/install-mac.html. No idea if it works

Sam

Aaron Meurer

unread,
Aug 7, 2011, 9:09:57 PM8/7/11
to sy...@googlegroups.com
On Sun, Aug 7, 2011 at 9:06 AM, Sam Magura <srma...@gmail.com> wrote:
> Thanks for looking over it Aaron.
> - Executing: I will add a setting eventually that lets you use Enter rather
> than Shift+Enter.
> - Pretty printing: Are you sure you were using my sympy fork?

Ah, no. I didn't know about this. Assumedly it is some branch at
your GitHub fork?

What did you have to change in your fork to make it work?

> --- I will set unicode pretty printing to be enabled by default
> - Parser: Almost everything in ./parsing is straight from Symbide. I'm sure
> it needs some clean-up. The main thing it does that sympify() can't do is
> detect undefined variables, and then define them as symbols.

Yes it does:

In [33]: a
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
/Users/aaronmeurer/Documents/python/sympy/sympy/<ipython-input-33-60b725f10c9c>
in <module>()
----> 1 a

NameError: name 'a' is not defined

In [34]: sympify("a")
a

In [35]: type(sympify("a"))
<class 'sympy.core.symbol.Symbol'>

By default, it uses the default namespace, so if you define a
variable, it doesn't recognize it. But this is easy to remedy by
passing the locals() dict to sympify():

In [40]: a = 1

In [41]: sympify("a")
a

In [42]: sympify("a", locals=locals())
1

By the way, your parser has a bug where it prints the output of
variable assignments, i.e.,

: a = 1

should be silent.


> - IPython kernel: Though that is a cool example, I don't think it is right
> for this project.
> --- Parsing: I think special IPython shorthand syntax could make automatic
> symbol definition much more
> difficult. http://ipython.org/ipython-doc/stable/interactive/reference.html#automatic-quoting

This can all be disabled. Indeed, I've disabled autocall in my own
personal IPython config file because I don't like it.

> --- Execution: I'm currently working on an execution model that lets the
> user kill the process that is doing the execution without losing their
> namespace (all the variables set in that session.)  I think using IPython
> would complicate this; features like output caching are going to break when
> moving execution to a new process.

Interesting. I don't know if the IPython architecture would let you
do this. You'd have to ask on their list.

> - Plotting: Agreed. That's something I want to work on.
> - GTK: That's too bad that it's hard to get GTK working on Mac. This
> application claims to have GTK and PyGTK compiled for
> you: http://0install.net/install-mac.html. No idea if it works
> Sam

I'll try it out.

Aaron Meurer

Sam Magura

unread,
Aug 7, 2011, 9:50:16 PM8/7/11
to sy...@googlegroups.com


On Sunday, August 7, 2011 9:09:57 PM UTC-4, Aaron Meurer wrote:

Ah, no.  I didn't know about this.  Assumedly it is some branch at
your GitHub fork?

What did you have to change in your fork to make it work?

Yes, it's the master branch of my sympy fork. Here's the pull request: https://github.com/sympy/sympy/pull/500 

Yes it does:

In [33]: a
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
/Users/aaronmeurer/Documents/python/sympy/sympy/<ipython-input-33-60b725f10c9c>
in <module>()
----> 1 a

NameError: name 'a' is not defined

In [34]: sympify("a")
a

In [35]: type(sympify("a"))
<class 'sympy.core.symbol.Symbol'>

Ah, I see what you are saying. I thought you were saying that 

>>> sympify("a = b**2")

would define b as a symbol. But rather, what I can do is something like

>>> #Return raw Python code
....   my_parser("a = b**2")

"sympify('b', locals=locals())
a = b **2 "

By the way, your parser has a bug where it prints the output of
variable assignments, i.e.,

: a = 1

should be silent.


Not a bug, but OK, (having it silent) would be more in line with the Python console. Added to future feature list.

I've just gotten back to school, so probably won't be doing much work over the next week. I'll notify you when I add new major features.

Sam

Christophe BAL

unread,
Aug 7, 2011, 9:52:44 PM8/7/11
to sy...@googlegroups.com
Hello,
pySide or pyQt works well on Linux, Windows and Mac.

C.

Aaron Meurer

unread,
Aug 7, 2011, 9:54:13 PM8/7/11
to sy...@googlegroups.com
On Sun, Aug 7, 2011 at 7:50 PM, Sam Magura <srma...@gmail.com> wrote:
>
> On Sunday, August 7, 2011 9:09:57 PM UTC-4, Aaron Meurer wrote:
>>
>> Ah, no.  I didn't know about this.  Assumedly it is some branch at
>> your GitHub fork?
>>
>> What did you have to change in your fork to make it work?
>
> Yes, it's the master branch of my sympy fork. Here's the pull
> request: https://github.com/sympy/sympy/pull/500

Oh. Sorry that that got forgotten due to the unrelated bug. I'll go
and review it right now.

Aaron Meurer

> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To view this discussion on the web visit

> https://groups.google.com/d/msg/sympy/-/KTO7Sl6-mnoJ.

Aaron Meurer

unread,
Aug 8, 2011, 4:22:46 AM8/8/11
to sy...@googlegroups.com
OK, I've merged your pull request, and I now have working LaTeX output.

By the way, I wasn't very clear when I said "the interaction is a
little awkward". I think the main thing (aside from the Shift-Enter
vs. Enter deal) is that executing a statement does not create a new
cell. Indeed, it's not very clear at all how to create a new cell.

Aaron Meurer

Sam Magura

unread,
Aug 8, 2011, 6:44:12 PM8/8/11
to sy...@googlegroups.com
Thanks for the merge.

Check out the branch spacer-focus on sympy-notebook. I've set it to focus the next spacer rather leave the focus in the input cell when a cell is executed. I think it makes it much more clear how to create a new cell.

I think automatically inserting a new cell would be annoying in many situations. Anyway, this way doesn't require any more keystrokes.

Sam Magura

Aaron Meurer

unread,
Aug 8, 2011, 11:37:19 PM8/8/11
to sy...@googlegroups.com
On Mon, Aug 8, 2011 at 4:44 PM, Sam Magura <srma...@gmail.com> wrote:
> Thanks for the merge.
> Check out the branch spacer-focus on sympy-notebook. I've set it to focus
> the next spacer rather leave the focus in the input cell when a cell is
> executed. I think it makes it much more clear how to create a new cell.
> I think automatically inserting a new cell would be annoying in many
> situations.

I don't see how. To me, *not* automatically inserting a new cell is annoying.

Oh, and by the way, that installer you linked to just installs pygtk,
not gtk (and of course, installing pygtk from source once you have gtk
is trivial).

Aaron Meurer

Sam Magura

unread,
Aug 9, 2011, 12:17:10 AM8/9/11
to sy...@googlegroups.com
Not sure if you've tried it out, but here's why the new way is better than inserting a new cell. (By new way, I mean branch spacer-focus.)

If the user wants to execute the current cell, then start typing code in a new cell after the current one, both ways are the same. Shift+Enter, then start typing.

If the user wants to execute the current cell, but not create a new cell after the current one:
-- New way: Shift+Enter (no cell is created, the "spacer" is just focused)
-- Insert cell way: Shift+Enter, then delete the new cell

I hope this clears it up.

Too bad about the installer.

Sam

Aaron Meurer

unread,
Aug 9, 2011, 12:36:51 AM8/9/11
to sy...@googlegroups.com
OK, I just tried it, and I still think that actually creating a new
cell would be better. It's not clear that if you just start typing
that it will create a new cell for you. The whole "spacer" deal is
rather subtle.

Aaron Meurer

Aaron Meurer

unread,
Aug 9, 2011, 12:40:13 AM8/9/11
to sy...@googlegroups.com
Also, I just noticed a bug. Suppose you've got a bunch of empty
cells. Pressing delete a lot sometimes deletes all the cells, but
sometimes it gets "stuck" on a spacer and just deletes and recreates
the same cell.

Aaron Meurer

Sam Magura

unread,
Aug 9, 2011, 8:26:39 AM8/9/11
to sy...@googlegroups.com
I've added both of these things (new cell creation and delete bug) to the GitHub issues for sympy notebook so that I'll look at them when I have time to. Thanks!

Sam Magura
Reply all
Reply to author
Forward
0 new messages