remote mathematica, magma and so on

77 views
Skip to first unread message

PaulOli...@gmail.com

unread,
Aug 14, 2007, 1:40:44 PM8/14/07
to sage-support
hi all
i was wondering if anyone had already implemented this:
my computing setup is not the greatest. i don't pay for mathematica or
magma so i don't have them available on my laptop. on the other hand
my university does pay for them, and i have a user account on the
machines where they are run. but then those machines don't have a very
current version of sage...
so i was curious whether it would be possible to have sage run
mathematica on a remote server and interact with it just as if it was
also installed on my machine?
thanks
paul

Chris Chiasson

unread,
Aug 14, 2007, 4:09:06 PM8/14/07
to sage-support
you can use mathematica remotely anyway
method 1: remote kernel (don't know if mathplayer can be made to
connect to one of these)
method 2: ssh tunneling, possibly with x windows (this should work,
but you will probably need to learn a lot to make it work)

plain method:
ssh and execute
math
to enter a mathematica terminal mode session (sans front end)

On Aug 14, 12:40 pm, "PaulOlivierS...@gmail.com"

PaulOli...@gmail.com

unread,
Aug 14, 2007, 4:48:49 PM8/14/07
to sage-support
i know about ssh tunneling and so on but i am posting this on sage-
support...
the point was to have a sage session on my laptop interacting with a
remote mathematica (for instance)
paul

Jack Schmidt

unread,
Aug 14, 2007, 10:51:44 PM8/14/07
to sage-support
You can just put a shell script in $SAGE_ROOT/local/bin/math (or
whatever the binary name is supposed to be) with the contents:

#!/bin/sh
exec ssh -t myMathem...@myMathematicaServer.DomainName.com math
$*

You need to setup some sort of password-less authentication from your
laptop to the mathematica server if you have not already. There are
lots of simple ways to do this. Two easy and elementary ways are the
ControlMaster option or the program ssh-agent, as described in the man
pages for ssh_config and ssh-agent.

I don't have access to mathematica, but this works for gap, kash, and
magma.

On Aug 14, 4:48 pm, "PaulOlivierS...@gmail.com"

William Stein

unread,
Aug 14, 2007, 11:20:56 PM8/14/07
to sage-s...@googlegroups.com
If you're just using an interface and have setup password-less authentication
using ssh-keys, you can use the server= option.

sage: m = Mathematica(server="name.of.computer.edu")

William


--
William Stein
Associate Professor of Mathematics
University of Washington
http://www.williamstein.org

PaulOli...@gmail.com

unread,
Aug 15, 2007, 7:54:44 AM8/15/07
to sage-support
> You can just put a shell script in $SAGE_ROOT/local/bin/math (or
> whatever the binary name is supposed to be) with the contents:
>
> #!/bin/sh
> exec ssh -t myMathematicaU...@myMathematicaServer.DomainName.com math
> $*

Thanks! After some sweat it worked. The main pain is that I can't
actually ssh directly to the machine running mathematica (speedy-
gonzales) when I am at home, I need to tunnel through yet another
machine (gate). This is the math* script:
#!/bin/sh
ssh -t gate.maths.ox.ac.uk "source .ssh-agent.sh;ssh -t speedy-
gonzales.maths.ox.ac.uk math"

The console, the interface and the interactive modes work (for
mathematica so far). The only thing is that when quitting the
console() it's not clean. SAGE hangs for a while, but reacts after a
few key presses:


sage: mathematica.console()
Pseudo-terminal will not be allocated because stdin is not a
terminal.
Agent pid
32110
<-------------------------------------------- my ssh-agent is started
Pseudo-terminal will not be allocated because stdin is not a terminal.
Mathematica 5.2 for Linux
Copyright 1988-2005 Wolfram Research, Inc.
-- Terminal graphics initialized --

In[1]:= Quit


<-------------------------------------------- Nothing happens so I
press a few times Enter

---------------------------------------------------------------------------
<type 'exceptions.IOError'> Traceback (most recent call
last)

/Users/pdehaye/<ipython console> in <module>()

/Library/sage/local/lib/python2.5/site-packages/sage/interfaces/
mathematica.py in console(self, readline)
393
394 def console(self, readline=True):
--> 395 mathematica_console(readline=readline)
396
397 def trait_names(self):

/Library/sage/local/lib/python2.5/site-packages/sage/interfaces/
mathematica.py in mathematica_console(readline)
495 line = raw_input(' ')
496 f1.writelines(line+'\n')
--> 497 f1.flush()
498 except KeyboardInterrupt:
499 f1.close()

<type 'exceptions.IOError'>: [Errno 32] Broken pipe
sage:
sage:
sage:

William Stein

unread,
Aug 15, 2007, 11:19:38 AM8/15/07
to sage-s...@googlegroups.com
On 8/15/07, PaulOli...@gmail.com <PaulOli...@gmail.com> wrote:
> > You can just put a shell script in $SAGE_ROOT/local/bin/math (or
> > whatever the binary name is supposed to be) with the contents:
> >
> > #!/bin/sh
> > exec ssh -t myMathematicaU...@myMathematicaServer.DomainName.com math
> > $*
>
> Thanks! After some sweat it worked. The main pain is that I can't
> actually ssh directly to the machine running mathematica (speedy-
> gonzales) when I am at home, I need to tunnel through yet another
> machine (gate). This is the math* script:
> #!/bin/sh
> ssh -t gate.maths.ox.ac.uk "source .ssh-agent.sh;ssh -t speedy-
> gonzales.maths.ox.ac.uk math"
>
> The console, the interface and the interactive modes work (for
> mathematica so far).

What happens if you try inputing something very large, e.g., with
a few thousand digits, e.g.,
mathematica(10^10000)?
SAGE normally uses files to send large input, and with the "server=" option
it would use scp, but with a "fake" math command line, I don't think files
will work at all. So unfortunately with what you're doing below probably
anything involving large input will fail.

That said, it is a very intriguing problem to make the SAGE interfaces work
even when there are arbitrarily many hops between you and the math software.

PaulOli...@gmail.com

unread,
Aug 15, 2007, 2:02:57 PM8/15/07
to sage-support
good catch, you can debug remotely on my computer :)
yes, william, you are right: the small examples work but not the big
ones. i didn t anticipate that SAGE was using files behind the scenes
(i don't know anything about how that works).
in any case, the fact that sage uses scp is not really a problem. this
is another workaround:
ssh -t tunnel scp test_file remote:~/test_file
(after setting all the passwordless stuff)
so if that s all that s needed, maybe one could add to the server
option of the interface a prefix and a suffix to trail the scp command
with, and the same for the ssh (or rsh or whatever is used)
Paul

On Aug 15, 4:19 pm, "William Stein" <wst...@gmail.com> wrote:

William Stein

unread,
Aug 15, 2007, 10:20:24 PM8/15/07
to sage-s...@googlegroups.com
> good catch, you can debug remotely on my computer :)
> yes, william, you are right: the small examples work but not the big
> ones. i didn t anticipate that SAGE was using files behind the scenes
> (i don't know anything about how that works).
> in any case, the fact that sage uses scp is not really a problem. this
> is another workaround:
> ssh -t tunnel scp test_file remote:~/test_file
> (after setting all the passwordless stuff)
> so if that s all that s needed, maybe one could add to the server
> option of the interface a prefix and a suffix to trail the scp command
> with, and the same for the ssh (or rsh or whatever is used)

You could try implementing this. Take a look at
SAGE_ROOT/devel/sage/sage/interfaces/expect.py
and
SAGE_ROOT/devel/sage/sage/interfaces/mathematica.py
Do a text search for "scp" in there. Make changes and do
"sage -br" to start SAGE with the changes in effect.

William

PaulOli...@gmail.com

unread,
Aug 16, 2007, 4:26:16 AM8/16/07
to sage-support
I will try, don't hold your breath.
Even without my additional problem of having to go through a gate, it
looks as if the scp file tranfers have only been implemented for
copies of sage (sage0.py, which is the only place scp appears), not
for a general expect interface (see line
eval_using_file_cutoff = 0 # don't allow this!
in expect.py)
In some sense that's enough in most cases (you can have a situation
where exact-same-version SAGE's do all the communicating, and each
runs different CAS on different machines), but there would be another
extra overhead and one can not always install sage on remote.
Paul


On Aug 16, 3:20 am, "William Stein" <wst...@gmail.com> wrote:

PaulOli...@gmail.com

unread,
Aug 19, 2007, 7:37:30 PM8/19/07
to sage-support
For the record...
I have gotten around my difficulty thanks to the option "ProxyCommand"
in ssh. I now have the following lines in my ~/.ssh/ssh_config

Host remote_for_sage
ProxyCommand ssh gateway nc -w 1 remote 22

and that (along with all the passwordless authentication associated)
does the trick.
It essentially tells my ssh to create a new virtual host called
"remote_for_sage", so that
- "ssh remote_for_sage" will actually return a SSH connection to
"remote", but through the machine "gateway"
- "ssh -t remote_for_sage magma" will similarly run magma on
"remote" through "gateway"
- "ssh remote" is not affected at all (and in my case won't work,
as "remote" is shielded by "gateway", that was the point)
- "scp remote_for_sage" will *also* be tunneled through
"gateway" (that's the power of ProxyCommand)

So when I do
sage: magma = Magma(server = "remote_for_sage")
, that ssh_config takes care of everything and the fact that it is
tunneled through gateway is entirely transparent to sage.

Paul

On Aug 16, 9:26 am, "PaulOlivierS...@gmail.com"

William Stein

unread,
Aug 19, 2007, 8:36:02 PM8/19/07
to sage-s...@googlegroups.com
On 8/19/07, PaulOli...@gmail.com <PaulOli...@gmail.com> wrote:
>
> For the record...
> I have gotten around my difficulty thanks to the option "ProxyCommand"
> in ssh. I now have the following lines in my ~/.ssh/ssh_config

Paul,

It would be great if you could add this discussion (in latex-ish format)
to the file SAGE_ROOT/devel/sage/sage/interfaces/expect.py (and
post a patch). Then people reading the reference manual about the
interfaces could have a reasonable chance of doing what you did.

-- William

PaulOli...@gmail.com

unread,
Aug 23, 2007, 9:37:10 AM8/23/07
to sage-support, sage-devel
Sorry if this is posted twice, first time didn t do it
This is now done in two patches posted at
http://www.sagemath.org:9002/sage_trac/ticket/483
Paul

On Aug 20, 1:36 am, "William Stein" <wst...@gmail.com> wrote:

Reply all
Reply to author
Forward
0 new messages