Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Using Sage with TensorFlow

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!