Ask Your Question
2

Using Sage with TensorFlow

asked 9 years ago

zqcm gravatar image

I've written something in TensorFlow that makes use of some nice group theory functions that work very easily in Sage (and seem prohibitively difficult to code from scratch). However, I can't get TensorFlow and Sage to work together. Each works on its own, but I think they rely on different Python versions and therefore won't run together. I think Sage uses Python 2.6 and TensorFlow 2.7.

Specifically, I can make a small Python script test.py that uses some Sage functions and run it using

sage --python test.py

and it runs with no problem. But trying to import the TensorFlow module in test.py throws an error saying the tensorflow module doesn't exist. Similarly, I get errors trying to import sage.all inside my .py script that uses TensorFlow. So I can neither add TensorFlow to Sage nor add Sage to Tensorflow.

I first encountered this problem in Sage 6.10 and upgrading to Sage 7.0 hasn't helped.

I'm not sure if this is relevant, but if I fire up normal Python (the kind TensorFlow uses), I get this:

from sage.env import SAGE_LOCAL

SAGE_LOCAL

which outputs '$SAGE_ROOT/local'.

However if I fire up Sage first I get this:

sage SAGE_LOCAL

which outputs ''/usr/lib/sagemath/local'.

Any possible workaround?

Thanks!

Preview: (hide)

Comments

slelievre gravatar imageslelievre ( 9 years ago )

Note: to display code blocks, indent them by 4 spaces. You can also select full lines and click the "code" button, which is the button with '101 010'.

slelievre gravatar imageslelievre ( 9 years ago )

The Python version shouldn't be the problem:

$ sage -ipython
Python 2.7.9 (default, Oct 13 2015, 12:06:06) 
Type "copyright", "credits" or "license" for more information.
kcrisman gravatar imagekcrisman ( 9 years ago )

1 Answer

Sort by » oldest newest most voted
2

answered 9 years ago

kcrisman gravatar image

Here's something NOT to do (yet):

$ sage -pip install https://storage.googleapis.com/tensorflow/mac/tensorflow-0.7.1-cp27-none-any.whl

Even though this "works", it also had several worrying messages about upgrading numpy and six, which completely broke the numpy part of my Sage installation. This was with Sage-6.9.

Which means you have to make sure you have a Sage that has the right versions of Numpy and six. With the latest development version, we do, apparently:

$ ./sage -pip install https://storage.googleapis.com/tensorflow/mac/tensorflow-0.7.1-cp27-none-any.whl
Collecting tensorflow==0.7.1 from https://storage.googleapis.com/tensorflow/mac/tensorflow-0.7.1-cp27-none-any.whl
  Using cached https://storage.googleapis.com/tensorflow/mac/tensorflow-0.7.1-cp27-none-any.whl
Requirement already satisfied (use --upgrade to upgrade): six>=1.10.0 in ./local/lib/python2.7/site-packages/six-1.10.0-py2.7.egg (from tensorflow==0.7.1)
Collecting protobuf==3.0.0b2 (from tensorflow==0.7.1)
  Using cached protobuf-3.0.0b2-py2.py3-none-any.whl
Collecting wheel (from tensorflow==0.7.1)
  Using cached wheel-0.29.0-py2.py3-none-any.whl
Requirement already satisfied (use --upgrade to upgrade): numpy>=1.10.1 in ./local/lib/python2.7/site-packages (from tensorflow==0.7.1)
Requirement already satisfied (use --upgrade to upgrade): setuptools in ./local/lib/python2.7/site-packages/setuptools-20.1.1-py2.7.egg (from protobuf==3.0.0b2->tensorflow==0.7.1)
Installing collected packages: protobuf, wheel, tensorflow
Successfully installed protobuf-3.0.0b2 tensorflow-0.7.1 wheel-0.29.0
You are using pip version 8.0.2, however version 8.1.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

And then I don't get any failures.

So one has to be careful, but apparently it's possible. However, you definitely have to use it from "within" Sage; Sage-as-distribution wouldn't allow you to use your other tensorflow with it.

Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 9 years ago

Seen: 2,075 times

Last updated: Mar 09 '16