[IPython-dev] [matplotlib-devel] IPython (new) + matplotlib report: happy news

Fernando Perez fperez.net@gmail....
Tue Sep 14 14:49:47 CDT 2010


On Tue, Sep 14, 2010 at 12:38 PM, Gökhan Sever <gokhansever@gmail.com> wrote:
>
> Sage provides some level of interaction actually without any deployment made
> on local side. Try for instance the following example on sagenb.org
> from scipy import stats
> import numpy as np
> import matplotlib.pyplot as plt
> @interact
> def plot_gamma(a=(1,(1,10)), loc=(0,(0,10)), scale=(1,(1,10))):
>     rv = stats.gamma(a, loc, scale)
>     x = np.linspace(-1,20,1000)
>     plt.plot(x,rv.pdf(x))
>     plt.grid(True)
>     plt.savefig('plt.png')
>     plt.clf()
> This one is very useful for educational and demonstrative purposes. Still
> requires a bit Sage syntax manipulations to make things fully interacting on
> browser.
> Nice that you have matured IPython infra for implementing
> such interactive functionality. I was thinking perhaps running something on
> top GApss Engine but not sure they allow compiling/running C/C++ extensions
> on their servers. Alternatively, like in Sage servers virtual OS'es might be
> the way to go with it then possibly there will be user registration and
> management issues (not sure about all specifics).

Actually sage does have one *implicit* but very particular 'local
deployment': its notebook execution model is *strictly* tied to the
idea that the client is a web browser.  Try this code in the sage
terminal (i.e. their customized ipython, not the notebook):

sage: @interact
....: def x(a=(1, (1, 10))):
....:     print a
....:

and you'll see:

<html><!--notruncate--><div padding=6 id='div-interact-0'> <table
width=800px height=20px bgcolor='#c5c5c5'
                 cellpadding=15><tr><td bgcolor='#f9f9f9' valign=top
align=left><table><tr><td align=right><font
color="black">a&nbsp;</font></td><td><table><tr><td>
        <div id='slider-a-0' style='margin:0px; margin-left: 1.0em;
margin-right: 1.0em; width: 15.0em;'></div>

 ... lots more...

</table><div id='cell-interact-0'><?__SAGE__START>
        <table border=0 bgcolor='#white' width=100% height=100%>
        <tr><td bgcolor=white align=left
valign=top><pre><?__SAGE__TEXT></pre></td></tr>
        <tr><td  align=left valign=top><?__SAGE__HTML></td></tr>
        </table><?__SAGE__END></div></td>
                 </tr></table></div>
                 </html>
sage:


So you can see, @interact in sage does basically:

- analyze the inputs of the function
- do some basic 'type inference' and emit javascript/html controls for
each parameter.
- emit an html section that wires the above controls to repeated calls
of the decorated function as the controls are operated.

This is very cool, and it enables great functionality, but it's
hard-coded to an html/javascript client.

What we're doing is a little different, as we've built a *protocol*
that clients can use to talk to the kernel, regardless of how they are
implemented.

As the functionality matures, we'll see who contributes a
browser-based client (that will require wrapping the kernel in an http
server, obviously).  And then the question of things like @interact
will be an interesting one to think about.  @interact by nature is
creating a user interface (Mathematica's Manipulate creates Notebook
controls, sage's @interact creates HTML ones).  I'm not sure yet how
we'll approach that: having per-client implementations? A traits-style
approach where each client renders it differently?  No idea yet.

Cheers,

f


More information about the IPython-dev mailing list