mrzv / saturn

plain-text Python notebooks with checkpointing
Other
6 stars 0 forks source link

Choose kernel #2

Open Eloitor opened 11 months ago

Eloitor commented 11 months ago

In a jupyter notebook it is possible to choose other kernels (like SageMath).

Is it possible to choose the kernel in saturn?

mrzv commented 11 months ago

There is no concept of kernels in Saturn. The idea is not to take over the environment, but to be just another Python module, inside whatever (possibly virtual) environment you like, that plays nice with everything else. So it's possible to install saturn as a package inside sage. The following works:

sage --pip install saturn_notebook
sage --python -m saturn_notebook

>>> from sage.all import *
>>> u = var('u')

Unfortunately, I don't know enough about sage to know if this will create problems or work as intended.

Eloitor commented 11 months ago

Thanks for the answer.

SageMath has slightly different syntax to python's: https://doc.sagemath.org/html/en/tutorial/afterword.html The equivalent of eval in sage is from sage.misc.sage_eval import sage_eval.

I think it should be possible to replace the python's eval of the notebook with sage_eval, but I'm not sure how

mrzv commented 11 months ago

All the code evaluation logic happens in evaluate.py. Perhaps, there is a way to tweak that. If you find a clean way, please submit a pull request.

Eloitor commented 11 months ago

Maybe https://pypi.org/project/jupyter-client/ could be used...

Here's an example of a jupyter notebook app using it: https://github.com/cvfosammmm/Porto/blob/master/notebook/backend/backend_code.py#L209