Welcome to Cadabra Q&A, where you can ask questions and receive answers from other members of the community.
+1 vote

Hello,

Trouble running Cadabra 2 and generating output with the system described below:

OS: WSL 2 [Windows Subsystem for Linux 2] Ubuntu 18.04 on Windows 10 x64

Python 3.7.7. Installation type: Anaconda 3

Cadabra2 download and installed using conda as per instructions

conda list cadabra packages in environment at /home/audrius/anaconda3: Name Version Build Channel cadabra2-jupyter-kernel 2.2.9 h6bb024c_0 kpeeters

conda list sympy packages in environment at /home/audrius/anaconda3: Name Version Build Channel sympy 1.5.1 py37_0

conda list jupyter packages in environment at /home/audrius/anaconda3: Name Version Build Channel cadabra2-jupyter-kernel 2.2.9 h6bb024c_0 kpeeters jupyter 1.0.0 py37_7 jupyter_client 6.1.2 py_0 jupyter_console 6.1.0 py_0 jupyter_core 4.6.3 py37_0 jupyterlab 1.2.6 pyhf63ae98_0 jupyterlab_server 1.1.0 py_0

Is there another conda package or packages that I should check?

Using the MS VS Code IDE, I start the Jupyter server, select the "Cadabra" kernel option. I then run the cell containing the example code from "Using Cadabra for tensor computations in General Relativity" by L. Brewin, "1. Hello metric connection", but no output is generated, just a new cell is created. Also, the Cadabra kernel state stays "Idle".

I've attached a screenshot below:

VS Code IDE. Cadabra kernel

in Installation trouble by

That's a combination I had not tried yet... ;-) Have you tried whether running it using Jupyter's own notebook server works? (so starting with 'jupyter notebook' and then using the web browser notebook interface? I suspect the answer is that that does not work either, but I'd like to have it confirmed before we dig any further.

1 Answer

+1 vote

"Have you tried whether running it using Jupyter's own notebook server works?"

No, I had not done so.

While WSL 2 is a fully functional Linux OS, not an emulator, it is command-line only - there is no GUI desktop and no browser. With a addition of an X-server on the Windows 10 side, such as VcXsrv, one can display matplotlib output, in a separate window, generated in VS Code running on WSL side.Which is more than sufficient for scientific computing using numpy/sympy/numba/etc.

[update in following comment]

by (220 points)
edited by

After a bit of investigation, I was able to start a standalone Jupyter Notebook on the WSL 2 side and run an .ipynb file, using the Cadabra 2 kernel, in a browser on the Windows 10 side.

I've listed the steps below should it be of interest to other users.

1/ WLS 2 side. If not already installed, install wslu.

https://github.com/wslutilities/wslu

As I'm running Ubuntu 18.04,

sudo apt update sudo apt install ubuntu-wsl wslview --register

The last command registers wslu as the browser.

2/ WLS 2 side. In ~/.bashrc, append a line setting the BROWSER environment variable

export BROWSER=wslview

3/ WLS 2 side. cd to the directory with the .ipynb file(s) of interest and enter the standard command

jupyter notebook --no-browser

A message such as the following should be generated, with no "tty" error message.

[I 05:18:22.050 NotebookApp] Writing notebook server cookie secret to /home/audrius/.local/share/jupyter/runtime/notebook_cookie_secret [I 05:18:24.296 NotebookApp] JupyterLab extension loaded from /home/audrius/anaconda3/lib/python3.7/site-packages/jupyterlab [I 05:18:24.296 NotebookApp] JupyterLab application directory is /home/audrius/anaconda3/share/jupyter/lab [I 05:18:24.305 NotebookApp] Serving notebooks from local directory: /mnt/c/projects/hamiltonian [I 05:18:24.305 NotebookApp] The Jupyter Notebook is running at: [I 05:18:24.305 NotebookApp] http://localhost:8888/?token=d2192d44165fd0f7a3162f6e6528425c838d27edb7b8d681 [I 05:18:24.306 NotebookApp] or http://127.0.0.1:8888/?token=d2192d44165fd0f7a3162f6e6528425c838d27edb7b8d681 [I 05:18:24.306 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation). [C 05:18:24.317 NotebookApp]

To access the notebook, open this file in a browser: file:///home/audrius/.local/share/jupyter/runtime/nbserver-29930-open.html Or copy and paste one of these URLs: http://localhost:8888/?token=d2192d44165fd0f7a3162f6e6528425c838d27edb7b8d681 or http://127.0.0.1:8888/?token=d2192d44165fd0f7a3162f6e6528425c838d27edb7b8d681

4/ Windows 10 side. Start the browser and enter the above url with token into the address bar.

In this case, I would enter

http://127.0.0.1:8888/?token=d2192d44165fd0f7a3162f6e6528425c838d27edb7b8d681

The browser should now display the WSL 2 side directory with the .ipynb files of interest.

5/ Windows 10 side. Left-click on the .ipynb file of interest. A new browser tab/window should appear with the kernel set to Cadabra. Run the cell to view the Latex/MathML output in the browser.


WSL 2 side only. No success in running Cadabra in VS Code.

So in summary, output works in Jupyter's own notebook, just not in VS Code?

That is correct.

Ok, thanks. I don't have time right now to dig into this, but I have opened an issue on the Cadabra issue tracker so it doesn't get lost:

https://github.com/kpeeters/cadabra2/issues/196

Thank you.

No idea if this would be simpler to implement, but could Cadabra 2 be converted to a Python package that one would import into a Python program as one does with Sympy?

Will also mention the VS Code extension Markdown+Math which be of use in displaying equation output:

https://marketplace.visualstudio.com/items?itemName=goessner.mdmath

Hi! I am also trying to make Cadabra2 work with WSL (Ubuntu 18.04). However, whenever I try to compile/run the Cadabra code I get a connection error, somehow the system cannot connect to the Kernel. Any suggestion?

Two questions:

  1. Are you using WSL 1 or WSL 2? If you are using WSL 1 you should switch to WSL 2.

  2. Are you using - trying to run the kernel in - MS VS Code?

If you are trying anything with Cadabra + Jupyter, please look at https://cadabra.science/jupyter.html , as there is now a new Jupyter kernel which no longer requires Xeus (only Python plus the cadabra2 python module). May make life easier.

Please take WSL-specific discussions which do not relate to VSCode to https://cadabra.science/qa/1811/installation-on-windows-subsystem-for-linux-wsl ; in short, I have verified that Cadabra (cli, jupyter and notebook interface) work with WSL2, but there are still a few rough edges.

I am using WSL2. Unfortunately I don't know the difference between MS and Code.

To be more specific about the symptoms, what I find is that jupyter does give the New>Cadabra2 option when creating a new project, but then the kernel gets stuck whenever I evaluate something.

You most likely need to set the PYTHONPATH before you start jupyter notebook:

export PYTHONPATH=${PYTHONPATH}:/usr/lib/x86_64-linux-gnu/python3.6/site-packages

That's for Ubuntu 18.04; for others you may need to adjust the python version in the above path. The problem is not that the kernel hangs, but that it cannot start the kernel at all, because it cannot find required package which is located at the path above.

I confirm: the magical command works like a charm on Ubuntu 18.04 with Python 3.6!!! Can I stick this in the bashrc file and never think about this again?

Yes, you can.

...