Sharedwww / talks / 2006-05-11-sage_how_works / current.texOpen in CoCalc
Author: William A. Stein
1
2
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3
% (c) William Stein
4
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5
6
\documentclass{beamer}
7
\usepackage{beamerthemesplit}
8
\usepackage{pgfpages}
9
10
%\pgfpagesuselayout{4 on 1}[letterpaper,landscape, border shrink=5mm]
11
%\setbeamercolor{background canvas}{bg=black!0}
12
13
\usepackage{graphicx}
14
\newcommand{\page}[1]{\frame{#1}}
15
16
\usepackage{amsmath}
17
\usepackage{amsfonts}
18
\usepackage{amssymb}
19
\usepackage{amsthm}
20
\usepackage{graphicx}
21
\usepackage{pstricks}
22
\usepackage{color}
23
\definecolor{dbluecolor}{rgb}{0,0,0.6}
24
\definecolor{dredcolor}{rgb}{.5,0.0,0.0}
25
\definecolor{dgreencolor}{rgb}{0,0.4,0}
26
\definecolor{blue}{rgb}{.02, .02, .908}
27
\newcommand{\dred}{\color{dredcolor}\bf}
28
\newcommand{\dblue}{\color{dbluecolor}\bf}
29
\newcommand{\dgreen}{\color{dgreencolor}\bf}
30
%\newcommand{\dred}{\bf}
31
%\newcommand{\dblue}{\bf}
32
%\newcommand{\dgreen}{\bf}
33
34
\usepackage{xspace} % to allow for text macros that don't eat space
35
\newcommand{\SAGE}{{\color{blue}\sf SAGE}\xspace }
36
\newcommand{\sage}{\SAGE}
37
38
\newcommand{\graph}[1]{\includegraphics[width=0.45\textwidth]{#1}}
39
40
\title{How SAGE Works: Interfaces}
41
\author{William Stein (University of Washington)}
42
\date{May 11, 2006: UW SAGE Seminar\vspace{2ex}\\
43
\includegraphics[width=1.5in]{icon-5}}
44
\bibliographystyle{amsalpha}
45
\newcommand{\Q}{\mathbb{Q}}
46
\newcommand{\Z}{\mathbb{Z}}
47
\newcommand{\defn}[1]{{\em #1}}
48
% ---- SHA ----
49
\DeclareFontEncoding{OT2}{}{} % to enable usage of cyrillic fonts
50
\newcommand{\textcyr}[1]{%
51
{\fontencoding{OT2}\fontfamily{wncyr}\fontseries{m}\fontshape{n}%
52
\selectfont #1}}
53
\newcommand{\Sha}{{\mbox{\textcyr{Sh}}}}
54
\DeclareMathOperator{\rank}{rank}
55
\DeclareMathOperator{\Vis}{Vis}
56
\DeclareMathOperator{\HH}{H}
57
\DeclareMathOperator{\Ker}{Ker}
58
\DeclareMathOperator{\ord}{ord}
59
\renewcommand{\H}{\HH}
60
\newcommand{\hra}{\hookrightarrow}
61
\newcommand{\isom}{\cong}
62
\newcommand{\ds}{\displaystyle}
63
\renewcommand{\t}[1]{\begin{center}{\large{\dblue #1}}\end{center}}
64
65
66
\begin{document}
67
68
\page{
69
\maketitle
70
}
71
72
73
\begin{frame}
74
\begin{abstract}
75
This talk will be aimed at people who want to understand the
76
architecture of \SAGE. Today I will explain some of the details
77
about how \SAGE interfaces with computer algebra systems and
78
how people interface with \sage.
79
\begin{enumerate}
80
\item How \sage{} {\dblue interfaces} with other computer algebra systems.
81
\item How \sage{} {\dblue interfaces} with users via their web-browsers.
82
\end{enumerate}
83
\end{abstract}
84
\end{frame}
85
86
\begin{frame}
87
\t{Part I: How \sage{} {\dblue interfaces} with other computer algebra systems.}
88
\end{frame}
89
90
\begin{frame}
91
\t{Class Hierarchy}
92
\includegraphics[width=1.1\textwidth]{classdia}
93
94
(examples)
95
\end{frame}
96
97
\begin{frame}
98
\t{Pexpect and Pseudotty's}
99
\begin{itemize}
100
\item {\dblue Pseudotty:} A device which appears to an application program
101
as an ordinary terminal but which is {\em in fact} connected to a
102
different process. Pseudo-ttys have a slave half and a control half.
103
104
\item {\dblue Pexpect:} {\em makes Python a better tool for controlling
105
other applications.} ({\tt pexpect.sourceforge.net})
106
107
Pexpect is a pure Python module for spawning child applications;
108
controlling them; and responding to expected patterns in their
109
output. Pexpect works like Don Libes' Expect. Pexpect allows your
110
script to spawn a child application and control it as if a human
111
were typing commands.
112
\end{itemize}
113
\end{frame}
114
115
\begin{frame}[fragile]
116
\t{Using pexpect: The Basic Idea}
117
\begin{verbatim}
118
sage: import pexpect
119
sage: p = pexpect.spawn('gp --emacs --fast --quiet')
120
sage: p.maxread = 100000 # crucial for speed!!!
121
sage: p.expect('\\? ')
122
0
123
sage: p.sendline('factor(2006)')
124
13
125
sage: p.expect('\\? ')
126
0
127
sage: p.before
128
'factor(2006)\r\n\r\n[2 1]\r\n\r\n[17 1]\r\n\r\n
129
[59 1]\r\n\r\n'
130
sage: p.close()
131
\end{verbatim}
132
\end{frame}
133
134
\begin{frame}
135
\t{Difficulties}
136
\begin{enumerate}
137
\item Getting subprocesses (and their children!) to quit when you
138
quit \sage{}.
139
\item I/O Prompts: make very obscure or embed control codes.
140
\item Control-C: How to break out of a computation.
141
\item Large I/O: use files.
142
\item Remote servers: Use the network -- will greatly improve
143
this summer (Yi Qiang).
144
\item Readline (weird formatting in server); often there are
145
debug modes, e.g., in Maple; or emacs modes.
146
\item Support for direct interaction -- coding sprint at Sage Days 1.
147
\item Unknown number of return values -- Magma.
148
\end{enumerate}
149
\end{frame}
150
151
\begin{frame}
152
\t{How to Create a New Interface}
153
\begin{enumerate}
154
\item Decide which of the following programs
155
is most similar to your program:
156
gap, gnuplot, magma, maxima, genus2reduction, gp, mwrank, ecm,
157
kash, maple, octave, singular, gfan, macaulay2, mathematica
158
\item Copy {\tt sage/interfaces/similarsys.py} and modify
159
as appropriate. Use the {\tt log=} option to interface
160
constructor for debuging.
161
\item Figure out what the true, false, equality, etc., symbols
162
are in your system and code those into the interface.
163
\item Provide special functionality for tab completion (listing
164
all defined functions), help on functions, etc.
165
\end{enumerate}
166
167
\end{frame}
168
169
\begin{frame}
170
\t{How to Improve an Existing Interface}
171
Let $C$ be a computer algebra system, e.g., Maple,
172
Macaulay2, etc.
173
\begin{enumerate}
174
\item Systematically work through a standard
175
tutorial for $C$ but using the SAGE interface;
176
record anything that is difficult, impossible,
177
or {\em unnatural} to do. Add functionality
178
to interface to remedy these problems.
179
\item Try the interface I and if I.[tab] doesn't
180
give all functions in the system, figure out how
181
to get them and tell me!
182
\item Write conversion functions between SAGE objects
183
and objects in $C$, e.g., matrices. We need far
184
more of these!
185
\end{enumerate}
186
\end{frame}
187
188
\begin{frame}
189
\t{Part II: Web Browser Interfaces to SAGE}
190
\begin{enumerate}
191
\item Simple cgi-bin script interface
192
\item SAJAX -- an AJAX interface to SAGE
193
\item SAGE Web Notebook -- brand new local web-server interface
194
\end{enumerate}
195
\end{frame}
196
197
198
\begin{frame}
199
\t{1. Simple cgi-bin script interface}
200
This is at
201
{\tt http://modular.math.washington.edu/calc/},
202
but people have copied it for Kash, MAGMA, etc.
203
204
\begin{enumerate}
205
\item Started so Keith Conrad's student at UCONN could use
206
PARI easily for their number theory class.
207
\item Uses apache2 and some simple Python cgi-bin scripts.
208
\item Provided way to ``try out MAGMA'' (and variant is
209
now available at MAGMA website.)
210
\end{enumerate}
211
\end{frame}
212
213
\begin{frame}[fragile]
214
\begin{verbatim}
215
Date: Mon, 19 Dec 2005 16:54:09 -0800
216
From: "John Cannon" <john@maths.usyd.edu.au>
217
William,
218
219
This is to formally advise you that your permission to
220
run a general-purpose calculator based on Magma ends on
221
Dec 31, 2005. [...]
222
223
Note that this does NOT affect the use of Magma in your
224
modular forms site. Nor is it likely that we would
225
withdraw permission for this use of Magma provided that
226
Magma is properly acknowledged (as it has been in the
227
past). In fact we are encouraging the use of Magma as
228
part of the backend in similar servers.
229
230
Please confirm receipt of this letter.
231
Wishing you a happy Christmas,
232
John
233
\end{verbatim}
234
\end{frame}
235
236
237
\begin{frame}
238
\t{2. SAJAX: AJAX interface to SAGE}
239
Aaron Klem found an AJAX terminal application at
240
{\tt http://antony.lesuisse.org/qweb/trac/wiki/AjaxTerm}.
241
It's a stand-alone webserver written with Python combined with
242
a javascript page.
243
244
I modified it to make
245
{\tt http://modular.math.washington.edu:8389/}
246
247
\begin{enumerate}
248
\item No authentication -- need chroot. The AJAX term web
249
server runs as a normal process. When a user connects,
250
a chroot'd SAGE session starts set to timeout after an
251
hour.
252
\item Multiple connections at once are allowed.
253
\item {\em Rumored} to be unusably slow, though I've
254
not experienced this (i.e., it's great if the server
255
is in ``on campus'').
256
\item No graphics. No scrollback. Cut and paste
257
is very difficult.
258
\item Tab completion, history, etc., work well.
259
\item Hard to setup (because of chroot jail).
260
\end{enumerate}
261
\end{frame}
262
263
\begin{frame}
264
\t{3. The SAGE Web Notebook}
265
Alex Clemesha and I wrote it from scratch as part of SAGE
266
(on Monday).
267
It uses that Python has (as part of the standard library!)
268
a web server built in.
269
\begin{itemize}
270
\item Completely standalone.
271
\item Python for webserver; some Javascript in the web page.
272
\item Not done! But I already like using it more than command line!
273
\item Saves all I/O to a disk file whenever possible (if you gave
274
optional name='file' argument).
275
\item Multiple people connect to a single session at
276
once.
277
\item May become the standard SAGE interface; you start a local server
278
on your computer (e.g., via Cygwin or VMware under Windows), connect
279
to a local web address, and use SAGE. Or connect to a university
280
server and use SAGE; same interface!
281
\item Completely avoids need to create GUI for SAGE.
282
\end{itemize}
283
\end{frame}
284
285
286
\begin{frame}[fragile]
287
\t{SAGE Web Notebook: TODO List}
288
{\tiny\begin{verbatim}
289
[] Add authentication
290
[] The "move to the current input box" javascript *only* works
291
with firefox (not opera, not konqueror); also this should
292
just keep the page position where it is rather than move it.
293
Moving to a more AJAX-ish model would alternatively fix this, maybe.
294
[] A. Clemesha: shrink/expand input/output blocks
295
[] A. Clemesha: When hit shift-enter the next text box should be made
296
into focus.
297
[] Add plain text annotation that is not evaluated
298
between blocks (maybe in html?)
299
E.g., just make ctrl-enter on a block by HTML-it.
300
[] Ability to interrupt running calculations directly
301
from the web interface (no console access)
302
[] Nice animation while a computation is proceeding.
303
[] Some way to show output as it is computed.
304
[] Option to delete blocks
305
[] Make block expand if enter a lot of text into it.
306
[] Evaluate the entire worksheet
307
[] Theme-able / skin-able
308
[] Embedded graphics from plots;
309
also embed png from latexing of math objects (so they look nice).
310
[] Downloading and access to exact log of IO to client SAGE process
311
[] Save session objects as to log objects so don't have to re-eval?
312
[] The entire page is resent/updated every time you hit shift-enter;
313
using 'AJAX' this flicker/lag could be completely eliminated.
314
[] When pressing shift-enter a line feed is inserted temporarily
315
into the inbox, which is unnerving.
316
317
Try it and send me some ideas!
318
\end{verbatim}
319
}
320
\end{frame}
321
322
\end{document}
323
324