SharedInstall-GAP-in-CoCalc-project.mdOpen in CoCalc
Authors: Pedro A. Garcia, Sebastian Gutsche, Samuel Lelièvre
Views : 23
Description: Install GAP 4.10.0 in CoCalc project

Install GAP 4.10.0 in a CoCalc project

Author: Samuel Lelièvre

Date: 2019-01-15

License: CC0

Goal

Instructions on how to build GAP in a CoCalc project.

(Should go roughly the same in any Linux or macOS system.)

Install GAP 4.10.0 following instructions on the GAP website

See instructions at

Note in particular that the path to the GAP directory should not contain spaces.

For a system-wide install, note the extra step in the INSTALL.md file:

  (If you unpack the archive as root user under Unix, make sure that you
  issue the command `umask 022` before, to ensure that users will have
  permissions to read the files.)

System-wide installation of GAP in CoCalc is discussed at

Download the tarball

This corresponds to "section 2: getting the archive" of the INSTALL.md file.

Done here using curl; one could alternatively use wget.

In a CoCalc project without internet access, one could

We first set our working directory to our home (change if needed).

$ WORKDIR=$HOME
$ cd $WORKDIR

The tarball is at https://www.gap-system.org/pub/gap/gap-4.10/tar.bz2/gap-4.10.0.tar.bz2 so we set:

$ REMOTE='https://www.gap-system.org/pub/gap/gap-4.10/tar.bz2'
$ VERSION='gap-4.10.0'
$ TARBALL=$VERSION'.tar.bz2'
$ GAPDIR=$WORKDIR/$VERSION

and we download using curl (we could also use wget):

$ cd $WORKDIR
$ curl -C - --retry 99 -o $TARBALL $REMOTE/$TARBALL

Check the sha256 hash

This step is omitted in section 2 of the INSTALL.md file, but it is good practice.

We compute the sha256 of the tarball, and check that it matches the one on the download page; for GAP 4.10.0, it should match 2dc71364b7418d16f8b99ca914971996fa4416294fa3ae8fb336c873c946abb6.

$ cd $WORKDIR
$ sha256sum $TARBALL

Unpack the tarball

This corresponds to "section 3: unpacking" of the INSTALL.md file.

Warning: this will erase the $GAPDIR directory if already present.

$ cd $WORKDIR
$ tar xjf $TARBALL
$ ls $WORKDIR | grep -E "^gap"

Configure and make

This corresponds to "section 4: compilation" of the INSTALL.md file.

Check if the MAKE environment variable is set:

$ echo $MAKE

Optionally, set the MAKE environment variable

$ export MAKE='make -j4'

Configure and make

$ cd $GAPDIR
$ ./configure && make

Install packages

This corresponds to "section 7: packages" of the INSTALL.md file.

We do this before testing the installation.

$ cd $GAPDIR/pkg
$ ../bin/BuildPackages.sh

Check the content of the pkg directory.

$ ls $GAPDIR/pkg

Test the installation

This corresponds to "section 2: testing the installation" of the INSTALL.md file.

$ ls $GAPDIR
$ ls $GAPDIR/bin
$ cd $WORKDIR
$ TEST='Read(Filename(DirectoriesLibrary("tst"), "testinstall.g"));'
$ echo $TEST > test_gap.g
$ cd $WORKDIR
$ $GAPDIR/bin/gap.sh test_gap.g

Optional: symbolic link to this version of GAP

This is so that typing gap in a terminal will launch this GAP rather than the system-wide installed GAP.

$ mkdir -p $HOME/bin
$ ln -s $GAPDIR/bin/gap.sh $HOME/bin
$ which gap

Install the GAP Jupyter kernel

Following the installation guide in the manual for the GAP package "JupyterKernel".

All system prerequisites are there; all prerequisite GAP packages are there and those that need compiling have been compiled.

The JupyterKernel GAP package itself is also present.

So it is just a matter of making it known to Jupyter, by doing:

$ cd $GAPDIR/pkg/JupyterKernel-1.0
$ python3 setup.py install --user
Installing jupyter kernel spec
Installing nbextension for syntax hilighting

Then the list of available kernels contains GAP-4:

$ jupyter kernelspec list
Available kernels:
  gap-4               /home/user/.local/share/jupyter/kernels/gap-4

and we can check the content of the kernel.json for that:

$ cat /home/user/.local/share/jupyter/kernels/gap-4/kernel.json
{"argv": ["jupyter-kernel-gap", "{connection_file}"], "display_name": "GAP 4", "language": "gap", "codemirror_mode": "gap", "env": {"PS1": "$"}, "interrupt_mode": "message"}

The kernel does not seem to work.

Tried modifying /home/user/.local/share/jupyter/kernels/gap-4/kernel.json so it reads

{"argv": ["jupyter-kernel-gap", "{connection_file}"], "display_name": "GAP 4", "language": "gap", "codemirror_mode": "gap", "env": {"JUPYTER_GAP_EXECUTABLE": "gap"}, "interrupt_mode": "message"}

or

{"argv": ["jupyter-kernel-gap", "{connection_file}"], "display_name": "GAP 4", "language": "gap", "codemirror_mode": "gap", "env": {"JUPYTER_GAP_EXECUTABLE": "gap -r -A"}, "interrupt_mode": "message"}

or

{"argv": ["/home/user/gap-4.10.0/pkg/JupyterKernel-1.0/jupyter-kernel-gap", "{connection_file}"], "display_name": "GAP 4", "language": "gap", "codemirror_mode": "gap", "env": {"JUPYTER_GAP_EXECUTABLE": "/home/user/bin/gap"}, "interrupt_mode": "message"}

Tried modifying the PATH in .bashrc.

Tried adding this line in .bashrc:

export JUPYTER_GAP_EXECUTABLE="gap"

or

export JUPYTER_GAP_EXECUTABLE="gap -r -A"

or

export JUPYTER_GAP_EXECUTABLE="/home/user/bin/gap -r -A"

Tried installing JupyterKernel 1.1:

$ cd $GAPDIR/pkg
$ curl -L -O https://github.com/gap-packages/JupyterKernel/releases/download/v1.1/JupyterKernel-1.1.tar.gz
$ tar xf JupyterKernel-1.1.tar.gz
$ cd JupyterKernel-1.1
$ python3 setup.py install --user

No luck getting it to work.

At some point I had managed to reach a state like the one illustrated by the screenshot at https://github.com/sagemathinc/cocalc/issues/1706#issuecomment-446273108 but then kept tinkering and could never reproduce that.

In that state, you could execute a cell, and would have to interrupt with ctrl-C, which would cause the output to be displayed, followed by a similar error message to that in the screenshot, involving ZeroMQ communications.

Then after all that, tried in Plain Jupyter and JupyterLab, and it works fine there!

It's just not working in CoCalc-Jupyter.

Note that contrary to the previous GAP Jupyter kernel based on pexpect and Python, and now deprecated (see https://github.com/markuspf/jupyter-kernel-gap), this new kernel is implemented in the GAP language.

Maybe that gives CoCalc-Jupyter trouble...