Ask Your Question
1

Run sage notebook without sage.all imported

asked 2019-09-09 05:25:11 -0600

Tilpo gravatar image

When I create a create a sage Jupyter notebook the kernel seems to always run from sage.all import *. This can be useful since you don't have to worry about importing all the things you need. However I find it has two big disadvantages:

  • The sage kernel takes a while to start (roughly one minute for me)
  • It causes naming conflicts when we define a function or class that already has a meaning somewhere in the huge sage library.

Therefore I wonder if it is possible to run a notebook with a sage kernel without importing the entire sage library.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-09-09 08:09:44 -0600

vdelecroix gravatar image

The fact that Sage takes so long to start is a problem. Though, if you want to use any function from Sage you need to run this import as it does initialize the many libraries it is using. You can still run a Python 2 (or Python 3 depending on your configuration) kernel and then run from sage.all import * in a cell. The kernel will start faster but you will still have to wait for the initialization to be done.

edit flag offensive delete link more

Comments

But my point is that I don't want to use from sage.all import *. I only need a couple libraries. If I try to import a sage library from a Python 2 kernel, I either get an ImportError or the kernel crashes. Is it really only possible to import the entire sage library or nothing at all?

Tilpo gravatar imageTilpo ( 2019-09-09 08:55:59 -0600 )edit

Short answer: no

Longer answer: it is complicated to make work together many libraries and the fact that Python is easily subject to cyclic imports. The initialization of the Sage module (in sage.all) is quite possibly not optimal as it does initialize and import everything. I agree with you that the initialization of the libraries should be made more local but it is currently not the case.

Advertisement: SageMath is a collaborative open source project. You are very welcome to propose concrete improvement by submitting code to the trac server.

vdelecroix gravatar imagevdelecroix ( 2019-09-09 09:58:10 -0600 )edit
1

I'm quite certain it's possible to speed of Sage initialization by importing just a smaller set of core modules, and I would like to be able to do that too. Even with the import cycles (some of which I believe can be broken with appropriate refactoring, although some others are unavoidable), I think it should be possible to get imports from sage working without importing as much as sage.all does. It's something I've always wanted to work on but it is a daunting task no doubt.

Iguananaut gravatar imageIguananaut ( 2019-09-09 10:49:23 -0600 )edit

That makes sense, thanks for clearing that up.

Tilpo gravatar imageTilpo ( 2019-09-09 13:13:30 -0600 )edit

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2019-09-09 05:25:11 -0600

Seen: 39 times

Last updated: Sep 09