kpeeters / cadabra2

A field-theory motivated approach to computer algebra.
https://cadabra.science/
GNU General Public License v3.0
226 stars 37 forks source link

Jupyter Notebook does not see the cadabra2 kernel, both installed via conda and the recommended way #270

Closed Fulmenius closed 1 month ago

Fulmenius commented 1 year ago

Hello there! I was trying to install cadabra2 so that I would be able to use it in Jupyter Notebook. First I installed it as an Anaconda package. It worked in the sense that Anaconda is aware that the package exists, and seems to understand commands like

import cadabra2 as cd
def post_process(ex):
    cd.sort_product(ex)
    cd.canonicalise(ex)
    cd.collect_terms(ex)

However, when I try something like {\mu,\nu,\rho}::Indices(position=free). or cd.{\mu,\nu,\rho}::Indices(position=free). Jupyter notebook raises a Python syntax error. I tried to install the standalone version of cadabra2, using the instruction from the official github repository, and it has installed successfully, but Jupyter notebook does not provide an option to run the cadabra2 kernel. What could be the problem? I use Xfce 4.16.0, distro: Linux Mint 21 Vanessa, base: Ubuntu 22.04 jammy.

P.S. Also cadabra2-gtk does not work from the terminal (fish thinks the command does not exist, although cadabra2 works just fine) P.P.S. Also this link: https://cadabra.science/static/cadabra_in_ipython.nb.html to the inside-Python use tutorial from the official site does not work

kpeeters commented 1 year ago

First of all, input like

{\mu,\nu,\rho}::Indices(position=free)

is Cadabra syntax, not Python, so you should not expect that to work in a Python session. You really need either the Cadabra Jupyter kernel or Cadabra's own notebook interface cadabra2-gtk (or the command line client cadabra2).

As for your Jupyter kernel problem: you cannot mix-and-match Python distributions. If you decide you want to use Anaconda for you Python things, then everything has to come from Anaconda, otherwise you are in for a disaster. So you have two options:

  1. Install the Cadabra Jupyter kernel using the cadabra2-jupyter-kernel Conda package, see https://anaconda.org/conda-forge/cadabra2-jupyter-kernel .

  2. Disable Anaconda (or at least not enable it by default in any shell) and install the Jupyter notebook using sudo apt install jupyter-notebook and then also install Cadabra from a prebuilt .deb package or from source (prebuilt .deb packages for Mint 21 will be available in a few days). Then you have Jupyter from the Ubuntu packages and a Cadabra to go with that.

Option 2 is by far the cleanest (the apt package manager is a lot better than the conda one).

P.S. I don't know why the conda installation does not put cadabra2-gtk in your path; what happens when you type which cadabra2-gtk?

P.P.S. Thanks, I have now fixed that page.

Fulmenius commented 1 year ago

Thank you for the response! I have tried installing cadabra2-jupyter-kernel, and now there is an option to choose the Cadabra kernel in jupyter notebook, but the kernel dies at a steady rate. What's worse, I can't even remove the conda installation using conda, because for some reason while building dependency tree conda runs out of memory (to the point that laptop ceases to respond to commands). I will try the recommended steps to the .deb installation when the latter will be available for Linux Mint P.S. which cadabra2-gtk exits with [1]

kpeeters commented 1 month ago

Since this seems to be caused by a mixture of system components and conda components I will close this for now; feel free to re-open if you think that the jupyter cadabra kernel does not work correctly on systems without conda.